Remove protocol names, instead use an enum with common protocols
authorAlexander Larsson <alexl@redhat.com>
Wed, 20 May 2009 10:01:29 +0000 (12:01 +0200)
committerAlexander Larsson <alexl@redhat.com>
Wed, 20 May 2009 10:14:50 +0000 (12:14 +0200)
The whole protocol name thing is pretty weird. The getprotobyname functions
seem to only specify one mapping for name <-> ids, so all families/types
must use the same values. Plus the values used for the protocols are
standardized by IANA, so are always the same.

So, we drop using names for protocols, intead introducing an enum with
a few commonly availible and used protocols.

16 files changed:
docs/reference/gio/#gio-unused.txt# [new file with mode: 0644]
docs/reference/gio/aa [new file with mode: 0644]
docs/reference/gio/b [new file with mode: 0644]
docs/reference/gio/bb [new file with mode: 0644]
docs/reference/gio/gio-sections.txt
gio/gio.symbols
gio/gioenums.h
gio/gsocket.c
gio/gsocket.h
gio/gsocketclient.c
gio/gsocketclient.h
gio/gsocketconnection.c
gio/gsocketlistener.c
gio/gsocketlistener.h
gio/gtcpconnection.c
gio/gunixconnection.c

diff --git a/docs/reference/gio/#gio-unused.txt# b/docs/reference/gio/#gio-unused.txt#
new file mode 100644 (file)
index 0000000..bf3faa5
--- /dev/null
@@ -0,0 +1,100 @@
+GFenDirectoryMonitor
+GFenDirectoryMonitorClass
+GFenFileMonitor
+GFenFileMonitorClass
+GLocalFileIOStream
+GLocalFileIOStreamClass
+GLocalFileIOStreamPrivate
+GSocketInputStream
+GSocketInputStreamClass
+GSocketInputStreamPrivate
+GSocketOutputStream
+GSocketOutputStreamClass
+GSocketOutputStreamPrivate
+GWin32DirectoryMonitor
+GWin32DirectoryMonitorClass
+GWin32DirectoryMonitorPrivate
+GWin32Mount
+GWin32MountClass
+GWin32Volume
+GWin32VolumeMonitor
+GWin32VolumeMonitorClass
+GWinHttpDllFuncs
+GWinHttpFile
+GWinHttpFileClass
+GWinHttpFileInputStream
+GWinHttpFileInputStreamClass
+GWinHttpFileOutputStream
+GWinHttpFileOutputStreamClass
+GWinHttpVfs
+GWinHttpVfsClass
+G_FEN_DIRECTORY_MONITOR
+G_FEN_DIRECTORY_MONITOR_CLASS
+G_FEN_FILE_MONITOR
+G_FEN_FILE_MONITOR_CLASS
+G_FILE_ATTRIBUTE_STANDARD_ALLOCATED_SIZE
+G_IS_FEN_DIRECTORY_MONITOR
+G_IS_FEN_DIRECTORY_MONITOR_CLASS
+G_IS_FEN_FILE_MONITOR
+G_IS_FEN_FILE_MONITOR_CLASS
+G_IS_LOCAL_FILE_IO_STREAM
+G_IS_LOCAL_FILE_IO_STREAM_CLASS
+G_IS_SOCKET_INPUT_STREAM
+G_IS_SOCKET_INPUT_STREAM_CLASS
+G_IS_SOCKET_OUTPUT_STREAM
+G_IS_SOCKET_OUTPUT_STREAM_CLASS
+G_IS_WIN32_DIRECTORY_MONITOR
+G_IS_WIN32_DIRECTORY_MONITOR_CLASS
+G_IS_WIN32_MOUNT
+G_IS_WIN32_MOUNT_CLASS
+G_IS_WIN32_VOLUME_MONITOR
+G_IS_WIN32_VOLUME_MONITOR_CLASS
+G_IS_WINHTTP_FILE
+G_IS_WINHTTP_FILE_CLASS
+G_IS_WINHTTP_FILE_INPUT_STREAM
+G_IS_WINHTTP_FILE_INPUT_STREAM_CLASS
+G_IS_WINHTTP_FILE_OUTPUT_STREAM
+G_IS_WINHTTP_FILE_OUTPUT_STREAM_CLASS
+G_IS_WINHTTP_VFS
+G_IS_WINHTTP_VFS_CLASS
+G_LOCAL_FILE_IO_STREAM
+G_LOCAL_FILE_IO_STREAM_CLASS
+G_LOCAL_FILE_IO_STREAM_GET_CLASS
+G_SOCKET_INPUT_STREAM
+G_SOCKET_INPUT_STREAM_CLASS
+G_SOCKET_INPUT_STREAM_GET_CLASS
+G_SOCKET_OUTPUT_STREAM
+G_SOCKET_OUTPUT_STREAM_CLASS
+G_SOCKET_OUTPUT_STREAM_GET_CLASS
+G_TYPE_FEN_DIRECTORY_MONITOR
+G_TYPE_FEN_FILE_MONITOR
+G_TYPE_LOCAL_FILE_IO_STREAM
+G_TYPE_SOCKET_OUTPUT_STREAM
+G_TYPE_WIN32_DIRECTORY_MONITOR
+G_TYPE_WIN32_MOUNT
+G_TYPE_WIN32_VOLUME_MONITOR
+G_TYPE_WINHTTP_FILE
+G_TYPE_WINHTTP_FILE_INPUT_STREAM
+G_TYPE_WINHTTP_FILE_OUTPUT_STREAM
+G_TYPE_WINHTTP_VFS
+G_WIN32_DIRECTORY_MONITOR
+G_WIN32_DIRECTORY_MONITOR_CLASS
+G_WIN32_DIRECTORY_MONITOR_GET_CLASS
+G_WIN32_MOUNT
+G_WIN32_MOUNT_CLASS
+G_WIN32_VOLUME_MONITOR
+G_WIN32_VOLUME_MONITOR_CLASS
+G_WINHTTP_FILE
+G_WINHTTP_FILE_CLASS
+G_WINHTTP_FILE_GET_CLASS
+G_WINHTTP_FILE_INPUT_STREAM
+G_WINHTTP_FILE_INPUT_STREAM_CLASS
+G_WINHTTP_FILE_INPUT_STREAM_GET_CLASS
+G_WINHTTP_FILE_OUTPUT_STREAM
+G_WINHTTP_FILE_OUTPUT_STREAM_CLASS
+G_WINHTTP_FILE_OUTPUT_STREAM_GET_CLASS
+G_WINHTTP_VFS
+G_WINHTTP_VFS_CLASS
+G_WINHTTP_VFS_GET_CLASS
+g_win32_directory_monitor_get_type
+g_win32_directory_monitor_register
diff --git a/docs/reference/gio/aa b/docs/reference/gio/aa
new file mode 100644 (file)
index 0000000..13ab1c0
--- /dev/null
@@ -0,0 +1,74 @@
+               
+<book lang=
+<!ENTITY version SYSTEM 
+xml/extensionpoints.xml
+xml/gappinfo.xml
+xml/gasyncinitable.xml
+xml/gasyncresult.xml
+xml/gbufferedinputstream.xml
+xml/gbufferedoutputstream.xml
+xml/gcancellable.xml
+xml/gcontenttype.xml
+xml/gdatainputstream.xml
+xml/gdataoutputstream.xml
+xml/gdesktopappinfo.xml
+xml/gdrive.xml
+xml/gemblemedicon.xml
+xml/gemblem.xml
+xml/gfileattribute.xml
+xml/gfileenumerator.xml
+xml/gfileicon.xml
+xml/gfileinfo.xml
+xml/gfileinputstream.xml
+xml/gfileiostream.xml
+xml/gfilemonitor.xml
+xml/gfilenamecompleter.xml
+xml/gfileoutputstream.xml
+xml/gfile.xml
+xml/gfilterinputstream.xml
+xml/gfilteroutputstream.xml
+xml/gicon.xml
+xml/ginetaddress.xml
+xml/ginetsocketaddress.xml
+xml/ginitable.xml
+xml/ginputstream.xml
+xml/gioerror.xml
+xml/giomodule.xml
+xml/gioscheduler.xml
+xml/giostream.xml
+xml/gloadableicon.xml
+xml/gmemoryinputstream.xml
+xml/gmemoryoutputstream.xml
+xml/gmountoperation.xml
+xml/gmount.xml
+xml/gnetworkaddress.xml
+xml/gnetworkservice.xml
+xml/goutputstream.xml
+xml/gresolver.xml
+xml/gseekable.xml
+xml/gsimpleasyncresult.xml
+xml/gsocketaddress.xml
+xml/gsocketclient.xml
+xml/gsocketconnectable.xml
+xml/gsocketconnection.xml
+xml/gsocketcontrolmessage.xml
+xml/gsocketlistener.xml
+xml/gsocketservice.xml
+xml/gsocket.xml
+xml/gsrvtarget.xml
+xml/gtcpconnection.xml
+xml/gthemedicon.xml
+xml/gthreadedsocketservice.xml
+xml/gunixconnection.xml
+xml/gunixfdmessage.xml
+xml/gunixinputstream.xml
+xml/gunixmounts.xml
+xml/gunixoutputstream.xml
+xml/gunixsocketaddress.xml
+xml/gvfs.xml
+xml/gvolumemonitor.xml
+xml/gvolume.xml
+xml/migrating.xml
+xml/overview.xml
+xml/tree_index.sgml
+<?xml version=
diff --git a/docs/reference/gio/b b/docs/reference/gio/b
new file mode 100644 (file)
index 0000000..4bf6ec2
--- /dev/null
@@ -0,0 +1,77 @@
+xml/api-index-2.18.xml
+xml/api-index-2.18..xml
+xml/api-index-2,20.xml
+xml/api-index-2.20.xml
+xml/api-index-2.22.xml
+xml/api-index-2.22..xml
+xml/api-index-deprecated.xml
+xml/api-index-full.xml
+xml/extensionpoints.xml
+xml/gappinfo.xml
+xml/gasyncinitable.xml
+xml/gasyncresult.xml
+xml/gbufferedinputstream.xml
+xml/gbufferedoutputstream.xml
+xml/gcancellable.xml
+xml/gcontenttype.xml
+xml/gdatainputstream.xml
+xml/gdataoutputstream.xml
+xml/gdesktopappinfo.xml
+xml/gdrive.xml
+xml/gemblemedicon.xml
+xml/gemblem.xml
+xml/gfileattribute.xml
+xml/gfileenumerator.xml
+xml/gfileicon.xml
+xml/gfileinfo.xml
+xml/gfileinputstream.xml
+xml/gfileiostream.xml
+xml/gfilemonitor.xml
+xml/gfilenamecompleter.xml
+xml/gfileoutputstream.xml
+xml/gfile.xml
+xml/gfilterinputstream.xml
+xml/gfilteroutputstream.xml
+xml/gicon.xml
+xml/ginetaddress.xml
+xml/ginetsocketaddress.xml
+xml/ginitable.xml
+xml/ginputstream.xml
+xml/gioerror.xml
+xml/giomodule.xml
+xml/gioscheduler.xml
+xml/giostream.xml
+xml/gloadableicon.xml
+xml/gmemoryinputstream.xml
+xml/gmemoryoutputstream.xml
+xml/gmountoperation.xml
+xml/gmount.xml
+xml/gnetworkaddress.xml
+xml/gnetworkservice.xml
+xml/goutputstream.xml
+xml/gresolver.xml
+xml/gseekable.xml
+xml/gsimpleasyncresult.xml
+xml/gsocketaddress.xml
+xml/gsocketclient.xml
+xml/gsocketconnectable.xml
+xml/gsocketconnection.xml
+xml/gsocketcontrolmessage.xml
+xml/gsocketlistener.xml
+xml/gsocketservice.xml
+xml/gsocket.xml
+xml/gsrvtarget.xml
+xml/gtcpconnection.xml
+xml/gthemedicon.xml
+xml/gthreadedsocketservice.xml
+xml/gunixconnection.xml
+xml/gunixfdmessage.xml
+xml/gunixinputstream.xml
+xml/gunixmounts.xml
+xml/gunixoutputstream.xml
+xml/gunixsocketaddress.xml
+xml/gvfs.xml
+xml/gvolumemonitor.xml
+xml/gvolume.xml
+xml/migrating.xml
+xml/overview.xml
diff --git a/docs/reference/gio/bb b/docs/reference/gio/bb
new file mode 100644 (file)
index 0000000..4bf6ec2
--- /dev/null
@@ -0,0 +1,77 @@
+xml/api-index-2.18.xml
+xml/api-index-2.18..xml
+xml/api-index-2,20.xml
+xml/api-index-2.20.xml
+xml/api-index-2.22.xml
+xml/api-index-2.22..xml
+xml/api-index-deprecated.xml
+xml/api-index-full.xml
+xml/extensionpoints.xml
+xml/gappinfo.xml
+xml/gasyncinitable.xml
+xml/gasyncresult.xml
+xml/gbufferedinputstream.xml
+xml/gbufferedoutputstream.xml
+xml/gcancellable.xml
+xml/gcontenttype.xml
+xml/gdatainputstream.xml
+xml/gdataoutputstream.xml
+xml/gdesktopappinfo.xml
+xml/gdrive.xml
+xml/gemblemedicon.xml
+xml/gemblem.xml
+xml/gfileattribute.xml
+xml/gfileenumerator.xml
+xml/gfileicon.xml
+xml/gfileinfo.xml
+xml/gfileinputstream.xml
+xml/gfileiostream.xml
+xml/gfilemonitor.xml
+xml/gfilenamecompleter.xml
+xml/gfileoutputstream.xml
+xml/gfile.xml
+xml/gfilterinputstream.xml
+xml/gfilteroutputstream.xml
+xml/gicon.xml
+xml/ginetaddress.xml
+xml/ginetsocketaddress.xml
+xml/ginitable.xml
+xml/ginputstream.xml
+xml/gioerror.xml
+xml/giomodule.xml
+xml/gioscheduler.xml
+xml/giostream.xml
+xml/gloadableicon.xml
+xml/gmemoryinputstream.xml
+xml/gmemoryoutputstream.xml
+xml/gmountoperation.xml
+xml/gmount.xml
+xml/gnetworkaddress.xml
+xml/gnetworkservice.xml
+xml/goutputstream.xml
+xml/gresolver.xml
+xml/gseekable.xml
+xml/gsimpleasyncresult.xml
+xml/gsocketaddress.xml
+xml/gsocketclient.xml
+xml/gsocketconnectable.xml
+xml/gsocketconnection.xml
+xml/gsocketcontrolmessage.xml
+xml/gsocketlistener.xml
+xml/gsocketservice.xml
+xml/gsocket.xml
+xml/gsrvtarget.xml
+xml/gtcpconnection.xml
+xml/gthemedicon.xml
+xml/gthreadedsocketservice.xml
+xml/gunixconnection.xml
+xml/gunixfdmessage.xml
+xml/gunixinputstream.xml
+xml/gunixmounts.xml
+xml/gunixoutputstream.xml
+xml/gunixsocketaddress.xml
+xml/gvfs.xml
+xml/gvolumemonitor.xml
+xml/gvolume.xml
+xml/migrating.xml
+xml/overview.xml
index e2fce8fbf758a2606db3f29426266ec5a19f1650..d882c01a7330a1030c5a99c6a98f8a5abfe8e572 100644 (file)
@@ -1631,6 +1631,7 @@ g_network_service_get_type
 GSocket
 GSocketSourceFunc
 GSocketType
