Hi,
I've spent some time polishing up std.socket a bit. I've tried to preserve
compatibility as much as possible.
The branch is here:
https://github.com/CyberShadow/phobos/tree/new-std-socket
A list of commits is here:
https://github.com/CyberShadow/phobos/compare/master...new-std-socket
Docs are here: http://thecybershadow.net/d/new-std-socket/std_socket.html
The most important changes are:
* Incorporate Chris Miller's std.socket updates and license change, which
were posted on Bugzilla as issue 5401 in January.
* Add bounds checking to SocketSet. Previously, adding sockets outside the
SocketSet's capacity was an unsafe operation which could corrupt memory.
* SocketSet now supports variable fd_set sizes on Windows.
* Re-entrant IPv4 name resolution for supported POSIX platforms. This will
potentially speed up existing multi-threaded network code.
* IPv6 address support, with wrapper functions which use IPv4-only
functions when the IPv6 functions are unavailable (Windows versions before
XP).
* Fixes for issues 5177 and 3484.
* Improved documentation, added examples.
* Some minor added functionality, such as retrieval of more detailed error
information, Unix Domain sockets, setting TCP keep-alive options.
I'd appreciate if someone with an existing body of D2 code using
std.socket could try my version, and let me know of any code breakage.
I've heard a lot of criticism about std.socket before. If I haven't fixed
your gripe, feel free to let me know.
Some concerns:
* std.socket enumerations do not conform to D's naming conventions. Fixing
this is complicated, due to (IIUC) enum aliases breaking code which
enumerate enum members, and the inability to deprecate individual enum
members.
* Exceptions retrieve a text description of numerical error codes when
they are created. If it's possible, it would be best to make that happen
when a text description is requested (msg field or .toString), though I
don't think msg being a field allows this.
* InternetAddress (and by convention, Internet6Address) has a constructor
which accepts a hostname. The constructor resolves the hostname and picks
the first address entry. I understand that conflating DNS resolution with
other functionality may be undesirable, so perhaps such functionality
should be deprecated.
* Currently, reverse hostname lookup functions throw on failure. Such
lookups are not reliable and are expected to sometimes fail, so perhaps a
more appropriate behavior would be to return the requested IP address
unchanged, or a value indicating failure (null or false).
* As far as I can tell, the UnknownAddress class is useless. The generic
sockaddr structure it encapsulates is not large enough to abstract and
hold newer socket address structures.
* David Nadlinger added functionality to work around an apparent oddity of
the Windows socket implementation (see WINSOCK_TIMEOUT_SKEW). Although the
hack is documented, I'm a bit uncomfortable with that there are no
provided details or instructions on how to reproduce the experiments and
measurements which led to the inclusion of this hack. (There's also the
question whether a language library's purpose includes working around
apparent bugs in platforms' implementations.)
* Some new functions (notably getAddress) could have probably been named
better. "getAddress", which returns an array of Address class instances,
is the logical extension of getAddressInfo (which returns the addresses
with accompanying information), which in turn is named after the POSIX
getaddrinfo function.
* InternetAddress has constructors and getters which use uint32_t as the
native type for an IPv4 address. Should Internet6Address use ubyte[16]?
Currently it uses the in6_addr structure, which is also used in POSIX
network structures.
--
Best regards,
Vladimir mailto:[email protected]