mirror of
https://github.com/kepler155c/opus
synced 2025-10-21 10:47:40 +00:00
networking improvements
This commit is contained in:
@@ -71,6 +71,19 @@ function socketClass:write(data)
|
||||
return true
|
||||
end
|
||||
|
||||
function socketClass:ping()
|
||||
if not self.connected then
|
||||
Logger.log('socket', 'ping: No connection')
|
||||
return false
|
||||
end
|
||||
transport.write(self, {
|
||||
type = 'PING',
|
||||
seq = self.wseq,
|
||||
data = data,
|
||||
})
|
||||
return true
|
||||
end
|
||||
|
||||
function socketClass:close()
|
||||
if self.connected then
|
||||
Logger.log('socket', 'closing socket ' .. self.sport)
|
||||
|
@@ -154,10 +154,11 @@ function Terminal.readPassword(prompt)
|
||||
if prompt then
|
||||
term.write(prompt)
|
||||
end
|
||||
local fn = term.write
|
||||
term.write = function() end
|
||||
local s = read(prompt)
|
||||
term.write = fn
|
||||
local fn = term.current().write
|
||||
term.current().write = function() end
|
||||
local s
|
||||
pcall(function() s = read(prompt) end)
|
||||
term.current().write = fn
|
||||
|
||||
if s == '' then
|
||||
return
|
||||
|
@@ -103,6 +103,14 @@ function Util.keys(t)
|
||||
return keys
|
||||
end
|
||||
|
||||
function Util.invert(t)
|
||||
local nt = { }
|
||||
for k,v in pairs(t) do
|
||||
nt[v] = k
|
||||
end
|
||||
return nt
|
||||
end
|
||||
|
||||
function Util.merge(obj, args)
|
||||
if args then
|
||||
for k,v in pairs(args) do
|
||||
|
@@ -110,9 +110,9 @@ function os.getVersion()
|
||||
local version
|
||||
|
||||
if _CC_VERSION then
|
||||
version = tonumber(_CC_VERSION)
|
||||
version = tonumber(_CC_VERSION:gmatch('[%d]+%.?[%d][%d]', '%1')())
|
||||
end
|
||||
if _HOST then
|
||||
if not version and _HOST then
|
||||
version = tonumber(_HOST:gmatch('[%d]+%.?[%d][%d]', '%1')())
|
||||
end
|
||||
|
||||
|
@@ -5,6 +5,8 @@
|
||||
* write acknowledgements
|
||||
* background read buffering
|
||||
]]--
|
||||
require = requireInjector(getfenv(1))
|
||||
local Logger = require('logger')
|
||||
|
||||
multishell.setTitle(multishell.getCurrent(), 'Net transport')
|
||||
|
||||
@@ -51,6 +53,7 @@ while true do
|
||||
if e == 'timer' then
|
||||
local socket = transport.timers[timerId]
|
||||
if socket and socket.connected then
|
||||
Logger.log('transport', 'timeout - closing socket ' .. socket.sport)
|
||||
socket:close()
|
||||
transport.timers[timerId] = nil
|
||||
end
|
||||
@@ -73,8 +76,15 @@ while true do
|
||||
socket.timers[msg.seq] = nil
|
||||
transport.timers[timerId] = nil
|
||||
|
||||
elseif msg.type == 'PING' then
|
||||
socket.transmit(socket.dport, socket.dhost, {
|
||||
type = 'ACK',
|
||||
seq = msg.seq,
|
||||
})
|
||||
|
||||
elseif msg.type == 'DATA' and msg.data then
|
||||
if msg.seq ~= socket.rseq then
|
||||
Logger.log('transport', 'seq error - closing socket ' .. socket.sport)
|
||||
socket:close()
|
||||
else
|
||||
socket.rseq = socket.rseq + 1
|
||||
|
Reference in New Issue
Block a user