GNOME Bugzilla – Bug 780875
gsocket: Add support for setting TCP keepalive timeout and interval
Last modified: 2018-05-24 19:28:29 UTC
GSocket currently allows to enable/disable sending of TCP keepalives, but offers no way of changing the interval before keepalive probes are sent, nor the interval between these probes. This commit adds - g_socket_set_keepalive_timeout - g_socket_get_keepalive_timeout - g_socket_set_keepalive_interval - g_socket_get_keepalive_interval to deal with this. Not all platforms support it, though Linux/Windows/OSX/recent BSDs should be fine. Windows support is a bit more limited as the values cannot be read, only set, and can only enable keepalive/set a timeout and an interval all at once.
Created attachment 349186 [details] [review] gsocket: Add support for setting TCP keepalive timeout and interval
What are you doing that you feel this would be useful for? Last time we talked about keepalive the consensus was that it was a mistake to have exposed even SO_KEEPALIVE, because most servers have application-layer timeouts that aren't affected by SO_KEEPALIVE.
Main rationale would be https://lists.freedesktop.org/archives/spice-devel/2017-March/036553.html , ie detect dead SPICE connections without having to wait for 2 hours. After working on this patch, I realized we'd also need some application-layer pings to keep connections alive (having issues with squid read_timeout setting), so I see your point/the consensus. This code can easily live in spice-gtk if it's considered out of scope for glib.
Created attachment 349361 [details] [review] gsocket: Add support for setting TCP keepalive timeout and interval GSocket currently allows to enable/disable sending of TCP keepalives, but offers no way of changing the interval before keepalive probes are sent, nor the interval between these probes. This commit adds - g_socket_set_keepalive_timeout - g_socket_get_keepalive_timeout - g_socket_set_keepalive_interval - g_socket_get_keepalive_interval to deal with this. Not all platforms support it, though Linux/Windows/OSX/recent BSDs should be fine. Windows support is a bit more limited as the values cannot be read, only set, and can only enable keepalive/set a timeout and an interval all at once.
This version is very similar to the previous one except that it was compile-tested with mingw this time.
-- 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/1255.