[glib] gsocketlistener: Don’t explicitly close so ckets on finalisation



commit f1095de46f5f43edf494ea6adcabbe86685baadf
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Mon Jun 23 15:01:28 2014 +0100

    gsocketlistener: Don’t explicitly close sockets on finalisation
    
    Instead of closing the sockets explicitly, let them close themselves
    when their final reference is dropped. This makes use of
    g_socket_listener_add_socket() more natural.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732107

 gio/gsocketlistener.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/gio/gsocketlistener.c b/gio/gsocketlistener.c
index 1848900..7185745 100644
--- a/gio/gsocketlistener.c
+++ b/gio/gsocketlistener.c
@@ -82,9 +82,11 @@ g_socket_listener_finalize (GObject *object)
   if (listener->priv->main_context)
     g_main_context_unref (listener->priv->main_context);
 
-  if (!listener->priv->closed)
-    g_socket_listener_close (listener);
-
+  /* Do not explicitly close the sockets. Instead, let them close themselves if
+   * their final reference is dropped, but keep them open if a reference is
+   * held externally to the GSocketListener (which is possible if
+   * g_socket_listener_add_socket() was used).
+   */
   g_ptr_array_free (listener->priv->sockets, TRUE);
 
   G_OBJECT_CLASS (g_socket_listener_parent_class)
@@ -206,6 +208,11 @@ check_listener (GSocketListener *listener,
  * useful if you're listening on multiple addresses and do
  * different things depending on what address is connected to.
  *
+ * The @socket will not be automatically closed when the @listener is finalized
+ * unless the listener held the final reference to the socket. Before GLib 2.42,
+ * the @socket was automatically closed on finalization of the @listener, even
+ * if references to it were held elsewhere.
+ *
  * Returns: %TRUE on success, %FALSE on error.
  *
  * Since: 2.22


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]