1
0
mirror of https://github.com/kepler155c/opus synced 2025-11-21 17:44:54 +00:00

convert to event api

This commit is contained in:
kepler155c@gmail.com
2017-08-03 01:46:39 -04:00
parent 252fb16853
commit a1660fd073
6 changed files with 80 additions and 108 deletions

View File

@@ -1,5 +1,5 @@
local Socket = require('socket')
local process = require('process')
local Event = require('event')
local fileUid = 0
local fileHandles = { }
@@ -57,31 +57,26 @@ local function sambaConnection(socket)
print('samba: Connection closed')
end
process:newThread('samba_server', function()
Event.addRoutine(function()
print('samba: listening on port 139')
while true do
local socket = Socket.server(139)
print('samba: connection from ' .. socket.dhost)
process:newThread('samba_connection', function()
Event.addRoutine('samba_connection', function()
print('samba: connection from ' .. socket.dhost)
sambaConnection(socket)
print('samba: closing connection to ' .. socket.dhost)
end)
end
end)
process:newThread('samba_manager', function()
while true do
local e, computer = os.pullEvent()
if e == 'network_attach' then
fs.mount(fs.combine('network', computer.label), 'netfs', computer.id)
elseif e == 'network_detach' then
print('samba: detaching ' .. computer.label)
fs.unmount(fs.combine('network', computer.label))
end
end
Event.on('network_attach', function(e, computer)
fs.mount(fs.combine('network', computer.label), 'netfs', computer.id)
end)
Event.on('network_detach', function(e, computer)
print('samba: detaching ' .. computer.label)
fs.unmount(fs.combine('network', computer.label))
end)