This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC 00/17] Merge event loop implementations
> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
> Date: Mon, 25 Feb 2019 13:55:13 -0700
>
> 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.
Thanks. It sounds like most of the adaptation is to use Gnulib's
replacements for these functions, and remove most or all of the
USE_WIN32API ifdef's.
> 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.
I guess stdin is disabled because 'select' doesn't support it. But
with Gnulib, we could allow that, although perhaps not in the initial
phase of the changes.
> 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.
And also 'accept' and 'bind', all of them are available in Gnulib. As
a nice bonus, we get to remove the USE_WIN32API parts that call
'closesocket' where on Posix platforms we call 'close', because
Gnulib's 'close' does that as well.
So, on balance I think if we want to remove USE_WIN32API regarding
sockets and related stuff, importing Gnulib replacements will be much
less work, and might also enable some features that are currently
disabled.