GNOME Bugzilla – Bug 712547
GSocketClient "event" not useful for determining resolved address
Last modified: 2013-11-18 22:16:39 UTC
So in my app "hotssh" I'm using GSocketClient, and I wanted to monitor the connection status. Like: Connecting to userinput.example.com... # No outstanding state Connecting to userinput.example.com (10.7.42.3) # After we've resolved address Connected to userinput.example.com (10.7.42.3) - frobnicating # After we've connect()ed I haven't actually done much raw socket stuff with Gio before, but I saw the "event" signal on GSocketClient, and assumed this *had* to be for exactly this use case, and I wrote: https://git.gnome.org/browse/hotssh/commit/?id=737a9fb2a7fc22878590ce323517277545f365d5 But then I read the glib source when my code didn't work, and yeah...from what I can tell we just don't pass "address" anywhere accessible to the application code before we're actually done attempting the connect() =( I'd like to not have to enumerate the GSocketConnectable myself and such... Am I missing something?
Doh. Yeah, this is broken. (The event signal is for several different use cases (bug 665805), but for the "progress message" use case I was thinking in terms of web browsers, where they don't show the IP address to the user, so I never noticed that it wasn't even available.) It shouldn't break anyone if we added some API so that GSocketClient can set GSocketConnection's remote_address before it's connected. (The only way it could break things is if someone was calling g_socket_connection_get_remote_address() from a GSocketClient::event CONNECTING handler, and then asserting that the result was NULL. Which would be silly.)
Created attachment 260167 [details] [review] GSocketClient: For _CONNECTING event, make remote address accessible My application (hotssh) would like to get the resolved address from DNS, before we start the connect(). Without adding an event (which would be an ABI break of sorts), cache it on the GSocketConnection.
Created attachment 260168 [details] [review] GSocketClient: For _CONNECTING event, make remote address accessible Now with correct entry in Makefile.am
Comment on attachment 260168 [details] [review] GSocketClient: For _CONNECTING event, make remote address accessible > gio/gsocketconnection-private.h | 35 +++++++++++++++++++++++++++++++++++ You could use gioprivate.h if you wanted. >+_g_socket_connection_set_cached_remote_address (GSocketConnection *connection, You don't need to use a "_" prefix these days, since anything not marked GLIB_AVAILABLE_IN_ won't get exported. Anyway, good to commit with either of the above changes or not. oh, and: > Without adding an event (which would be an ABI break of sorts) The ::event docs explicitly warn: * Note that there may be additional #GSocketClientEvent values in * the future; unrecognized @event values should be ignored.
Thanks! Committed with those fixes, plus some docs. Attachment 260168 [details] pushed as a46459b - GSocketClient: For _CONNECTING event, make remote address accessible