mirror of
https://github.com/kepler155c/opus
synced 2025-01-24 06:06:54 +00:00
networking improvements
This commit is contained in:
parent
3a922ad2f4
commit
e287958faa
@ -32,13 +32,13 @@ while true do
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- ensure socket is connected
|
||||||
process:newThread('pinger', function()
|
process:newThread('pinger', function()
|
||||||
while true do
|
while true do
|
||||||
os.sleep(3)
|
os.sleep(3)
|
||||||
if not socket.connected then
|
if not socket:ping() then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
socket:ping()
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -26,22 +26,22 @@ exchange.publicKey = modexp(exchange.base, exchange.secretKey, exchange.primeMod
|
|||||||
|
|
||||||
function socketClass:read(timeout)
|
function socketClass:read(timeout)
|
||||||
|
|
||||||
if not self.connected then
|
|
||||||
Logger.log('socket', 'read: No connection')
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local data, distance = transport.read(self)
|
local data, distance = transport.read(self)
|
||||||
if data then
|
if data then
|
||||||
return data, distance
|
return data, distance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not self.connected then
|
||||||
|
Logger.log('socket', 'read: No connection')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local timerId = os.startTimer(timeout or 5)
|
local timerId = os.startTimer(timeout or 5)
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local e, id = os.pullEvent()
|
local e, id = os.pullEvent()
|
||||||
|
|
||||||
if e == 'transport_' .. self.dport then
|
if e == 'transport_' .. self.sport then
|
||||||
|
|
||||||
data, distance = transport.read(self)
|
data, distance = transport.read(self)
|
||||||
if data then
|
if data then
|
||||||
@ -59,29 +59,25 @@ function socketClass:read(timeout)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function socketClass:write(data)
|
function socketClass:write(data)
|
||||||
if not self.connected then
|
if self.connected then
|
||||||
Logger.log('socket', 'write: No connection')
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
transport.write(self, {
|
transport.write(self, {
|
||||||
type = 'DATA',
|
type = 'DATA',
|
||||||
seq = self.wseq,
|
seq = self.wseq,
|
||||||
data = data,
|
data = data,
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function socketClass:ping()
|
function socketClass:ping()
|
||||||
if not self.connected then
|
if self.connected then
|
||||||
Logger.log('socket', 'ping: No connection')
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
transport.write(self, {
|
transport.write(self, {
|
||||||
type = 'PING',
|
type = 'PING',
|
||||||
seq = self.wseq,
|
seq = self.wseq,
|
||||||
data = data,
|
data = data,
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function socketClass:close()
|
function socketClass:close()
|
||||||
@ -166,7 +162,7 @@ function Socket.connect(host, port)
|
|||||||
socket:close()
|
socket:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
function trusted(msg, port)
|
local function trusted(msg, port)
|
||||||
|
|
||||||
if port == 19 or msg.shost == os.getComputerID() then
|
if port == 19 or msg.shost == os.getComputerID() then
|
||||||
-- no auth for trust server or loopback
|
-- no auth for trust server or loopback
|
||||||
|
@ -92,7 +92,7 @@ while true do
|
|||||||
|
|
||||||
-- use resume instead ??
|
-- use resume instead ??
|
||||||
if not socket.messages[2] then -- table size is 1
|
if not socket.messages[2] then -- table size is 1
|
||||||
os.queueEvent('transport_' .. dport)
|
os.queueEvent('transport_' .. socket.sport)
|
||||||
end
|
end
|
||||||
|
|
||||||
--debug('>> ' .. Util.tostring({ type = 'ACK', seq = msg.seq }))
|
--debug('>> ' .. Util.tostring({ type = 'ACK', seq = msg.seq }))
|
||||||
|
Loading…
Reference in New Issue
Block a user