Merge branch 'master' into errorstate
authorSamuel Cormier-Iijima <sciyoshi@gmail.com>
Fri, 29 Feb 2008 17:47:21 +0000 (12:47 -0500)
committerSamuel Cormier-Iijima <sciyoshi@gmail.com>
Fri, 29 Feb 2008 17:47:21 +0000 (12:47 -0500)
Conflicts:

gnio/gsocket.c

1  2 
gnio/gsocket.c

diff --cc gnio/gsocket.c
@@@ -78,98 -69,11 +78,102 @@@ struct _GSocketPrivat
    GSocketAddress *remote_address;
  };
  
 +static void
++<<<<<<< HEAD:gnio/gsocket.c
 +g_socket_constructed (GObject *object)
 +{
 +  GSocket *sock = G_SOCKET (object);
 +  GError *error = NULL;
 +  static GStaticMutex getprotobyname_mutex = G_STATIC_MUTEX_INIT;
 +  gint fd, native_domain, native_type, native_protocol;
 +
 +  if (sock->priv->fd >= 0)
 +    {
 +      // we've been constructed from an existing file descriptor
 +      glong arg;
 +      gboolean blocking;
 +
 +      // TODO: set the socket type with getsockopt (SO_TYPE)
 +      // TODO: what should we do about domain and protocol?
 +
 +      if ((arg = fcntl (sock->priv->fd, F_GETFL, NULL)) < 0)
 +        g_warning ("Error getting socket status flags: %s", g_strerror (errno));
 +
 +      blocking = ((arg & O_NONBLOCK) == 0);
 +
 +      return;
 +    }
 +
 +  switch (sock->priv->domain)
 +    {
 +      case G_SOCKET_DOMAIN_INET:
 +        native_domain = PF_INET;
 +        break;
 +
 +      case G_SOCKET_DOMAIN_INET6:
 +        native_domain = PF_INET6;
 +        break;
 +
 +      case G_SOCKET_DOMAIN_UNIX:
 +        native_domain = PF_UNIX;
 +        break;
 +
 +      default:
 +        g_set_error (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "unsupported socket domain");
 +        return;
 +    }
 +
 +  switch (sock->priv->type)
 +    {
 +      case G_SOCKET_TYPE_STREAM:
 +        native_type = SOCK_STREAM;
 +        break;
 +
 +      case G_SOCKET_TYPE_DATAGRAM:
 +        native_type = SOCK_DGRAM;
 +        break;
 +
 +      case G_SOCKET_TYPE_SEQPACKET:
 +        native_type = SOCK_SEQPACKET;
 +        break;
 +
 +      default:
 +        g_set_error (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "unsupported socket type");
 +        return;
 +    }
 +
 +  if (sock->priv->protocol == NULL)
 +    native_protocol = 0;
 +  else
 +    {
 +      struct protoent *ent;
 +      g_static_mutex_lock (&getprotobyname_mutex);
 +      if (!(ent = getprotobyname (sock->priv->protocol)))
 +        {
 +          g_static_mutex_unlock (&getprotobyname_mutex);
 +          g_set_error (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "unsupported socket protocol");
 +          return;
 +        }
 +      native_protocol = ent->p_proto;
 +      g_static_mutex_unlock (&getprotobyname_mutex);
 +    }
 +
 +  fd = socket (native_domain, native_type, native_protocol);
 +
 +  if (fd < 0)
 +    {
 +      g_set_error (&error, G_IO_ERROR, g_io_error_from_errno (errno), "unable to create socket: %s", g_strerror (errno));
 +      return;
 +    }
 +
 +  sock->priv->fd = fd;
 +}
 +
  static void
- g_socket_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+ g_socket_get_property (GObject    *object,
+                        guint       prop_id,
+                        GValue     *value,
+                        GParamSpec *pspec)
  {
    GSocket *socket = G_SOCKET (object);