+GSocketProtocol
 GSocketMsgFlags
 GInputVector
 GOutputVector
@@ -1663,11 +1664,9 @@ g_socket_set_keepalive
 g_socket_get_family
 g_socket_get_fd
 g_socket_get_local_address
-g_socket_get_protocol_id
-g_socket_get_protocol_name
+g_socket_get_protocol
 g_socket_get_remote_address
 g_socket_get_socket_type
-g_socket_protocol_id_lookup_by_name
 <SUBSECTION Standard>
 GSocketClass
 G_IS_SOCKET
index 7db9b5c25eb39ec899ca53649907a862d398758e..70ba7500030534aff5722c4cfc1cbac98b757fcb 100644 (file)
@@ -1078,9 +1078,7 @@ g_socket_get_fd
 g_socket_get_keepalive
 g_socket_get_listen_backlog
 g_socket_get_local_address
-g_socket_get_protocol_id
-g_socket_get_protocol_name
-g_socket_protocol_id_lookup_by_name
+g_socket_get_protocol
 g_socket_get_remote_address
 g_socket_get_socket_type
 g_socket_is_closed
index 2f5ad760a6c32a728b3ace36179e8bf318047217..6b6ef40272f3c7712a6f46f58692a59496d49c6c 100644 (file)
@@ -556,6 +556,30 @@ typedef enum
   G_SOCKET_MSG_DONTROUTE = GLIB_SYSDEF_MSG_DONTROUTE
 } GSocketMsgFlags;
 
