lua-users home
lua-l archive

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


On 02/24/2010 07:58 AM, Matthew Wild wrote:
> One sticking point seems to be deciding on the API. I believe an IPv6
> socket must be declared so at creation (avoiding platform-specific
> magic). LuaSocket though allows you to create a socket and then
> bind/connect it later, and until then it won't know which kind of
> socket to use. It could be added as an optional new flag to
> socket.tcp(), but some suggest this isn't the "right" way.
> 
> Does anyone have thoughts on this?

The trick of an IPv4-to-IPv6 transition is to think of it as an
IPv4-to-* transition. The programming interfaces developed for getting
an IPv6 socket (getaddrinfo) are generic enough that you just use it for
IPv4, IPv6, and arbitrary future protocols as well.

The key of this is that it takes a hostname (or numeric address) as a
string, and gives you a list of sockets that you try in turn until one
succeeds. This list is ordered in a specific way to ensure maximum
compatibility and success. You use the same getaddrinfo to get a
listening port as well, and it will automatically take care of binding
to whatever is necessary to listen.

For a luasocket API, the trick should be to get rid of places where
explicitly-sized network addresses are stored, and just use strings.
(This may already be the case.) Then use getaddrinfo when constructing
sockets, and you'll get IPv6 (or whatever) automatically. As long as the
socket itself is sufficiently abstract, everything that uses it should
work fine.

There is a good introduction to all of this, including sample client and
server code as well as a map from old IPv4 functions to the new ones:
http://people.redhat.com/drepper/userapi-ipv6.html

I hope this helps, I'm eager to see IPv6 working in luasocket,
implemented in a clean way.


Adam

Attachment: signature.asc
Description: OpenPGP digital signature