1
0
mirror of https://github.com/ShadowKatStudios/OC-Minitel.git synced 2024-11-23 10:38:05 +11:00

made timeouts shorter and made stuff fail when it times out, resolves #3 hopefully

This commit is contained in:
Izaya 2018-06-17 23:00:19 +10:00
parent e74b8282c6
commit ad3c6d8433
2 changed files with 15 additions and 9 deletions

View File

@ -21,7 +21,7 @@ local listener = false
local dbug = false local dbug = false
local modems = {} local modems = {}
local port = 4096 local port = 4096
local retry = 30 local retry = 10
local route = true local route = true
--[[ --[[
@ -51,7 +51,7 @@ local pqueue = {}
-- packet cache: [packet ID]=uptime -- packet cache: [packet ID]=uptime
local pcache = {} local pcache = {}
local pctime = 30 local pctime = 15
local function dprint(...) local function dprint(...)
if dbug then if dbug then

View File

@ -2,7 +2,7 @@ local computer = require "computer"
local event = require "event" local event = require "event"
local net = {} local net = {}
net.mtu = 4096 net.mtu = 4096
net.streamdelay = 60 net.streamdelay = 30
net.minport = 32768 net.minport = 32768
net.maxport = 65535 net.maxport = 65535
net.openports = {} net.openports = {}
@ -20,11 +20,13 @@ function net.usend(to,port,data,npID)
end end
function net.rsend(to,port,data) function net.rsend(to,port,data)
local pid = net.genPacketID() local pid, stime = net.genPacketID(), computer.uptime() + net.streamdelay
computer.pushSignal("net_send",1,to,port,data,pid) computer.pushSignal("net_send",1,to,port,data,pid)
repeat repeat
_,rpid = event.pull("net_ack") _,rpid = event.pull(0.5,"net_ack")
until rpid == pid until rpid == pid or computer.uptime() > stime
if not rpid then return false end
return true
end end
-- ordered packet delivery, layer 4? -- ordered packet delivery, layer 4?
@ -40,15 +42,18 @@ function net.send(to,port,ldata)
tdata = {ldata} tdata = {ldata}
end end
for k,v in ipairs(tdata) do for k,v in ipairs(tdata) do
net.rsend(to,port,v) if not net.rsend(to,port,v) then return false end
end end
return true
end end
-- socket stuff, layer 5? -- socket stuff, layer 5?
local function cwrite(self,data) local function cwrite(self,data)
if self.state == "open" then if self.state == "open" then
net.send(self.addr,self.port,data) if not net.send(self.addr,self.port,data) then
self:close()
end
end end
end end
local function cread(self,length) local function cread(self,length)
@ -58,13 +63,14 @@ local function cread(self,length)
return rdata return rdata
end end
local function socket(addr,port,sclose) -- todo, add remote closing of sockets local function socket(addr,port,sclose)
local conn = {} local conn = {}
conn.addr,conn.port = addr,tonumber(port) conn.addr,conn.port = addr,tonumber(port)
conn.rbuffer = "" conn.rbuffer = ""
conn.write = cwrite conn.write = cwrite
conn.read = cread conn.read = cread
conn.state = "open" conn.state = "open"
conn.sclose = sclose
local function listener(_,f,p,d) local function listener(_,f,p,d)
if f == conn.addr and p == conn.port then if f == conn.addr and p == conn.port then
if d == sclose then if d == sclose then