This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author neologix
Recipients ezio.melotti, maker, neologix, pitrou, santoso.wijaya, vstinner
Date 2013-08-29.14:13:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAH_1eM37KJ7JuFaiN-xYxLiAjiNR2+H1QBz2kbDyN69pK=FvjQ@mail.gmail.com>
In-reply-to <CAH_1eM2c2iLOVKOUQk-37j4XfibomJhy7muj-eUQ9t0G-AEDig@mail.gmail.com>
Content
Here's a patch using inet_pton() if available, otherwise inet_aton()
if available, otherwise fallback to getaddrinfo().
This should work on every platform, but if a platform has neither
inet_pton() nor inet_aton(), calling getaddrinfo() will incur an
overhead.
All Unices have either inet_aton() or inet_pton().
For Windows >= Vista, inet_pton() is available.
I'm not sure whether XP has one of them: if not, then we might keep
the hand-parsing as a fallback.

This adds support for numeric IPv6 addresses (if inet_pton() is
available), which notably speeds up sendto() on IPv6 sockets, and
gives a tiny speedup for IPv4 sockets:
before:
$ ./python -m timeit -s "import socket; s =
socket.socket(socket.AF_INET, socket.SOCK_DGRAM); DATA = b'x'"
"s.sendto(DATA, ('127.0.0.1', 4242))"
100000 loops, best of 3: 13.2 usec per loop
$ ./python -m timeit -s "import socket; s =
socket.socket(socket.AF_INET6, socket.SOCK_DGRAM); DATA = b'x'"
"s.sendto(DATA, ('::1', 4242))"
10000 loops, best of 3: 32.1 usec per loop
after:
$ ./python -m timeit -s "import socket; s =
socket.socket(socket.AF_INET, socket.SOCK_DGRAM); DATA = b'x'"
"s.sendto(DATA, ('127.0.0.1', 4242))"
100000 loops, best of 3: 11.5 usec per loop
$ ./python -m timeit -s "import socket; s =
socket.socket(socket.AF_INET6, socket.SOCK_DGRAM); DATA = b'x'"
"s.sendto(DATA, ('::1', 4242))"
100000 loops, best of 3: 12.8 usec per loop

Note that if the IPv6 address contains a scope ID ('%' suffix), then
we fallback to getaddrinfo() which handles it properly (the scope ID
can be an interface index but also an interface name).
Files
File name Uploaded
parse_inet.diff neologix, 2013-08-29.14:13:59
History
Date User Action Args
2013-08-29 14:13:59neologixsetrecipients: + neologix, pitrou, vstinner, ezio.melotti, santoso.wijaya, maker
2013-08-29 14:13:59neologixlinkissue16201 messages
2013-08-29 14:13:59neologixcreate