lua-users home
lua-l archive

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


It was thus said that the Great Coroutines once stated:
> On Mon, Aug 25, 2014 at 4:38 PM, Sean Conner <sean@conman.org> wrote:
> 
> >   There are four functions you can use to read data from a socket:
> >
> >         read()
> >         recv()
> >         recvfrom()
> >         recvmsg()
> >
> >   read() is fine for TCP and for "connected" UDP sockets [1], but for
> > unconnected TCP (or even packets for other IP protocols like OSPF) you can't
> > use read().  That's one reason I rejected using read().
> 
> Secret:  You can associate the remote peer (sockaddr) with a UDP
> socket by calling connect() -- after that I believe you can call
> read() like normal.

  Sure, on the client side.  On the server side, there is no UDP equivalent
of listen().  Yes, you can use recv() only on the server side, but then you
remove any chance of sending back a reply (note:  this applies to UDP).   

> >   Harder than it sounds.  One thougt I did have was to "tweak" the type byte
> > in the common header from LUA_TUSERDATA to LUA_TSTRING, but then I looked at
> > the defintions of both strings and userdata:
> >
> > typedef union TString {
> >   L_Umaxalign dummy;  /* ensures maximum alignment for strings */
> >   struct {
> >     CommonHeader;
> >     lu_byte reserved;
> >     unsigned int hash;
> >     size_t len;
> >   } tsv;
> > } TString;
> >
> > typedef union Udata {
> >   L_Umaxalign dummy;  /* ensures maximum alignment for ocal' udata */
> >   struct {
> >     CommonHeader;
> >     struct Table *metatable;
> >     struct Table *env;
> >     size_t len;
> >   } uv;
> > } Udata;
> >
> >   You *MIGHT* get away with that on a 32-bit system where sizeof(pointer) ==
> > sizeof(int) == sizeof(lu_byte + padding) and nothing touches the hash,
> > metatable or env fields of either structure.  But on a 64-bit system, I
> > woudn't count on sizeof(tsv) (from TString) being equal to sizeof(uv) (from
> > Udata).
> 
> Hmm this will take some time for me to understand :>  Thanks for
> finding the relevant bits for me <3

  You mean you didn't even bother to do *this*?  <headdesk>

  -spc