lua-users home
lua-l archive

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


On Thu, Mar 15, 2012 at 8:29 PM, Sam Roberts <vieuxtech@gmail.com> wrote:
> On Thu, Mar 15, 2012 at 12:40 PM, Matthew Wild <mwild1@gmail.com> wrote:
>> On 15 March 2012 19:19, Flemming Madsen <lua@themadsens.dk> wrote:
>>> Speaking of LuaSocket .. I have a small request ..
>>>
>>> Could we have receive() behavior ala Posix read().
>>>
>>> Ie. after select() reports a steam readable, the next receive() can be
>>> specified non-blocking, no matter the number of requested bytes, and the
>>> number of actually received bytes is returned.
>>>
>>> (A new function, negative count dor receive(), whatever)
>> Are you missing conn:settimeout(0)? If not, do you have a test case
>> where receive() blocks?
>
> I'm confused, too. Is it possible that what you want to do is
> receive() as much data as is currently available, as soon as select()
> says a socket is readable?
>
> This is the most basic usage of the BSD socket API, and while not
> directly supported by luasocket, you can do it like this:
>
> https://github.com/sam-github/swirl/blob/master/lua/sockext.lua, see line 39.

This works because elsewhere sockets are set to have a timeout of 0.
(As a reminder, the select() system call may be misinformed about how
ready a particular fd is, so you need to be reading/writing in
non-blocking mode anyway. Regardless of what POSIX says.)