+/**
+ * GSocketProtocol:
+ * @G_SOCKET_PROTOCOL_UNKNOWN: The protocol type is unknown
+ * @G_SOCKET_PROTOCOL_DEFAULT: The default protocol for the family/type
+ * @G_SOCKET_PROTOCOL_TCP: Tcp over IP
+ * @G_SOCKET_PROTOCOL_UDP: UDP over IP
+ * @G_SOCKET_PROTOCOL_SCTP: SCTP over IP
+ *
+ * A protocol identifier is specified when creating a #GSocket, which is a family/type
+ * specific identifier, where 0 means the default protocol for the particular family/type.
+ * This enum contains a set of commonly availible and used protocols. You can also
+ * pass any other identifiers handled by the platform in order to use protocols not
+ * listed here.
+ *
+ * Since: 2.22
+ */
+typedef enum {
+  G_SOCKET_PROTOCOL_UNKNOWN = -1,
+  G_SOCKET_PROTOCOL_DEFAULT = 0,
+  G_SOCKET_PROTOCOL_TCP     = 6,
+  G_SOCKET_PROTOCOL_UDP     = 17,
+  G_SOCKET_PROTOCOL_SCTP    = 132
+} GSocketProtocol;
+
 G_END_DECLS
 
 #endif /* __GIO_ENUMS_H__ */
