Beginnings of GSocket API, small fixes for InetAddress
authorSamuel CORMIER-IIJIMA <scormi3@lab2-15.cs.mcgill.ca>
Mon, 11 Feb 2008 16:12:56 +0000 (11:12 -0500)
committerSamuel CORMIER-IIJIMA <scormi3@lab2-15.cs.mcgill.ca>
Mon, 11 Feb 2008 16:12:56 +0000 (11:12 -0500)
gnio/Makefile.am
gnio/ginet4address.c
gnio/ginet6address.c
gnio/ginetsocketaddress.c
gnio/gnetworkinputstream.c [new file with mode: 0644]
gnio/gnetworkinputstream.h [new file with mode: 0644]
gnio/gnetworkoutputstream.c [new file with mode: 0644]
gnio/gnetworkoutputstream.h [new file with mode: 0644]
gnio/gresolver.h
gnio/gsocket.c
gnio/gsocket.h

index dfb4d13..17f5a64 100644 (file)
@@ -18,6 +18,8 @@ gnio_headers =        \
        gsocketaddress.h    \
        ginetsocketaddress.h \
        gsocket.h \
+       gnetworkinputstream.h \
+       gnetworkoutputstream.h \
        $(NULL)
 
 gioincludedir=$(includedir)/glib-2.0/gnio/
@@ -33,6 +35,8 @@ libgnio_la_SOURCES =        \
        gsocketaddress.c    \
        ginetsocketaddress.c \
        gsocket.c \
+       gnetworkinputstream.c \
+       gnetworkoutputstream.c \
         $(NULL)
 
 
index 12919b1..61f1226 100644 (file)
@@ -36,7 +36,8 @@
 
 G_DEFINE_TYPE (GInet4Address, g_inet4_address, G_TYPE_INET_ADDRESS);
 
