After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 736441 - Printing a socket address is too complex
Printing a socket address is too complex
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-09-10 21:17 UTC by Paolo Borelli
Modified: 2018-05-24 17:01 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Paolo Borelli 2014-09-10 21:17:21 UTC
logging a simple message like "Connected to 123.123.123.123:42" requires *a lot* of boring code:

 - from the connection you get the GSocketAddress
 - you cast GSocketAddress to GInetSocketAddress making an ugly assumption
 - from the GInetSocketAddress you get the GInetAddress
 - GInetAddress finally has a to_string() method that just gives you the IP part
 - the you get the port from the the GInetSocketAddress
 - then you strdup_printf the two


GSocketAddress should have a print method that

1) takes care of all this stuff for me
2) does not require to assume that it can be casted to a specific subclass

I guess (2) requires adding a vfunc implemented by the subclasses
Comment 1 Dan Winship 2014-09-11 11:37:08 UTC
(In reply to comment #0)
>  - you cast GSocketAddress to GInetSocketAddress making an ugly assumption

Well, you generally know that it's a GInetSocketAddress. But it might be a GProxyAddress, which is a subclass of that, but in that case you might want to show both the proxy address and the final destination.

> I guess (2) requires adding a vfunc implemented by the subclasses

which unfortunately we can't do, because many of the networking-related classes accidentally got added without extra padding in their class structs.
Comment 2 Paolo Borelli 2014-09-11 14:54:42 UTC
Some ideas, none particularly clean:

1 - add a display-name property and override it in the subclasses instead of the vfunc  
2 - (ab)use g_signal_new_class_handler to add an overridable vfunc
3 - hardcode a "case IS_INSTANCE_OF ()" in the base class for the known subclasses and just print "unknown" for the rest, since subclassing is pretty rare
Comment 3 Dan Winship 2014-09-11 16:17:47 UTC
(In reply to comment #2)
> 1 - add a display-name property and override it in the subclasses instead of
> the vfunc  

That's probably the cleanest, and you can provide a wrapper method to fetch it, in which case it looks just the same as a vmethod from the caller's point of view.
Comment 4 Michael Catanzaro 2018-03-21 00:49:06 UTC
Adjusting component to gio in preparation for GitLab migration
Comment 5 GNOME Infrastructure Team 2018-05-24 17:01:08 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/926.