#include "gtcpconnection.h"
#include "glibintl.h"
-#include "gioalias.h"
/**
* SECTION:gsocketconnection
* depends on the type of the underlying socket that is in use. For
* instance, for a TCP/IP connection it will be a #GTcpConnection.
*
- * Chosing what type of object to construct is done with the socket
+ * Choosing what type of object to construct is done with the socket
* connection factory, and it is possible for 3rd parties to register
* custom socket connection types for specific combination of socket
* family/type/protocol using g_socket_connection_factory_register_type().
* Since: 2.22
*/
-G_DEFINE_TYPE (GSocketConnection,
- g_socket_connection, G_TYPE_IO_STREAM);
+G_DEFINE_TYPE (GSocketConnection, g_socket_connection, G_TYPE_IO_STREAM);
enum
{
GSocket *socket;
GInputStream *input_stream;
GOutputStream *output_stream;
+
+ gboolean in_dispose;
};
static gboolean g_socket_connection_close (GIOStream *stream,
* This can be useful if you want to do something unusual on it
* not supported by the #GSocketConnection APIs.
*
- * Returns: a #GSocketAddress or %NULL on error.
+ * Returns: (transfer none): a #GSocketAddress or %NULL on error.
*
* Since: 2.22
*/
*
* Try to get the local address of a socket connection.
*
- * Returns: a #GSocketAddress or %NULL on error.
+ * Returns: (transfer full): a #GSocketAddress or %NULL on error.
* Free the returned object with g_object_unref().
*
* Since: 2.22
*
* Try to get the remote address of a socket connection.
*
- * Returns: a #GSocketAddress or %NULL on error.
+ * Returns: (transfer full): a #GSocketAddress or %NULL on error.
* Free the returned object with g_object_unref().
*
* Since: 2.22
}
static void
+g_socket_connection_dispose (GObject *object)
+{
+ GSocketConnection *connection = G_SOCKET_CONNECTION (object);
+
+ connection->priv->in_dispose = TRUE;
+
+ G_OBJECT_CLASS (g_socket_connection_parent_class)
+ ->dispose (object);
+
+ connection->priv->in_dispose = FALSE;
+}
+
+static void
g_socket_connection_finalize (GObject *object)
{
GSocketConnection *connection = G_SOCKET_CONNECTION (object);
gobject_class->get_property = g_socket_connection_get_property;
gobject_class->constructed = g_socket_connection_constructed;
gobject_class->finalize = g_socket_connection_finalize;
+ gobject_class->dispose = g_socket_connection_dispose;
stream_class->get_input_stream = g_socket_connection_get_input_stream;
stream_class->get_output_stream = g_socket_connection_get_output_stream;
g_input_stream_close (connection->priv->input_stream,
cancellable, NULL);
+ /* Don't close the underlying socket if this is being called
+ * as part of dispose(); when destroying the GSocketConnection,
+ * we only want to close the socket if we're holding the last
+ * reference on it, and in that case it will close itself when
+ * we unref it in finalize().
+ */
+ if (connection->priv->in_dispose)
+ return TRUE;
+
return g_socket_close (connection->priv->socket, error);
}
if (class->close_fn &&
!class->close_fn (stream, cancellable, &error))
{
- g_simple_async_report_gerror_in_idle (G_OBJECT (stream),
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (stream),
callback, user_data,
error);
- g_error_free (error);
return;
}
* @protocol: a protocol id
*
* Looks up the #GType to be used when creating socket connections on
- * sockets with the specified @family,@type and @protocol.
+ * sockets with the specified @family, @type and @protocol.
*
* If no type is registered, the #GSocketConnection base type is returned.
*
a_type = g_unix_connection_get_type ();
#endif
a_type = g_tcp_connection_get_type ();
+ (a_type); /* To avoid -Wunused-but-set-variable */
}
/**
* @protocol_id: a protocol id
*
* Looks up the #GType to be used when creating socket connections on
- * sockets with the specified @family,@type and @protocol_id.
+ * sockets with the specified @family, @type and @protocol_id.
*
* If no type is registered, the #GSocketConnection base type is returned.
*
* Creates a #GSocketConnection subclass of the right type for
* @socket.
*
- * Returns: a #GSocketConnection
+ * Returns: (transfer full): a #GSocketConnection
*
* Since: 2.22
*/
g_socket_get_protocol (socket));
return g_object_new (type, "socket", socket, NULL);
}
-
-#define __G_SOCKET_CONNECTION_C__
-#include "gioaliasdef.c"