mirror of
https://github.com/kepler155c/opus
synced 2025-01-24 06:06:54 +00:00
convert to event api
This commit is contained in:
parent
252fb16853
commit
a1660fd073
@ -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)
|
||||
|
||||
Event.addRoutine('samba_connection', function()
|
||||
print('samba: connection from ' .. socket.dhost)
|
||||
|
||||
process:newThread('samba_connection', function()
|
||||
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
|
||||
Event.on('network_attach', function(e, computer)
|
||||
fs.mount(fs.combine('network', computer.label), 'netfs', computer.id)
|
||||
elseif e == 'network_detach' then
|
||||
end)
|
||||
|
||||
Event.on('network_detach', function(e, computer)
|
||||
print('samba: detaching ' .. computer.label)
|
||||
fs.unmount(fs.combine('network', computer.label))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -1,6 +1,6 @@
|
||||
local Socket = require('socket')
|
||||
local GPS = require('gps')
|
||||
local process = require('process')
|
||||
local Event = require('event')
|
||||
|
||||
-- move this into gps api
|
||||
local gpsRequested
|
||||
@ -77,29 +77,25 @@ local function snmpConnection(socket)
|
||||
end
|
||||
end
|
||||
|
||||
process:newThread('snmp_server', function()
|
||||
Event.addRoutine(function()
|
||||
|
||||
print('snmp: listening on port 161')
|
||||
|
||||
while true do
|
||||
local socket = Socket.server(161)
|
||||
print('snmp: connection from ' .. socket.dhost)
|
||||
|
||||
process:newThread('snmp_connection', function()
|
||||
Event.addRoutine(function()
|
||||
print('snmp: connection from ' .. socket.dhost)
|
||||
snmpConnection(socket)
|
||||
print('snmp: closing connection to ' .. socket.dhost)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
process:newThread('discovery_server', function()
|
||||
device.wireless_modem.open(999)
|
||||
|
||||
--os.sleep(1) -- allow services a chance to startup
|
||||
print('discovery: listening on port 999')
|
||||
|
||||
while true do
|
||||
local e, s, sport, id, info, distance = os.pullEvent('modem_message')
|
||||
Event.on('modem_message', function(e, s, sport, id, info, distance)
|
||||
|
||||
if sport == 999 and tonumber(id) and type(info) == 'table' then
|
||||
if not network[id] then
|
||||
@ -114,7 +110,6 @@ process:newThread('discovery_server', function()
|
||||
os.queueEvent('network_attach', network[id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local info = {
|
||||
@ -135,12 +130,8 @@ local function sendInfo()
|
||||
end
|
||||
|
||||
-- every 10 seconds, send out this computer's info
|
||||
process:newThread('discovery_heartbeat', function()
|
||||
--os.sleep(1)
|
||||
|
||||
while true do
|
||||
Event.onInterval(10, function()
|
||||
sendInfo()
|
||||
|
||||
for _,c in pairs(_G.network) do
|
||||
local elapsed = os.clock()-c.timestamp
|
||||
if c.active and elapsed > 15 then
|
||||
@ -148,20 +139,11 @@ process:newThread('discovery_heartbeat', function()
|
||||
os.queueEvent('network_detach', c)
|
||||
end
|
||||
end
|
||||
|
||||
os.sleep(10)
|
||||
end
|
||||
end)
|
||||
|
||||
if os.isTurtle() then
|
||||
process:newThread('turtle_heartbeat', function()
|
||||
|
||||
while true do
|
||||
os.pullEvent('turtle_response')
|
||||
Event.on('turtle_response', function()
|
||||
if turtle.status ~= info.status or
|
||||
turtle.fuel ~= info.fuel then
|
||||
sendInfo()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
@ -1,7 +1,7 @@
|
||||
local Socket = require('socket')
|
||||
local process = require('process')
|
||||
local Event = require('event')
|
||||
|
||||
local function telnetHost(socket, termInfo)
|
||||
local function telnetHost(socket)
|
||||
|
||||
require = requireInjector(getfenv(1))
|
||||
local Event = require('event')
|
||||
@ -9,6 +9,12 @@ local function telnetHost(socket, termInfo)
|
||||
'setTextColor', 'setTextColour', 'setBackgroundColor',
|
||||
'setBackgroundColour', 'scroll', 'setCursorBlink', }
|
||||
|
||||
local termInfo = socket:read(5)
|
||||
if not termInfo then
|
||||
printtError('read failed')
|
||||
return
|
||||
end
|
||||
|
||||
socket.term = term.current()
|
||||
local oldWindow = Util.shallowCopy(socket.term)
|
||||
|
||||
@ -47,7 +53,6 @@ local function telnetHost(socket, termInfo)
|
||||
Event.exitPullEvents()
|
||||
break
|
||||
end
|
||||
|
||||
shellThread:resume(table.unpack(data))
|
||||
end
|
||||
end)
|
||||
@ -58,7 +63,7 @@ local function telnetHost(socket, termInfo)
|
||||
shellThread:terminate()
|
||||
end
|
||||
|
||||
process:newThread('telnet_server', function()
|
||||
Event.addRoutine(function()
|
||||
|
||||
print('telnet: listening on port 23')
|
||||
while true do
|
||||
@ -66,15 +71,12 @@ process:newThread('telnet_server', function()
|
||||
|
||||
print('telnet: connection from ' .. socket.dhost)
|
||||
|
||||
local termInfo = socket:read(5)
|
||||
if termInfo then
|
||||
multishell.openTab({
|
||||
fn = telnetHost,
|
||||
args = { socket, termInfo },
|
||||
args = { socket },
|
||||
env = getfenv(1),
|
||||
title = 'Telnet Client',
|
||||
hidden = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -1,8 +1,8 @@
|
||||
local Socket = require('socket')
|
||||
local process = require('process')
|
||||
local Event = require('event')
|
||||
local Crypto = require('crypto')
|
||||
|
||||
process:newThread('trust_server', function()
|
||||
Event.addRoutine(function()
|
||||
|
||||
print('trust: listening on port 19')
|
||||
while true do
|
||||
|
@ -1,5 +1,5 @@
|
||||
local Socket = require('socket')
|
||||
local process = require('process')
|
||||
local Event = require('event')
|
||||
|
||||
local function wrapTerm(socket, termInfo)
|
||||
local methods = { 'blit', 'clear', 'clearLine', 'setCursorPos', 'write',
|
||||
@ -13,7 +13,10 @@ local function wrapTerm(socket, termInfo)
|
||||
socket.term[k] = function(...)
|
||||
if not socket.queue then
|
||||
socket.queue = { }
|
||||
os.queueEvent('vnc_flush')
|
||||
Event.onTimeout(0, function()
|
||||
socket:write(socket.queue)
|
||||
socket.queue = nil
|
||||
end)
|
||||
end
|
||||
table.insert(socket.queue, {
|
||||
f = k,
|
||||
@ -32,16 +35,6 @@ local function vncHost(socket, termInfo)
|
||||
|
||||
wrapTerm(socket, termInfo)
|
||||
|
||||
local queueThread = process:newThread('queue_writer', function()
|
||||
while true do
|
||||
os.pullEvent('vnc_flush')
|
||||
if socket.queue then
|
||||
socket:write(socket.queue)
|
||||
socket.queue = nil
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
os.queueEvent('term_resize')
|
||||
|
||||
while true do
|
||||
@ -56,15 +49,13 @@ local function vncHost(socket, termInfo)
|
||||
end
|
||||
end
|
||||
|
||||
queueThread:terminate()
|
||||
|
||||
for k,v in pairs(socket.oldTerm) do
|
||||
socket.term[k] = v
|
||||
end
|
||||
os.queueEvent('term_resize')
|
||||
end
|
||||
|
||||
process:newThread('vnc_server', function()
|
||||
Event.addRoutine(function()
|
||||
|
||||
print('vnc: listening on port 5900')
|
||||
|
||||
|
@ -6,7 +6,8 @@ multishell.setTitle(multishell.getCurrent(), 'Net Daemon')
|
||||
_G.network = { }
|
||||
|
||||
local function netUp()
|
||||
local process = require('process')
|
||||
require = requireInjector(getfenv(1))
|
||||
local Event = require('event')
|
||||
|
||||
local files = fs.list('/sys/network')
|
||||
|
||||
@ -19,19 +20,20 @@ local function netUp()
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
local e = process:pullEvent('device_detach')
|
||||
if not device.wireless_modem or e == 'terminate' then
|
||||
Event.on('device_detach', function()
|
||||
if not device.wireless_modem then
|
||||
Event.exitPullEvents()
|
||||
end
|
||||
end)
|
||||
|
||||
Event.pullEvents()
|
||||
|
||||
for _,c in pairs(network) do
|
||||
c.active = false
|
||||
os.queueEvent('network_detach', c)
|
||||
end
|
||||
os.queueEvent('network_down')
|
||||
process:pullEvent('network_down')
|
||||
process:threadEvent('terminate')
|
||||
break
|
||||
end
|
||||
end
|
||||
Event.pullEvent('network_down')
|
||||
|
||||
Util.clear(_G.network)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user