-struct _GInet4AddressPrivate {
+struct _GInet4AddressPrivate
+{
   union {
     guint8  u4_addr8[4];
     guint32 u4_addr32;
index c8c1a39..6598572 100644 (file)
@@ -32,7 +32,8 @@
 
 G_DEFINE_TYPE (GInet6Address, g_inet6_address, G_TYPE_INET_ADDRESS);
 
-struct _GInet6AddressPrivate {
+struct _GInet6AddressPrivate
+{
   union {
     guint8  u6_addr8[16];
     guint16 u6_addr16[8];
index 1771240..6b2d7b1 100644 (file)
@@ -34,7 +34,8 @@ enum {
   PROP_PORT
 };
 
-struct _GInetSocketAddressPrivate {
+struct _GInetSocketAddressPrivate
+{
   GInetAddress *address;
   guint16       port;
 };
diff --git a/gnio/gnetworkinputstream.c b/gnio/gnetworkinputstream.c
new file mode 100644 (file)
index 0000000..50eb1a6
--- /dev/null
@@ -0,0 +1,60 @@
+/* GNIO - GLib Network Layer of GIO
+ *
+ * Copyright (C) 2008 Christian Kellner, Samuel Cormier-Iijima
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * 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.
+ *
+ * Authors: Christian Kellner <gicmo@gnome.org>
+ *          Samuel Cormier-Iijima <sciyoshi@gmail.com>
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <string.h>
+#ifndef G_OS_WIN32
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# include <netdb.h>
+#else
+# include <winsock2.h>
+# include <winerror.h>
+# include <ws2tcpip.h>
+# undef HAVE_GETADDRINFO
+# define HAVE_GETHOSTBYNAME_THREADSAFE 1
+#endif
+#include <errno.h>
+
+#include "ginetaddress.h"
+#include "ginet4address.h"
+#include "ginet6address.h"
+#include "gnetworkinputstream.h"
+#include "gnioerror.h"
+
+G_DEFINE_TYPE (GNetworkInputStream, g_network_input_stream, G_TYPE_INPUT_STREAM);
+
+static void
+g_network_input_stream_class_init (GNetworkInputStreamClass *klass)
+{
+  GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
+}
+
+static void
+g_network_input_stream_init (GNetworkInputStream *address)
+{
+
+}
diff --git a/gnio/gnetworkinputstream.h b/gnio/gnetworkinputstream.h
new file mode 100644 (file)
index 0000000..06df919
--- /dev/null
@@ -0,0 +1,61 @@
+/* GNIO - GLib Network Layer of GIO
+ *
+ * Copyright (C) 2008 Christian Kellner, Samuel Cormier-Iijima
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * 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.
+ *
+ * Authors: Christian Kellner <gicmo@gnome.org>
+ *          Samuel Cormier-Iijima <sciyoshi@gmail.com>
+ */
+
+#ifndef G_NETWORK_INPUT_STREAM_H
+#define G_NETWORK_INPUT_STREAM_H
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include "gsocket.h"
+
+G_BEGIN_DECLS
+
+#define G_TYPE_NETWORK_INPUT_STREAM         (g_socket_get_type ())
+#define G_NETWORK_INPUT_STREAM(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_NETWORK_INPUT_STREAM, GNetworkInputStream))
+#define G_NETWORK_INPUT_STREAM_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_NETWORK_INPUT_STREAM, GNetworkInputStreamClass))
+#define G_IS_NETWORK_INPUT_STREAM(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_NETWORK_INPUT_STREAM))
+#define G_IS_NETWORK_INPUT_STREAM_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_NETWORK_INPUT_STREAM))
+#define G_NETWORK_INPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_NETWORK_INPUT_STREAM, GNetworkInputStream))
+
+typedef struct _GNetworkInputStream        GNetworkInputStream;
+typedef struct _GNetworkInputStreamClass   GNetworkInputStreamClass;
+
+struct _GNetworkInputStream
+{
+  GInputStream parent;
+};
+
+struct _GNetworkInputStreamClass
+{
+  GInputStreamClass parent_class;
+};
+
+GType                 g_network_input_stream_get_type (void) G_GNUC_CONST;
+
+GNetworkInputStream * g_network_input_stream_new      (GSocket *socket);
+
+G_END_DECLS
+
+#endif /* G_NETWORK_INPUT_STREAM_H */
+
diff --git a/gnio/gnetworkoutputstream.c b/gnio/gnetworkoutputstream.c
new file mode 100644 (file)
index 0000000..eecd2db
--- /dev/null
@@ -0,0 +1,60 @@
+/* GNIO - GLib Network Layer of GIO
+ *
+ * Copyright (C) 2008 Christian Kellner, Samuel Cormier-Iijima
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * 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.
+ *
+ * Authors: Christian Kellner <gicmo@gnome.org>
+ *          Samuel Cormier-Iijima <sciyoshi@gmail.com>
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <string.h>
+#ifndef G_OS_WIN32
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# include <netdb.h>
+#else
+# include <winsock2.h>
+# include <winerror.h>
+# include <ws2tcpip.h>
+# undef HAVE_GETADDRINFO
+# define HAVE_GETHOSTBYNAME_THREADSAFE 1
+#endif
+#include <errno.h>
+
+#include "ginetaddress.h"
+#include "ginet4address.h"
+#include "ginet6address.h"
+#include "gnetworkoutputstream.h"
+#include "gnioerror.h"
+
+G_DEFINE_TYPE (GNetworkOutputStream, g_network_output_stream, G_TYPE_OUTPUT_STREAM);
+
+static void
+g_network_output_stream_class_init (GNetworkOutputStreamClass *klass)
+{
+  GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
+}
+
+static void
+g_network_output_stream_init (GNetworkOutputStream *address)
+{
+
+}
diff --git a/gnio/gnetworkoutputstream.h b/gnio/gnetworkoutputstream.h
new file mode 100644 (file)
index 0000000..b3dfee0
--- /dev/null
@@ -0,0 +1,61 @@
+/* GNIO - GLib Network Layer of GIO
+ *
+ * Copyright (C) 2008 Christian Kellner, Samuel Cormier-Iijima
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * 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.
+ *
+ * Authors: Christian Kellner <gicmo@gnome.org>
+ *          Samuel Cormier-Iijima <sciyoshi@gmail.com>
+ */
+
+#ifndef G_NETWORK_OUTPUT_STREAM_H
+#define G_NETWORK_OUTPUT_STREAM_H
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include "gsocket.h"
+
+G_BEGIN_DECLS
+
+#define G_TYPE_NETWORK_OUTPUT_STREAM         (g_socket_get_type ())
+#define G_NETWORK_OUTPUT_STREAM(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_NETWORK_OUTPUT_STREAM, GNetworkOutputStream))
+#define G_NETWORK_OUTPUT_STREAM_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_NETWORK_OUTPUT_STREAM, GNetworkOutputStreamClass))
+#define G_IS_NETWORK_OUTPUT_STREAM(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_NETWORK_OUTPUT_STREAM))
+#define G_IS_NETWORK_OUTPUT_STREAM_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_NETWORK_OUTPUT_STREAM))
+#define G_NETWORK_OUTPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_NETWORK_OUTPUT_STREAM, GNetworkOutputStream))
+
+typedef struct _GNetworkOutputStream        GNetworkOutputStream;
+typedef struct _GNetworkOutputStreamClass   GNetworkOutputStreamClass;
+
+struct _GNetworkOutputStream
+{
+  GOutputStream parent;
+};
+
+struct _GNetworkOutputStreamClass
+{
+  GOutputStreamClass parent_class;
+};
+
+GType                  g_network_output_stream_get_type (void) G_GNUC_CONST;
+
+GNetworkOutputStream * g_network_output_stream_new      (GSocket *socket);
+
+G_END_DECLS
+
+#endif /* G_NETWORK_OUTPUT_STREAM_H */
+
index cfc5892..e91ced8 100644 (file)
@@ -51,7 +51,7 @@ struct _GResolverClass
   GObjectClass parent_class;
 };
 
-GType          g_resolver_get_type (void) G_GNUC_CONST;
+GType          g_resolver_get_type                  (void) G_GNUC_CONST;
 
 GInetAddress * g_resolver_resolve                   (GResolver     *resolver,
                                                      const char    *host,
index c6d1ce9..c0a8a1a 100644 (file)
 #include "ginet6address.h"
 #include "gsocket.h"
 #include "gnioerror.h"
-#include "gsocket.h"
+#include "ginetsocketaddress.h"
 
 G_DEFINE_TYPE (GSocket, g_socket, G_TYPE_OBJECT);
 
+struct _GSocketPrivate
+{
+  int fd;
+};
+
 static void
 g_socket_class_init (GSocketClass *klass)
 {
   GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (GSocketPrivate));
 }
 
 static void
 g_socket_init (GSocket *address)
 {
+  address->priv = G_TYPE_INSTANCE_GET_PRIVATE (address, G_TYPE_SOCKET, GSocketPrivate);
+}
+
+GSocket *
+g_socket_new ()
+{
+  return G_SOCKET (g_object_new (G_TYPE_SOCKET, NULL));
+}
+
+void
+g_socket_listen (GSocket *socket, gint backlog)
+{
+  g_return_if_fail (G_IS_SOCKET (socket));
 
+  listen (socket->priv->fd, backlog);
 }
index b7af2ee..4143d3e 100644 (file)
@@ -39,12 +39,15 @@ G_BEGIN_DECLS
 #define G_IS_SOCKET_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_SOCKET))
 #define G_SOCKET_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_SOCKET, GSocket))
 
-typedef struct _GSocket        GSocket;
-typedef struct _GSocketClass   GSocketClass;
+typedef struct _GSocket          GSocket;
+typedef struct _GSocketClass     GSocketClass;
+typedef struct _GSocketPrivate   GSocketPrivate;
 
 struct _GSocket
 {
   GObject parent;
+
+  GSocketPrivate *priv;
 };
 
 struct _GSocketClass
@@ -52,12 +55,13 @@ struct _GSocketClass
   GObjectClass parent_class;
 };
 
-GType          g_socket_get_type (void) G_GNUC_CONST;
+GType          g_socket_get_type         (void) G_GNUC_CONST;
 
-GSocket *      g_socket_new ();
+GSocket *      g_socket_new              (void);
 
-void           g_socket_bind             (GSocket        *socket,
-                                          GSocketAddress *address);
+gboolean       g_socket_bind             (GSocket         *socket,
+                                          GSocketAddress  *address,
+                                          GError         **error);
 
 void           g_socket_connect          (GSocket        *socket,
                                           GSocketAddress *address,