index e5e6fe8107f7b95c219be0250ba5c7ac85a1c551..4d33394bab64b0ba5ce1701dd933531d7e56f6e4 100644 (file)
@@ -132,7 +132,7 @@ struct _GSocketPrivate
 {
   GSocketFamily   family;
   GSocketType     type;
-  gint            protocol;
+  GSocketProtocol protocol;
   gint            fd;
   gint            listen_backlog;
   GError         *construct_error;
@@ -400,88 +400,10 @@ g_socket_details_from_fd (GSocket *socket)
               socket_strerror (errsv));
 }
 
-static char *
-get_protocol_name (int protocol_id)
-{
-  struct protoent *protoent;
-#ifdef HAVE_GETPROTOBYNUMBER_R
-  char buffer[1024];
-  struct protoent my_protoent;
-#endif
-
-  if (protocol_id == 0)
-    return NULL;
-
-  if (protocol_id == -1)
-    return g_strdup ("unknown");
-
-#ifdef HAVE_GETPROTOBYNUMBER_R
-  protoent = NULL;
-  getprotobynumber_r (protocol_id,
-                     &my_protoent, buffer, sizeof (buffer),
-                     &protoent);
-#else
-  protoent = getprotobynumber (protocol_id);
-#endif
-
-  if (protoent == NULL)
-    return g_strdup_printf ("proto-%d", protocol_id);
-
-  return g_strdup (protoent->p_name);
-}
-
-/**
- * g_socket_protocol_id_lookup_by_name:
- * @protocol_name: The name of a protocol, or %NULL
- *
- * Tries to look up the protocol id for a given
- * protocol name. If the protocol name is not known
- * on this system it returns -1.
- *
- * If @protocol_name is %NULL (default protocol) then
- * 0 is returned.
- *
- * Returns: a protocol id, or -1 if unknown
- *
- * Since: 2.22
- **/
-gint
-g_socket_protocol_id_lookup_by_name (const char *protocol_name)
-{
-  struct protoent *protoent;
-  int protocol = 0;
-#ifdef HAVE_GETPROTOBYNAME_R
-  char buffer[1024];
-  struct protoent my_protoent;
-#endif
-
-  if (!protocol_name)
-    return 0;
-
-#ifdef HAVE_GETPROTOBYNAME_R
-  protoent = NULL;
-  getprotobyname_r (protocol_name,
-                   &my_protoent, buffer, sizeof (buffer),
-                   &protoent);
-#else
-  protoent = getprotobyname (protocol_name);
-#endif
-
-  if (protoent == NULL)
-    {
-      if (g_str_has_prefix (protocol_name, "proto-"))
-       return atoi (protocol_name + strlen ("proto-"));
-      return -1;
-    }
-  protocol = protoent->p_proto;
-
-  return protocol;
-}
-
 static gint
 g_socket_create_socket (GSocketFamily   family,
                        GSocketType     type,
-                       int             protocol_id,
+                       int             protocol,
                        GError        **error)
 {
   gint native_type;
@@ -505,7 +427,7 @@ g_socket_create_socket (GSocketFamily   family,
       g_assert_not_reached ();
     }
 
-  if (protocol_id == -1)
+  if (protocol == -1)
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
                   _("Unable to create socket: %s"), _("Unknown protocol was specified"));
