* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Authors: Christian Kellner <gicmo@gnome.org>
* Samuel Cormier-Iijima <sciyoshi@gmail.com>
* SECTION:gsocketlistener
* @title: GSocketListener
* @short_description: Helper for accepting network client connections
+ * @include: gio/gio.h
* @see_also: #GThreadedSocketService, #GSocketService.
*
* A #GSocketListener is an object that keeps track of a set
* Since: 2.22
*/
-G_DEFINE_TYPE (GSocketListener, g_socket_listener, G_TYPE_OBJECT);
-
enum
{
PROP_0,
guint closed : 1;
};
+G_DEFINE_TYPE_WITH_PRIVATE (GSocketListener, g_socket_listener, G_TYPE_OBJECT)
+
static void
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)
{
GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
- g_type_class_add_private (klass, sizeof (GSocketListenerPrivate));
-
gobject_class->finalize = g_socket_listener_finalize;
gobject_class->set_property = g_socket_listener_set_property;
gobject_class->get_property = g_socket_listener_get_property;
static void
g_socket_listener_init (GSocketListener *listener)
{
- listener->priv = G_TYPE_INSTANCE_GET_PRIVATE (listener,
- G_TYPE_SOCKET_LISTENER,
- GSocketListenerPrivate);
+ listener->priv = g_socket_listener_get_instance_private (listener);
listener->priv->sockets =
g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
listener->priv->listen_backlog = 10;
* 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
socket = g_socket_accept (accept_socket, g_task_get_cancellable (task), &error);
if (socket)
{
- g_task_return_pointer (task, socket, g_object_unref);
source_object = g_object_get_qdata (G_OBJECT (accept_socket), source_quark);
if (source_object)
g_object_set_qdata_full (G_OBJECT (task),
source_quark,
g_object_ref (source_object), g_object_unref);
+ g_task_return_pointer (task, socket, g_object_unref);
}
else
{