X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgsocketcontrolmessage.c;h=a526b4f76dd093571a9cc250db018c5f3109bfe2;hb=7a1aaaa1fa02679ecf335a19fffe3f55505921b5;hp=7a519f9ee8afad560b6bfb9d9d5479616f56a94f;hpb=c93c98732aefb8472c94e75fea36f4924c7c746c;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gsocketcontrolmessage.c b/gio/gsocketcontrolmessage.c index 7a519f9..a526b4f 100644 --- a/gio/gsocketcontrolmessage.c +++ b/gio/gsocketcontrolmessage.c @@ -13,18 +13,19 @@ */ /** - * SECTION: gsocketcontrolmessage + * SECTION:gsocketcontrolmessage * @title: GSocketControlMessage - * @short_description: a #GSocket control message + * @short_description: A GSocket control message + * @include: gio/gio.h * @see_also: #GSocket. * * A #GSocketControlMessage is a special-purpose utility message that - * can be sent to or received from a #GSocket. These types of + * can be sent to or received from a #GSocket. These types of * messages are often called "ancillary data". * * The message can represent some sort of special instruction to or * information from the socket or can represent a special kind of - * transfer to the peer (for example, sending a file description over + * transfer to the peer (for example, sending a file descriptor over * a UNIX socket). * * These messages are sent with g_socket_send_message() and received @@ -40,21 +41,18 @@ * g_socket_receive_message() to read such a message. * * Since: 2.22 - **/ + */ #include "config.h" #include "gsocketcontrolmessage.h" +#include "gnetworkingprivate.h" #include "glibintl.h" #ifndef G_OS_WIN32 +#include "gunixcredentialsmessage.h" #include "gunixfdmessage.h" -#include -#else -# include -# include #endif -#include "gioalias.h" G_DEFINE_ABSTRACT_TYPE (GSocketControlMessage, g_socket_control_message, @@ -70,7 +68,7 @@ G_DEFINE_ABSTRACT_TYPE (GSocketControlMessage, * Returns: The number of bytes required. * * Since: 2.22 - **/ + */ gsize g_socket_control_message_get_size (GSocketControlMessage *message) { @@ -86,10 +84,10 @@ g_socket_control_message_get_size (GSocketControlMessage *message) * Returns the "level" (i.e. the originating protocol) of the control message. * This is often SOL_SOCKET. * - * Returns: and int describing the level + * Returns: an integer describing the level * * Since: 2.22 - **/ + */ int g_socket_control_message_get_level (GSocketControlMessage *message) { @@ -102,13 +100,13 @@ g_socket_control_message_get_level (GSocketControlMessage *message) * g_socket_control_message_get_msg_type: * @message: a #GSocketControlMessage * - * Returns the protocol specify type of the control message. - * For instance, for unix fd passing this would be SCM_RIGHTS. + * Returns the protocol specific type of the control message. + * For instance, for UNIX fd passing this would be SCM_RIGHTS. * - * Returns: and int describing the level + * Returns: an integer describing the type of control message * * Since: 2.22 - **/ + */ int g_socket_control_message_get_msg_type (GSocketControlMessage *message) { @@ -130,7 +128,7 @@ g_socket_control_message_get_msg_type (GSocketControlMessage *message) * object. * * Since: 2.22 - **/ + */ void g_socket_control_message_serialize (GSocketControlMessage *message, gpointer data) @@ -151,24 +149,40 @@ g_socket_control_message_class_init (GSocketControlMessageClass *class) { } +/** + * g_socket_control_message_deserialize: + * @level: a socket level + * @type: a socket control message type for the given @level + * @size: the size of the data in bytes + * @data: (array length=size) (element-type guint8): pointer to the message data + * + * Tries to deserialize a socket control message of a given + * @level and @type. This will ask all known (to GType) subclasses + * of #GSocketControlMessage if they can understand this kind + * of message and if so deserialize it into a #GSocketControlMessage. + * + * If there is no implementation for this kind of control message, %NULL + * will be returned. + * + * Returns: (transfer full): the deserialized message or %NULL + * + * Since: 2.22 + */ GSocketControlMessage * -g_socket_control_message_deserialize (int level, - int type, - gsize size, - gpointer data) +g_socket_control_message_deserialize (int level, + int type, + gsize size, + gpointer data) { - GSocketControlMessageClass *klass; GSocketControlMessage *message; GType *message_types; guint n_message_types; int i; -#ifndef G_OS_WIN32 - volatile GType a_type; -#endif /* Ensure we know about the built in types */ #ifndef G_OS_WIN32 - a_type = g_unix_fd_message_get_type (); + g_type_ensure (G_TYPE_UNIX_CREDENTIALS_MESSAGE); + g_type_ensure (G_TYPE_UNIX_FD_MESSAGE); #endif message_types = g_type_children (G_TYPE_SOCKET_CONTROL_MESSAGE, &n_message_types); @@ -176,25 +190,27 @@ g_socket_control_message_deserialize (int level, message = NULL; for (i = 0; i < n_message_types; i++) { - klass = (GSocketControlMessageClass *)g_type_class_ref (type); + GSocketControlMessageClass *class; - if (klass && klass->deserialize) - { - message = klass->deserialize (level, type, size, data); - g_type_class_unref ((GTypeClass *) klass); - } + class = g_type_class_ref (message_types[i]); + message = class->deserialize (level, type, size, data); + g_type_class_unref (class); if (message != NULL) - break; + break; } g_free (message_types); - if (message == NULL) - g_warning ("unknown control message type %d:%d", level, type); + /* It's not a bug if we can't deserialize the control message - for + * example, the control message may be be discarded if it is deemed + * empty, see e.g. + * + * http://git.gnome.org/browse/glib/commit/?id=ec91ed00f14c70cca9749347b8ebc19d72d9885b + * + * Therefore, it's not appropriate to print a warning about not + * being able to deserialize the message. + */ return message; } - -#define __G_SOCKET_CONTROL_MESSAGE_C__ -#include "gioaliasdef.c"