Re: [RFC 00/17] Merge event loop implementations

Tom Tromey
2019-02-25T20:55:19Z

Eli> Can you point me to the gdbserver code which calls 'socket' and
Eli> 'accept' on Windows, whose results are used in 'select'? I'd like to
Eli> see what it does on Windows, to be able to have a better idea of what
Eli> adaptations would be necessary for Gnulib's 'select'.

Everything is in gdb/gdbserver/remote-utils.c. Search for the calls to
add_file_handler.

handle_accept_event calls accept, sets remote_desc, then calls
add_file_handler for it.

remote_open does the other call. It is maybe less than obvious but this
code rules out the use of stdin on windows:

#ifdef USE_WIN32API
if (port_str == NULL)
error ("Only HOST:PORT is supported on this platform.");
#endif

So, the STDIO_CONNECTION_NAME branch cannot be taken; the others are
#if'd out; leaving just the final one that calls add_file_handler on
listen_desc. listen_desc is actually created in remote_prepare.

Eli> Offhand, I think we'd need just the trivial adaptations, like make
Eli> sure gdbserver uses file descriptors instead of HSOCKETs on Windows as
Eli> well. Probably it would be best to import Gnulib's 'socket' and
Eli> 'accept' as well, and use their SOCKET_TO_FD and FD_TO_SOCKET macros
Eli> if/where needed (hopefully nowhere). Are there any more related APIs,
Eli> besides those 3? I guess, 'close' (which should call 'closesocket' on
Eli> Windows) and perhaps 'ioctl'? Gnulib has those as well.

gdbserver uses setsockopt as well.

Tom