lua-users home
lua-l archive

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

On Tue, Jul 22, 2014 at 01:52:13AM -0400, Sean Conner wrote:
> It was thus said that the Great Nicolas CARRIER once stated:
> > Ok, your solution is interesting, but my issue doesn't correspond well.
> > 
> > The problem is, because of how the API is written, the whole array
> > address array must be freed at once, so I can't store only an address in
> > the tiny user data, but also a pointer, or something to retrieve the
> > address of the original array. What's more, I can't free the array when
> > the garbage collector decides to free one address, because the others
> > could be still in use, so I have to implement a mechanism for freeing it
> > at the right time (e.g. reference counting).
> > 
> > So I think I'll make a copy of each address in a lua allocated user data
> > and let lua take care of all.
> > 
> > For information, the address structure is basically a union of the
> > standard address types: socaddr_in, _in6 and _un, so an address is
> > approximately a hundred of bytes.
>   I use the same approach [1][2] and don't find it to be that much of a
> problem.  It's not called often enough to be a performance issue and it
> makes working with the results much easier in the long run.
>   -spc 
> [1]	The first instance is to enumerate all the network interfaces under
> 	Linux:

Kinda off-topic, but I noticed your source code comment says that getifaddrs
is "Linux-only". getifaddrs was original to BSDi. Linux adopted it. It's
supported by not only all the modern BSDs, but also Solaris 11 and even QNX.
It should be trivial to emulate on other systems, like AIX.

I'll probably add it to my Lua Unix module, with emulation on AIX. Looks
simple enough.