Recently I’ve been messing around with net.tcp module in order to exchange some data with server over socks. What I have noticed is that net.tcp.recv() function has fixed buffer size set to 4KB (4096bytes), which is not mentioned in documentation. As a result of that – single call gets from server only first 4KB chunk of data and does not notify if there is more to fetch. Consequent calls of recv() will ofcourse return additional 4KB of data left, _until_ end of trasnmission which will result in throwing “Timeout occurred before data was available on connection” error.
I’ve managed to workaround this issue by checking in loop if buffer contains endOfTransmission marker. (It is not completly safe though, as it may produce false positives if message contains endOfTransmission marker itself)
local receivedData, hasData, eotMarker = '', true, "EOT" local s = net.tcp.connect('localhost:8086') s:send(query) while hasData do local buffer = s:recv() receivedData = receivedData .. buffer if buffer:ends(eotMarker) then hasData = false end end
Please consider overloading net.tcp.recv() with something like net.tcp.recv(size), where size would be customized buffer size to read from socks server. Or perhaps add a possibility to alter currently fixed buffer size.
It would be nice also if recv() returned additional bool parameter indicating that there is more data to fetch from server.
Edit: some typos.
You must be logged in to reply to this topic.