X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgsocketconnection.c;h=9f490c84564c3bff82f08a2c81652b221b8348bd;hb=33b9935efc82f8cc4747dfea2743129dfc418d19;hp=d60f1989635a532dc32babac839d373ce36ee645;hpb=d21309464cbbe3970a08a10d1a1a91ebf279dadb;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gsocketconnection.c b/gio/gsocketconnection.c index d60f198..9f490c8 100644 --- a/gio/gsocketconnection.c +++ b/gio/gsocketconnection.c @@ -15,9 +15,7 @@ * 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 . * * Authors: Christian Kellner * Samuel Cormier-Iijima @@ -31,6 +29,7 @@ #include "gsocketoutputstream.h" #include "gsocketinputstream.h" +#include "gioprivate.h" #include #include #include "gunixconnection.h" @@ -57,11 +56,13 @@ * custom socket connection types for specific combination of socket * family/type/protocol using g_socket_connection_factory_register_type(). * + * To close a #GSocketConnection, use g_io_stream_close(). Closing both + * substreams of the #GIOStream separately will not close the underlying + * #GSocket. + * * Since: 2.22 */ -G_DEFINE_TYPE (GSocketConnection, g_socket_connection, G_TYPE_IO_STREAM); - enum { PROP_NONE, @@ -74,6 +75,8 @@ struct _GSocketConnectionPrivate GInputStream *input_stream; GOutputStream *output_stream; + GSocketAddress *cached_remote_address; + gboolean in_dispose; }; @@ -89,6 +92,8 @@ static gboolean g_socket_connection_close_finish (GIOStream *stream, GAsyncResult *result, GError **error); +G_DEFINE_TYPE_WITH_PRIVATE (GSocketConnection, g_socket_connection, G_TYPE_IO_STREAM) + static GInputStream * g_socket_connection_get_input_stream (GIOStream *io_stream) { @@ -305,6 +310,13 @@ g_socket_connection_get_local_address (GSocketConnection *connection, * * Try to get the remote address of a socket connection. * + * Since GLib 2.40, when used with g_socket_client_connect() or + * g_socket_client_connect_async(), during emission of + * %G_SOCKET_CLIENT_CONNECTING, this function will return the remote + * address that will be used for the connection. This allows + * applications to print e.g. "Connecting to example.com + * (10.42.77.3)...". + * * Returns: (transfer full): a #GSocketAddress or %NULL on error. * Free the returned object with g_object_unref(). * @@ -314,9 +326,27 @@ GSocketAddress * g_socket_connection_get_remote_address (GSocketConnection *connection, GError **error) { + if (!g_socket_is_connected (connection->priv->socket)) + { + return connection->priv->cached_remote_address ? + g_object_ref (connection->priv->cached_remote_address) : NULL; + } return g_socket_get_remote_address (connection->priv->socket, error); } +/* Private API allowing applications to retrieve the resolved address + * now, before we start connecting. + * + * https://bugzilla.gnome.org/show_bug.cgi?id=712547 + */ +void +g_socket_connection_set_cached_remote_address (GSocketConnection *connection, + GSocketAddress *address) +{ + g_clear_object (&connection->priv->cached_remote_address); + connection->priv->cached_remote_address = address ? g_object_ref (address) : NULL; +} + static void g_socket_connection_get_property (GObject *object, guint prop_id, @@ -370,6 +400,8 @@ g_socket_connection_dispose (GObject *object) connection->priv->in_dispose = TRUE; + g_clear_object (&connection->priv->cached_remote_address); + G_OBJECT_CLASS (g_socket_connection_parent_class) ->dispose (object); @@ -399,8 +431,6 @@ g_socket_connection_class_init (GSocketConnectionClass *klass) GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GIOStreamClass *stream_class = G_IO_STREAM_CLASS (klass); - g_type_class_add_private (klass, sizeof (GSocketConnectionPrivate)); - gobject_class->set_property = g_socket_connection_set_property; gobject_class->get_property = g_socket_connection_get_property; gobject_class->constructed = g_socket_connection_constructed; @@ -427,9 +457,7 @@ g_socket_connection_class_init (GSocketConnectionClass *klass) static void g_socket_connection_init (GSocketConnection *connection) { - connection->priv = G_TYPE_INSTANCE_GET_PRIVATE (connection, - G_TYPE_SOCKET_CONNECTION, - GSocketConnectionPrivate); + connection->priv = g_socket_connection_get_instance_private (connection); } static gboolean