lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


lua@zevv.nl wrote:
> So, what do I need to do to handle this properly ? Is there a 
> way to make tcp.receive() have the same behaviour as my 
> libc's receive(), that is
> 
> - don't receive any more then the requested amount of bytes from the
>   socket, and leave the rest pending so select() will notice there's
>   still data waiting to be read.
> 
> - also return when fewer then the requested amount of bytes are
>   received, returning both the data and it's size

According to the doc of receive in LuaSocket [1], you can pass "*a" as a
pattern to read all the data available in the socket. Also socket.select
[2] should tell if characters are available for reading, so it should
return any socket that has unread buffered data, even if no socket
actually received data (though there may be a bug somewhere).

Also if you want to read a specific maximum of bytes (eg. up to 8
bytes), you can set the socket to non blocking mode, and then read 8
bytes, and you may have a partial result available (still according to
receive doc [1] in such a case it should
nil,'timeout',<partial_result>).

[1]
http://www.cs.princeton.edu/~diego/professional/luasocket/udp.html#recei
ve
[2]
http://www.cs.princeton.edu/~diego/professional/luasocket/socket.html#se
lect