lua-users home
lua-l archive

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


On Tue, Apr 23, 2013 at 04:53:01PM -0700, William Ahern wrote:
> On Tue, Apr 23, 2013 at 07:23:32PM -0400, Rena wrote:
<snip>
> > I've been writing a socket library myself and want to support the same
> > functionality as LuaSocket, in which receive() accepts patterns *l and *a.
> > However I'm not sure what to do about this possibility, nor what LuaSocket
> > does if you specify *a and receive messages from multiple peers. Does it
> > just concat them all together disregarding the source information? Or am I
> > misunderstanding how UDP sockets work?
> 
> UDP preserves message boundaries, so UDP messages will never be
> concatenated. They may be truncated, however--especially if they're very
> long*--or lost entirely. Lost** UDP messages are common on high-load
> servers--e.g. a DNS server or client sending or receiving many packets per
> second.

Just to be clear:

1) By never concatenated I mean recv() or recvfrom() will only every return
a single message, which generally means a message sent by a single call to
send() or sendto()**.

2) By truncated I mean that if the message was 1025 bytes, but you called
recvfrom() with a buffer limit of 1024 bytes, 1 byte of the message will be
lost entirely--the UDP stack will discard the remainder of a message not
copied to the application.


** On Unix read() and write() also work the same way as recv() and send().