@@ -515,7 +437,7 @@ g_socket_create_socket (GSocketFamily   family,
 #ifdef SOCK_CLOEXEC
   native_type |= SOCK_CLOEXEC;
 #endif
-  fd = socket (family, native_type, protocol_id);
+  fd = socket (family, native_type, protocol);
 
   if (fd < 0)
     {
@@ -589,7 +511,7 @@ g_socket_get_property (GObject    *object,
        break;
 
       case PROP_PROTOCOL:
-       g_value_set_int (value, socket->priv->protocol);
+       g_value_set_enum (value, socket->priv->protocol);
        break;
 
       case PROP_FD:
@@ -642,7 +564,7 @@ g_socket_set_property (GObject      *object,
        break;
 
       case PROP_PROTOCOL:
-       socket->priv->protocol = g_value_get_int (value);
+       socket->priv->protocol = g_value_get_enum (value);
        break;
 
       case PROP_FD:
@@ -718,12 +640,11 @@ g_socket_class_init (GSocketClass *klass)
                                                      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_property (gobject_class, PROP_PROTOCOL,
-                                  g_param_spec_int ("protocol",
+                                  g_param_spec_enum ("protocol",
                                                     P_("Socket protocol"),
                                                     P_("The id of the protocol to use, or -1 for unknown"),
-                                                    G_MININT,
-                                                    G_MAXINT,
-                                                    -1,
+                                                     G_TYPE_SOCKET_PROTOCOL,
+                                                     G_SOCKET_PROTOCOL_UNKNOWN,
                                                     G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_property (gobject_class, PROP_FD,
@@ -828,20 +749,22 @@ g_socket_initable_init (GInitable *initable,
  * g_socket_new:
  * @family: the socket family to use, e.g. %G_SOCKET_FAMILY_IPV4.
  * @type: the socket type to use.
- * @protocol_id: the id of the protocol to use, or 0 for default.
+ * @protocol: the id of the protocol to use, or 0 for default.
  * @error: #GError for error reporting, or %NULL to ignore.
  *
  * Creates a new #GSocket with the defined family, type and protocol.
- * If @protocol_id is 0 the default protocol type for the family and
- * type is used.
+ * If @protocol is 0 (%G_SOCKET_PROTOCOL_DEFAULT) the default protocol type
+ * for the family and type is used.
+ *
+ * The @protocol is a family and type specific int that specifies what
+ * kind of protocol to use. #GSocketProtocol lists several common ones.
+ * Many families only support one protocol, and use 0 for this, others
+ * support several and using 0 means to use the default protocol for
+ * the family and type.
  *
- * The @protocol_id is a family and type specific int that specifies what
- * kind of protocol to use. Many families only support one protocol,
- * and use 0 for this, others support several and using 0 means
- * to use the default protocol for the family and type. To use
- * other protocol, you can use g_socket_protocol_id_lookup_by_name()
- * to look up the protocol by name, or if you known the system specific
- * protocol id you can use that.
+ * The protocol id is passed directly to the operating
+ * system, so you can use protocols not listed in #GSocketProtocol if you
+ * know the protocol number used for it.
  *
  * Returns: a #GSocket or %NULL on error.
  *     Free the returned object with g_object_unref().
@@ -851,14 +774,14 @@ g_socket_initable_init (GInitable *initable,
 GSocket *
 g_socket_new (GSocketFamily family,
              GSocketType type,
-             int protocol_id,
+             GSocketProtocol protocol,
              GError **error)
 {
   return G_SOCKET (g_initable_new (G_TYPE_SOCKET,
                                   NULL, error,
                                   "family", family,
                                   "type", type,
-                                  "protocol", protocol_id,
+                                  "protocol", protocol,
                                   NULL));
 }
 
@@ -1089,7 +1012,7 @@ g_socket_get_socket_type (GSocket *socket)
 }
 
 /**
- * g_socket_get_protocol_id:
+ * g_socket_get_protocol:
  * @socket: a #GSocket.
  *
  * Gets the socket protocol id the socket was created with.
@@ -1099,33 +1022,14 @@ g_socket_get_socket_type (GSocket *socket)
  *
  * Since: 2.22
  **/
-gint
-g_socket_get_protocol_id (GSocket *socket)
+GSocketProtocol
+g_socket_get_protocol (GSocket *socket)
 {
   g_return_val_if_fail (G_IS_SOCKET (socket), -1);
 
   return socket->priv->protocol;
 }
 
-/**
- * g_socket_get_protocol_name:
- * @socket: a #GSocket.
- *
- * Gets the socket protocol type name the socket was created with.
- * This can be %NULL if the socket was created with a NULL protocol.
- *
- * Returns: a string or %NULL, free with g_free
- *
- * Since: 2.22
- **/
-char *
-g_socket_get_protocol_name (GSocket *socket)
-{
-  g_return_val_if_fail (G_IS_SOCKET (socket), NULL);
-
-  return get_protocol_name (socket->priv->protocol);
-}
-
 /**
  * g_socket_get_fd:
  * @socket: a #GSocket.
index 7d5d0d48ec28a6db4e0bf1e133fc6521be30c633..2ca90d287130fe128ba03a5a4ed1a1ad171b9651 100644 (file)
@@ -76,15 +76,14 @@ struct _GSocket
 GType                  g_socket_get_type                (void) G_GNUC_CONST;
 GSocket *              g_socket_new                     (GSocketFamily            family,
                                                         GSocketType              type,
-                                                        gint                     protocol_id,
+                                                        GSocketProtocol          protocol,
                                                         GError                 **error);
 GSocket *              g_socket_new_from_fd             (gint                     fd,
                                                         GError                 **error);
 int                    g_socket_get_fd                  (GSocket                 *socket);
 GSocketFamily          g_socket_get_family              (GSocket                 *socket);
 GSocketType            g_socket_get_socket_type         (GSocket                 *socket);
-gint                   g_socket_get_protocol_id         (GSocket                 *socket);
-char *                 g_socket_get_protocol_name       (GSocket                 *socket);
+GSocketProtocol        g_socket_get_protocol            (GSocket                 *socket);
 GSocketAddress *       g_socket_get_local_address       (GSocket                 *socket,
                                                         GError                 **error);
 GSocketAddress *       g_socket_get_remote_address      (GSocket                 *socket,
@@ -163,8 +162,6 @@ GSource *              g_socket_create_source           (GSocket
                                                         GIOCondition             condition,
                                                         GCancellable            *cancellable);
 
-gint                  g_socket_protocol_id_lookup_by_name (const char            *protocol_name);
-
 G_END_DECLS
 
 #endif /* __G_SOCKET_H__ */
index 922479347717dca8901a7582e31c9f11cf9c2c0a..944b73cb24b78bd921b19ec9e10c3bd1b7d118aa 100644 (file)
@@ -77,7 +77,7 @@ struct _GSocketClientPrivate
 {
   GSocketFamily family;
   GSocketType type;
-  char *protocol;
+  GSocketProtocol protocol;
   GSocketAddress *local_address;
 };
 
@@ -88,7 +88,6 @@ create_socket (GSocketClient  *client,
 {
   GSocketFamily family;
   GSocket *socket;
-  int proto;
 
   family = client->priv->family;
   if (family == G_SOCKET_FAMILY_INVALID &&
@@ -97,10 +96,9 @@ create_socket (GSocketClient  *client,
   if (family == G_SOCKET_FAMILY_INVALID)
     family = g_socket_address_get_family (dest_address);
 
-  proto = g_socket_protocol_id_lookup_by_name (client->priv->protocol);
   socket = g_socket_new (family,
                         client->priv->type,
-                        proto,
+                        client->priv->protocol,
                         error);
   if (socket == NULL)
     return NULL;
@@ -153,8 +151,6 @@ g_socket_client_finalize (GObject *object)
   if (client->priv->local_address)
     g_object_unref (client->priv->local_address);
 
-  g_free (client->priv->protocol);
-
   if (G_OBJECT_CLASS (g_socket_client_parent_class)->finalize)
     (*G_OBJECT_CLASS (g_socket_client_parent_class)->finalize) (object);
 }
@@ -178,7 +174,7 @@ g_socket_client_get_property (GObject    *object,
        break;
 
       case PROP_PROTOCOL:
-       g_value_set_string (value, client->priv->protocol);
+       g_value_set_enum (value, client->priv->protocol);
        break;
 
       case PROP_LOCAL_ADDRESS:
@@ -209,7 +205,7 @@ g_socket_client_set_property (GObject      *object,
       break;
 
     case PROP_PROTOCOL:
-      g_socket_client_set_protocol (client, g_value_get_string (value));
+      g_socket_client_set_protocol (client, g_value_get_enum (value));
       break;
 
     case PROP_LOCAL_ADDRESS:
@@ -317,11 +313,11 @@ g_socket_client_set_socket_type (GSocketClient *client,
  *
  * See g_socket_client_set_protocol() for details.
  *
- * Returns: a string or %NULL. don't free
+ * Returns: a #GSocketProtocol
  *
  * Since: 2.22
  **/
-const char *
+GSocketProtocol
 g_socket_client_get_protocol (GSocketClient *client)
 {
   return client->priv->protocol;
@@ -330,26 +326,25 @@ g_socket_client_get_protocol (GSocketClient *client)
 /**
  * g_socket_client_set_protocol:
  * @client: a #GSocketClient.
- * @protocol: a string, or %NULL
+ * @protocol: a #GSocketProtocol
  *
  * Sets the protocol of the socket client.
  * The sockets created by this object will use of the specified
  * protocol.
  *
- * If @protocol is %NULL that means to use the default
+ * If @protocol is %0 that means to use the default
  * protocol for the socket family and type.
  *
  * Since: 2.22
  **/
 void
-g_socket_client_set_protocol (GSocketClient        *client,
-                             const char           *protocol)
+g_socket_client_set_protocol (GSocketClient *client,
+                             GSocketProtocol protocol)
 {
-  if (g_strcmp0 (client->priv->protocol, protocol) == 0)
+  if (client->priv->protocol == protocol)
     return;
 
-  g_free (client->priv->protocol);
-  client->priv->protocol = g_strdup (protocol);
+  client->priv->protocol = protocol;
   g_object_notify (G_OBJECT (client), "protocol");
 }
 
@@ -429,11 +424,12 @@ g_socket_client_class_init (GSocketClientClass *class)
                                                      G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_property (gobject_class, PROP_PROTOCOL,
-                                  g_param_spec_string ("protocol",
-                                                       P_("Socket protocol"),
-                                                       P_("The protocol to use for socket construction, or %NULL for default"),
-                                                       NULL,
-                                                       G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+                                  g_param_spec_enum ("protocol",
+                                                     P_("Socket protocol"),
+                                                     P_("The protocol to use for socket construction, or 0 for default"),
+                                                     G_TYPE_SOCKET_PROTOCOL,
+                                                     G_SOCKET_PROTOCOL_DEFAULT,
+                                                     G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_property (gobject_class, PROP_LOCAL_ADDRESS,
                                   g_param_spec_object ("local-address",
index b70246fa0ef9aad8eb75d955b40169f3c4813f39..b04f57be5054a70f5a79f28d0ed8353d024c3c9b 100644 (file)
@@ -76,9 +76,9 @@ void                    g_socket_client_set_family                      (GSocket
 GSocketType             g_socket_client_get_socket_type                 (GSocketClient        *client);
 void                    g_socket_client_set_socket_type                 (GSocketClient        *client,
                                                                         GSocketType           type);
-const char             *g_socket_client_get_protocol                    (GSocketClient        *client);
+GSocketProtocol         g_socket_client_get_protocol                    (GSocketClient        *client);
 void                    g_socket_client_set_protocol                    (GSocketClient        *client,
-                                                                        const char           *protocol);
+                                                                        GSocketProtocol       protocol);
 GSocketAddress         *g_socket_client_get_local_address               (GSocketClient        *client);
 void                    g_socket_client_set_local_address               (GSocketClient        *client,
                                                                         GSocketAddress       *address);
index c14e3c1f3992874e1959e84c31fe5b3d348f6705..3033c3a8e9ea93b48f3c00699765d3d6a40cd5b9 100644 (file)
@@ -483,7 +483,7 @@ g_socket_connection_factory_create_connection (GSocket *socket)
 
   type = g_socket_connection_factory_lookup_type (g_socket_get_family (socket),
                                                  g_socket_get_socket_type (socket),
-                                                 g_socket_get_protocol_id (socket));
+                                                 g_socket_get_protocol (socket));
   return g_object_new (type, "socket", socket, NULL);
 }
 
index 6fa5d709ad38eebe5f233d861569b949e1b307c7..1d75a51a3544cca34d2b28b9277764c136033c59 100644 (file)
@@ -246,9 +246,9 @@ g_socket_listener_add_socket (GSocketListener *listener,
 /**
  * g_socket_listener_add_address:
  * @listener: a #GSocketListener
- * @address: a #GSocketAddres
+ * @address: a #GSocketAddress
  * @type: a #GSocketType
- * @protocol: a protocol name, or %NULL
+ * @protocol: a #GSocketProtocol
  * @source_object: Optional #GObject identifying this source
  * @error: #GError for error reporting, or %NULL to ignore.
  *
@@ -269,7 +269,7 @@ gboolean
 g_socket_listener_add_address (GSocketListener *listener,
                               GSocketAddress *address,
                               GSocketType type,
-                              const char *protocol,
+                              GSocketProtocol protocol,
                               GObject *source_object,
                               GError **error)
 {
@@ -280,8 +280,7 @@ g_socket_listener_add_address (GSocketListener *listener,
     return FALSE;
 
   family = g_socket_address_get_family (address);
-  socket = g_socket_new (family, type,
-                        g_socket_protocol_id_lookup_by_name (protocol), error);
+  socket = g_socket_new (family, type, protocol, error);
   if (socket == NULL)
     return FALSE;
 
@@ -347,7 +346,7 @@ g_socket_listener_add_inet_port (GSocketListener *listener,
   if (!g_socket_listener_add_address (listener,
                                      address6,
                                      G_SOCKET_TYPE_STREAM,
-                                     NULL,
+                                     G_SOCKET_PROTOCOL_DEFAULT,
                                      source_object,
                                      NULL))
     {
@@ -356,7 +355,7 @@ g_socket_listener_add_inet_port (GSocketListener *listener,
       res = g_socket_listener_add_address (listener,
                                           address4,
                                           G_SOCKET_TYPE_STREAM,
-                                          NULL,
+                                          G_SOCKET_PROTOCOL_DEFAULT,
                                           source_object,
                                           error);
     }
@@ -368,7 +367,7 @@ g_socket_listener_add_inet_port (GSocketListener *listener,
       g_socket_listener_add_address (listener,
                                     address4,
                                     G_SOCKET_TYPE_STREAM,
-                                    NULL,
+                                    G_SOCKET_PROTOCOL_DEFAULT,
                                     source_object,
                                     NULL);
     }
index 9a13209a2b19f1c71f3b818c3bbb940812c66bc2..da51a760d05c115c23e122805e383bd0364a7124 100644 (file)
@@ -90,7 +90,7 @@ gboolean                g_socket_listener_add_socket                    (GSocket
 gboolean                g_socket_listener_add_address                   (GSocketListener      *listener,
                                                                          GSocketAddress      *address,
                                                                         GSocketType          type,
-                                                                        const char          *protocol,
+                                                                        GSocketProtocol      protocol,
                                                                         GObject             *source_object,
                                                                         GError             **error);
 gboolean                g_socket_listener_add_inet_port                 (GSocketListener      *listener,
index 6c4e320bfd4004d30864889176e4bd663a6c1a8e..62a90b3ad8040b88872d86c25bf56ce674cf9fe0 100644 (file)
@@ -41,19 +41,19 @@ G_DEFINE_TYPE_WITH_CODE (GTcpConnection, g_tcp_connection,
   g_socket_connection_factory_register_type (g_define_type_id,
                                             G_SOCKET_FAMILY_IPV4,
                                             G_SOCKET_TYPE_STREAM,
-                                            0);
+                                            G_SOCKET_PROTOCOL_DEFAULT);
   g_socket_connection_factory_register_type (g_define_type_id,
                                             G_SOCKET_FAMILY_IPV6,
                                             G_SOCKET_TYPE_STREAM,
-                                            0);
+                                            G_SOCKET_PROTOCOL_DEFAULT);
   g_socket_connection_factory_register_type (g_define_type_id,
                                             G_SOCKET_FAMILY_IPV4,
                                             G_SOCKET_TYPE_STREAM,
-                                            g_socket_protocol_id_lookup_by_name ("tcp"));
+                                            G_SOCKET_PROTOCOL_TCP);
   g_socket_connection_factory_register_type (g_define_type_id,
                                             G_SOCKET_FAMILY_IPV6,
                                             G_SOCKET_TYPE_STREAM,
-                                            g_socket_protocol_id_lookup_by_name ("tcp"));
+                                            G_SOCKET_PROTOCOL_TCP);
                         );
 
 static gboolean g_tcp_connection_close       (GIOStream            *stream,
index 1877f3772b9de338e3b9ce60a3c99e7acd351818..47d17239684088d9f3360f88cfcb8e1bec72e40a 100644 (file)
@@ -43,7 +43,7 @@ G_DEFINE_TYPE_WITH_CODE (GUnixConnection, g_unix_connection,
   g_socket_connection_factory_register_type (g_define_type_id,
                                             G_SOCKET_FAMILY_UNIX,
                                             G_SOCKET_TYPE_STREAM,
-                                            0);
+                                            G_SOCKET_PROTOCOL_DEFAULT);
                         );
 
 /**