[bind10-dev] the socket descriptor type
Francis Dupont
fdupont at isc.org
Sun Jul 1 16:47:39 UTC 2012
There are many issues related to the socket descriptor type, hidden
today because the code is written at 100% for Unixes.
First there is a good news: if there is no "local/unix" socket domain
on Windows, there is a clean way to transfer an open socket descriptor
between processes (IMHO simply because it is a very useful feature :-).
I write socket descriptor when in all code comments, file, function,
..., names it is file descriptor because in fact it is allways about
sockets (so the fact real file descriptors on Windows are different
doesn't matter). IMHO comments should be improved but I can't see
a critical reason to rename files, functions, ...
The main issue is the type: on Unixes the type is an int, on Windows
it is SOCKET (UINT_PTR). There are two ways to solve this:
- use a #ifdef _WIN32 to choose the correct type. It works but
it is not the "C++ way"
- import asio::detail socket_types defines
BTW it should be fine to use too the invalid_socket idea too
(-1 (not 0 as I can see from time to time) and INVALID_SOCKET),
which is part of socket_types. Note this means the type of recv_fd()
is wrong because it overloads the result between errors and values.
Regards
Francis Dupont <fdupont at isc.org>
PS: it should fine again to limit the socket descriptor transfer to
a few code files: I can see in recent sources at least 3 different
variants, i.e., it follows the Linux way (write new code and bother
of the already existing one only when a name conflicts), not the BSD
way (first look for the same function in the existing code and
minimize the effort).
More information about the bind10-dev
mailing list