From 1c031c7647fc229c3be8fc40a4153aa47d3aea6b Mon Sep 17 00:00:00 2001 From: Samuel Cormier-Iijima Date: Thu, 28 Feb 2008 17:11:43 -0500 Subject: [PATCH] Add TcpClient and TcpServer --- gnio/Makefile.am | 4 ++ gnio/gsocket.h | 5 +- gnio/gtcpclient.c | 124 +++++++++++++++++++++++++++++++++++++++++++ gnio/gtcpclient.h | 69 ++++++++++++++++++++++++ gnio/gtcpserver.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++ gnio/gtcpserver.h | 83 +++++++++++++++++++++++++++++ 6 files changed, 416 insertions(+), 1 deletion(-) create mode 100644 gnio/gtcpclient.c create mode 100644 gnio/gtcpclient.h create mode 100644 gnio/gtcpserver.c create mode 100644 gnio/gtcpserver.h diff --git a/gnio/Makefile.am b/gnio/Makefile.am index e911e78..62cc1bf 100644 --- a/gnio/Makefile.am +++ b/gnio/Makefile.am @@ -18,6 +18,8 @@ gnio_headers = \ gsocketaddress.h \ ginetsocketaddress.h \ gsocket.h \ + gtcpserver.h \ + gtcpclient.h \ gnetworkinputstream.h \ gnetworkoutputstream.h \ $(NULL) @@ -35,6 +37,8 @@ libgnio_la_SOURCES = \ gsocketaddress.c \ ginetsocketaddress.c \ gsocket.c \ + gtcpserver.c \ + gtcpclient.c \ gnetworkinputstream.c \ gnetworkoutputstream.c \ gasynchelper.c \ diff --git a/gnio/gsocket.h b/gnio/gsocket.h index 6ae1f81..5aa7040 100644 --- a/gnio/gsocket.h +++ b/gnio/gsocket.h @@ -71,7 +71,10 @@ typedef enum GType g_socket_get_type (void) G_GNUC_CONST; -GSocket * g_socket_new (GSocketDomain domain, GSocketType type, const gchar *protocol, GError **error); +GSocket * g_socket_new (GSocketDomain domain, + GSocketType type, + const gchar *protocol, + GError **error); GSocket * g_socket_new_from_fd (gint fd); diff --git a/gnio/gtcpclient.c b/gnio/gtcpclient.c new file mode 100644 index 0000000..599358e --- /dev/null +++ b/gnio/gtcpclient.c @@ -0,0 +1,124 @@ +/* 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 + * Samuel Cormier-Iijima + */ + +#include +#include +#include +#include + +#include +#include + +#include "ginetaddress.h" +#include "ginet4address.h" +#include "ginet6address.h" +#include "gsocket.h" +#include "gtcpclient.h" +#include "gnioerror.h" +#include "ginetsocketaddress.h" + +G_DEFINE_TYPE (GTcpClient, g_tcp_client, G_TYPE_OBJECT); + +enum +{ + PROP_0 +}; + +struct _GTcpClientPrivate +{ + +}; + +static void +g_tcp_client_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + GTcpClient *client = G_TCP_CLIENT (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +g_tcp_client_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + GTcpClient *client = G_TCP_CLIENT (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +g_tcp_client_finalize (GObject *object) +{ + GTcpClient *client = G_TCP_CLIENT (object); + + if (G_OBJECT_CLASS (g_tcp_client_parent_class)->finalize) + (*G_OBJECT_CLASS (g_tcp_client_parent_class)->finalize) (object); +} + +static void +g_tcp_client_dispose (GObject *object) +{ + GTcpClient *client = G_TCP_CLIENT (object); + + if (G_OBJECT_CLASS (g_tcp_client_parent_class)->dispose) + (*G_OBJECT_CLASS (g_tcp_client_parent_class)->dispose) (object); +} + +static void +g_tcp_client_class_init (GTcpClientClass *klass) +{ + GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (GTcpClientPrivate)); + + gobject_class->finalize = g_tcp_client_finalize; + gobject_class->dispose = g_tcp_client_dispose; + gobject_class->set_property = g_tcp_client_set_property; + gobject_class->get_property = g_tcp_client_get_property; +} + +static void +g_tcp_client_init (GTcpClient *client) +{ + client->priv = G_TYPE_INSTANCE_GET_PRIVATE (client, G_TYPE_TCP_CLIENT, GTcpClientPrivate); +} + +GTcpClient * +g_tcp_client_new (GInetSocketAddress *address, + GError **error) +{ + return NULL; +} + +void +g_tcp_client_close (GTcpClient *tcp_client) +{ + g_return_if_fail (G_IS_TCP_CLIENT (tcp_client)); +} diff --git a/gnio/gtcpclient.h b/gnio/gtcpclient.h new file mode 100644 index 0000000..f461221 --- /dev/null +++ b/gnio/gtcpclient.h @@ -0,0 +1,69 @@ +/* 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 + * Samuel Cormier-Iijima + */ + +#ifndef G_TCP_CLIENT_H +#define G_TCP_CLIENT_H + +#include +#include + +#include "ginetsocketaddress.h" +#include "gnetworkinputstream.h" +#include "gnetworkoutputstream.h" + +G_BEGIN_DECLS + +#define G_TYPE_TCP_CLIENT (g_tcp_client_get_type ()) +#define G_TCP_CLIENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_TCP_CLIENT, GTcpClient)) +#define G_TCP_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_TCP_CLIENT, GTcpClientClass)) +#define G_IS_TCP_CLIENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_TCP_CLIENT)) +#define G_IS_TCP_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_TCP_CLIENT)) +#define G_TCP_CLIENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_TCP_CLIENT, GTcpClient)) + +typedef struct _GTcpClient GTcpClient; +typedef struct _GTcpClientClass GTcpClientClass; +typedef struct _GTcpClientPrivate GTcpClientPrivate; + +struct _GTcpClient +{ + GObject parent; + + GTcpClientPrivate *priv; +}; + +struct _GTcpClientClass +{ + GObjectClass parent_class; +}; + +GType g_tcp_client_get_type (void) G_GNUC_CONST; + +GTcpClient * g_tcp_client_new (GInetSocketAddress *address, + GError **error); + +void g_tcp_client_close (GTcpClient *client); + +G_END_DECLS + +#endif /* G_TCP_CLIENT_H */ + diff --git a/gnio/gtcpserver.c b/gnio/gtcpserver.c new file mode 100644 index 0000000..6b7349b --- /dev/null +++ b/gnio/gtcpserver.c @@ -0,0 +1,132 @@ +/* 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 + * Samuel Cormier-Iijima + */ + +#include +#include +#include +#include + +#include +#include + +#include "ginetaddress.h" +#include "ginet4address.h" +#include "ginet6address.h" +#include "gsocket.h" +#include "gtcpserver.h" +#include "gnioerror.h" +#include "ginetsocketaddress.h" + +G_DEFINE_TYPE (GTcpServer, g_tcp_server, G_TYPE_OBJECT); + +enum +{ + PROP_0 +}; + +struct _GTcpServerPrivate +{ + +}; + +static void +g_tcp_server_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + GTcpServer *server = G_TCP_SERVER (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +g_tcp_server_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + GTcpServer *server = G_TCP_SERVER (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +g_tcp_server_finalize (GObject *object) +{ + GTcpServer *server = G_TCP_SERVER (object); + + if (G_OBJECT_CLASS (g_tcp_server_parent_class)->finalize) + (*G_OBJECT_CLASS (g_tcp_server_parent_class)->finalize) (object); +} + +static void +g_tcp_server_dispose (GObject *object) +{ + GTcpServer *server = G_TCP_SERVER (object); + + if (G_OBJECT_CLASS (g_tcp_server_parent_class)->dispose) + (*G_OBJECT_CLASS (g_tcp_server_parent_class)->dispose) (object); +} + +static void +g_tcp_server_class_init (GTcpServerClass *klass) +{ + GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (GTcpServerPrivate)); + + gobject_class->finalize = g_tcp_server_finalize; + gobject_class->dispose = g_tcp_server_dispose; + gobject_class->set_property = g_tcp_server_set_property; + gobject_class->get_property = g_tcp_server_get_property; +} + +static void +g_tcp_server_init (GTcpServer *server) +{ + server->priv = G_TYPE_INSTANCE_GET_PRIVATE (server, G_TYPE_TCP_SERVER, GTcpServerPrivate); +} + +GTcpServer * +g_tcp_server_new (GInetSocketAddress *address, + GError **error) +{ + return NULL; +} + +GTcpClient * +g_tcp_server_accept (GTcpServer *tcp_server, + GCancellable *cancellable, + GError **error) +{ + return NULL; +} + +void +g_tcp_server_close (GTcpServer *tcp_server) +{ + g_return_if_fail (G_IS_TCP_SERVER (tcp_server)); +} diff --git a/gnio/gtcpserver.h b/gnio/gtcpserver.h new file mode 100644 index 0000000..5cb8d63 --- /dev/null +++ b/gnio/gtcpserver.h @@ -0,0 +1,83 @@ +/* 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 + * Samuel Cormier-Iijima + */ + +#ifndef G_TCP_SERVER_H +#define G_TCP_SERVER_H + +#include +#include + +#include "ginetsocketaddress.h" +#include "gtcpclient.h" +#include "gnetworkinputstream.h" +#include "gnetworkoutputstream.h" + +G_BEGIN_DECLS + +#define G_TYPE_TCP_SERVER (g_tcp_server_get_type ()) +#define G_TCP_SERVER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_TCP_SERVER, GTcpServer)) +#define G_TCP_SERVER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_TCP_SERVER, GTcpServerClass)) +#define G_IS_TCP_SERVER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_TCP_SERVER)) +#define G_IS_TCP_SERVER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_TCP_SERVER)) +#define G_TCP_SERVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_TCP_SERVER, GTcpServer)) + +typedef struct _GTcpServer GTcpServer; +typedef struct _GTcpServerClass GTcpServerClass; +typedef struct _GTcpServerPrivate GTcpServerPrivate; + +struct _GTcpServer +{ + GObject parent; + + GTcpServerPrivate *priv; +}; + +struct _GTcpServerClass +{ + GObjectClass parent_class; +}; + +GType g_tcp_server_get_type (void) G_GNUC_CONST; + +GTcpServer * g_tcp_server_new (GInetSocketAddress *address, + GError **error); + +GTcpClient * g_tcp_server_accept (GTcpServer *server, + GCancellable *cancellable, + GError **error); + +void g_tcp_server_accept_async (GTcpServer *server, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +GTcpClient * g_tcp_server_accept_finish (GTcpServer *server, + GAsyncResult *result, + GError **error); + +void g_tcp_server_close (GTcpServer *server); + +G_END_DECLS + +#endif /* G_TCP_SERVER_H */ + -- 2.20.1