Beginnings of GSocket API, small fixes for InetAddress
[cascardo/gnio.git] / gnio / gsocket.c
1 /* GNIO - GLib Network Layer of GIO
2  *
3  * Copyright (C) 2008 Christian Kellner, Samuel Cormier-Iijima
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Authors: Christian Kellner <gicmo@gnome.org>
21  *          Samuel Cormier-Iijima <sciyoshi@gmail.com>
22  */
23
24 #include <config.h>
25 #include <glib.h>
26 #include <gio/gio.h>
27
28 #include <string.h>
29 #ifndef G_OS_WIN32
30 # include <netinet/in.h>
31 # include <arpa/inet.h>
32 # include <netdb.h>
33 #else
34 # include <winsock2.h>
35 # include <winerror.h>
36 # include <ws2tcpip.h>
37 # undef HAVE_GETADDRINFO
38 # define HAVE_GETHOSTBYNAME_THREADSAFE 1
39 #endif
40 #include <errno.h>
41
42 #include "ginetaddress.h"
43 #include "ginet4address.h"
44 #include "ginet6address.h"
45 #include "gsocket.h"
46 #include "gnioerror.h"
47 #include "ginetsocketaddress.h"
48
49 G_DEFINE_TYPE (GSocket, g_socket, G_TYPE_OBJECT);
50
51 struct _GSocketPrivate
52 {
53   int fd;
54 };
55
56 static void
57 g_socket_class_init (GSocketClass *klass)
58 {
59   GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
60
61   g_type_class_add_private (klass, sizeof (GSocketPrivate));
62 }
63
64 static void
65 g_socket_init (GSocket *address)
66 {
67   address->priv = G_TYPE_INSTANCE_GET_PRIVATE (address, G_TYPE_SOCKET, GSocketPrivate);
68 }
69
70 GSocket *
71 g_socket_new ()
72 {
73   return G_SOCKET (g_object_new (G_TYPE_SOCKET, NULL));
74 }
75
76 void
77 g_socket_listen (GSocket *socket, gint backlog)
78 {
79   g_return_if_fail (G_IS_SOCKET (socket));
80
81   listen (socket->priv->fd, backlog);
82 }