added a timeout to net.recvstring

This commit is contained in:
Izaya 2017-08-03 12:24:54 +10:00
parent d234a9e4bf
commit 224d2160ac

View File

@ -8,13 +8,17 @@ function net.sendstring(addr,port,msg) -- for sending lots of data
end
end
function net.recvstring(addr,port)
local fr,po,msg = ""
local t,fr,po,msg = {},"","",""
repeat
_,fr,po,msg = event.pull("net_msg")
t,fr,po,msg = event.pull("net_msg",10)
if not t then
return
end
until fr == addr and po == port
local ml,s = tonumber(msg), ""
for i = 1, ml do
_,fr,po,msg = event.pull("net_msg")
t,fr,po,msg = event.pull("net_msg",10)
if t == nil then break end
if fr == addr and po == port then
s=s..tostring(msg)
end