[gnio] Make socket code build on win32
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnio] Make socket code build on win32
- Date: Thu, 30 Apr 2009 04:19:12 -0400 (EDT)
commit 8224624ae70b471115e91433658962d8e0076bf9
Author: Alexander Larsson <alexl redhat com>
Date: Wed Apr 29 13:35:52 2009 +0200
Make socket code build on win32
Make socket code build on win32. socket control messages
are not supported, but the scatter/gather aspect of send/revieve_message
work.
---
configure.ac | 3 +-
gio/gsocket.c | 600 +++++++++++++++++++++++++++----------------
gio/gsocketcontrolmessage.c | 19 ++-
gio/gtcpclient.c | 10 +-
4 files changed, 407 insertions(+), 225 deletions(-)
diff --git a/configure.ac b/configure.ac
index 9e084f6..63fd191 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,8 @@ AC_CHECK_FUNC(g_socket_connectable_enumerate,,
AC_MSG_ERROR([gnio requires a new glib (git://git.gnome.org/glib)]))
LIBS="$gnio_saved_libs"
-AC_CHECK_FUNCS(getprotobyname_r)
+AC_CHECK_FUNCS(getprotobyname_r endservent)
+AC_CHECK_HEADERS([netdb.h winsock2.h mswsock.h])
AC_ARG_ENABLE(vala,
AS_HELP_STRING([--enable-vala],
diff --git a/gio/gsocket.c b/gio/gsocket.c
index 4aa2d6f..72fd9d9 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -36,6 +36,7 @@
# include <sys/types.h>
#else
# include <winsock2.h>
+# include <mswsock.h>
#endif
#include <gio/gcancellable.h>
@@ -112,23 +113,32 @@ check_socket (GSocket *socket,
static void
g_socket_details_from_fd (GSocket *socket)
{
-#ifndef G_OS_WIN32
struct sockaddr_storage address;
gint fd;
guint addrlen;
guint optlen;
- int value, result;
+ int value;
int errsv;
+#ifndef G_OS_WIN32
+ BOOL bool_val;
+#else
+ int bool_val;
+#endif
fd = socket->priv->fd;
optlen = sizeof value;
- if (getsockopt (fd, SOL_SOCKET, SO_TYPE, &value, &optlen) != 0)
+ if (getsockopt (fd, SOL_SOCKET, SO_TYPE, (void *)&value, &optlen) != 0)
{
errsv = get_socket_errno ();
switch (errsv)
{
+#ifdef ENOTSOCK
case ENOTSOCK:
+#endif
+#ifdef WSAENOTSOCK
+ case WSAENOTSOCK:
+#endif
case EBADF:
/* programmer error */
g_error ("creating GSocket from fd %d: %s\n",
@@ -193,20 +203,28 @@ g_socket_details_from_fd (GSocket *socket)
g_socket_address_new_from_native (&address, addrlen);
}
- result = fcntl (fd, F_GETFL, NULL);
- if (result == -1)
- {
- errsv = get_socket_errno ();
- goto err;
- }
- socket->priv->blocking = !(result & O_NONBLOCK);
+#ifndef G_OS_WIN32
+ {
+ int result;
+ result = fcntl (fd, F_GETFL, NULL);
+ if (result == -1)
+ {
+ errsv = get_socket_errno ();
+ goto err;
+ }
+ socket->priv->blocking = !(result & O_NONBLOCK);
+ }
+#else
+ /* There doesn't seem to be a way to get this on win32... */
+ socket->priv->blocking = FALSE;
+#endif
- optlen = sizeof value;
+ optlen = sizeof bool_val;
if (getsockopt (fd, SOL_SOCKET, SO_KEEPALIVE,
- &value, &optlen) == 0)
+ (void *)&bool_val, &optlen) == 0)
{
- g_assert (optlen == sizeof value);
- socket->priv->keepalive = !!value;
+ g_assert (optlen == sizeof bool_val);
+ socket->priv->keepalive = !!bool_val;
}
else
{
@@ -214,12 +232,12 @@ g_socket_details_from_fd (GSocket *socket)
socket->priv->keepalive = FALSE;
}
- optlen = sizeof value;
+ optlen = sizeof bool_val;
if (getsockopt (fd, SOL_SOCKET, SO_REUSEADDR,
- &value, &optlen) == 0)
+ (void *)&bool_val, &optlen) == 0)
{
- g_assert (optlen == sizeof value);
- socket->priv->reuse_address = !!value;
+ g_assert (optlen == sizeof bool_val);
+ socket->priv->reuse_address = !!bool_val;
}
else
{
@@ -227,14 +245,6 @@ g_socket_details_from_fd (GSocket *socket)
socket->priv->reuse_address = FALSE;
}
-#else /* windows */
- socket->type = G_SOCKET_TYPE_INVALID;
- socket->family = G_SOCKET_DOMAIN_INVALID;
- socket->blocking = FALSE;
- socket->keepalive = FALSE;
- socket->reuse_address = FALSE;
-#endif
-
return;
err:
@@ -1139,117 +1149,191 @@ g_socket_send_message (GSocket *socket,
gint flags,
GError **error)
{
- struct msghdr msg;
- gssize result;
+ GOutputVector one_vector;
char zero;
- struct iovec one_iovec;
if (!check_socket (socket, error))
return -1;
- /* name */
- if (address)
+ if (num_vectors == -1)
+ {
+ for (num_vectors = 0;
+ vectors[num_vectors].buffer != NULL;
+ num_vectors++)
+ ;
+ }
+
+ if (num_messages == -1)
{
- msg.msg_namelen = g_socket_address_get_native_size (address);
- msg.msg_name = g_alloca (msg.msg_namelen);
- g_socket_address_to_native (address, msg.msg_name, msg.msg_namelen);
+ for (num_messages = 0;
+ messages != NULL && messages[num_messages] != NULL;
+ num_messages++)
+ ;
+ }
+
+ if (num_vectors == 0)
+ {
+ zero = '\0';
+
+ one_vector.buffer = &zero;
+ one_vector.size = 1;
+ num_vectors = 1;
+ vectors = &one_vector;
}
- /* iov */
+#ifndef G_OS_WIN32
{
- if (num_vectors == -1)
+ struct msghdr msg;
+ gssize result;
+
+ /* name */
+ if (address)
{
- for (num_vectors = 0; vectors[num_vectors].buffer != NULL; num_vectors++)
- ;
+ msg.msg_namelen = g_socket_address_get_native_size (address);
+ msg.msg_name = g_alloca (msg.msg_namelen);
+ g_socket_address_to_native (address, msg.msg_name, msg.msg_namelen);
}
- if (num_vectors == 0)
- {
- zero = '\0';
+ /* iov */
+ {
+ /* this entire expression will be evaluated at compile time */
+ if (sizeof *msg.msg_iov == sizeof *vectors &&
+ sizeof msg.msg_iov->iov_base == sizeof vectors->buffer &&
+ G_STRUCT_OFFSET (struct iovec, iov_base) ==
+ G_STRUCT_OFFSET (GOutputVector, buffer) &&
+ sizeof msg.msg_iov->iov_len == sizeof vectors->size &&
+ G_STRUCT_OFFSET (struct iovec, iov_len) ==
+ G_STRUCT_OFFSET (GOutputVector, size))
+ /* ABI is compatible */
+ {
+ msg.msg_iov = (struct iovec *) vectors;
+ msg.msg_iovlen = num_vectors;
+ }
+ else
+ /* ABI is incompatible */
+ {
+ gint i;
+
+ msg.msg_iov = g_newa (struct iovec, num_vectors);
+ for (i = 0; i < num_vectors; i++)
+ {
+ msg.msg_iov[i].iov_base = (void *) vectors[i].buffer;
+ msg.msg_iov[i].iov_len = vectors[i].size;
+ }
+ msg.msg_iovlen = num_vectors;
+ }
+ }
- msg.msg_iov = &one_iovec;
- msg.msg_iov->iov_base = &zero;
- msg.msg_iov->iov_len = 1;
- msg.msg_iovlen = 1;
- }
+ /* control */
+ {
+ struct cmsghdr *cmsg;
+ gint i;
- /* this entire expression will be evaluated at compile time */
- else if (sizeof *msg.msg_iov == sizeof *vectors &&
- sizeof msg.msg_iov->iov_base == sizeof vectors->buffer &&
- G_STRUCT_OFFSET (struct iovec, iov_base) ==
- G_STRUCT_OFFSET (GOutputVector, buffer) &&
- sizeof msg.msg_iov->iov_len == sizeof vectors->size &&
- G_STRUCT_OFFSET (struct iovec, iov_len) ==
- G_STRUCT_OFFSET (GOutputVector, size))
- /* ABI is compatible */
- {
- msg.msg_iov = (struct iovec *) vectors;
- msg.msg_iovlen = num_vectors;
- }
+ msg.msg_controllen = 0;
+ for (i = 0; i < num_messages; i++)
+ msg.msg_controllen += g_socket_control_message_space (messages[i]);
- else
- /* ABI is incompatible */
+ msg.msg_control = g_alloca (msg.msg_controllen);
+
+ cmsg = CMSG_FIRSTHDR (&msg);
+ for (i = 0; i < num_messages; i++)
+ {
+ g_assert (cmsg != NULL);
+ g_socket_control_message_serialise (messages[i], cmsg);
+ cmsg = CMSG_NXTHDR (&msg, cmsg);
+ }
+ g_assert (cmsg == NULL);
+ }
+
+ while (1)
{
- gint i;
-
- msg.msg_iov = g_newa (struct iovec, num_vectors);
- for (i = 0; i < num_vectors; i++)
- {
- msg.msg_iov[i].iov_base = (void *) vectors[i].buffer;
- msg.msg_iov[i].iov_len = vectors[i].size;
- }
- msg.msg_iovlen = num_vectors;
+ result = sendmsg (socket->priv->fd, &msg, flags);
+ if (result < 0)
+ {
+ int errsv = get_socket_errno ();
+
+ if (errsv == EINTR)
+ continue;
+
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errsv),
+ "sendmsg: %s", g_strerror (errsv));
+
+ return -1;
+ }
+ break;
}
- }
- /* control */
+ return result;
+ }
+#else
{
- struct cmsghdr *cmsg;
+ struct sockaddr_storage addr;
+ guint addrlen;
+ DWORD bytes_sent;
+ int result;
+ WSABUF *bufs;
gint i;
- if (num_messages == -1)
+ /* Win32 doesn't support control messages.
+ Actually this is possible for raw and datagram sockets
+ via WSASendMessage on Vista or later, but that doesn't
+ seem very useful */
+ if (num_messages != 0)
{
- for (num_messages = 0; messages[num_messages] != NULL; num_messages++)
- ;
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ "GSocketControlMessage not supported on windows");
+ return -1;
}
- msg.msg_controllen = 0;
- for (i = 0; i < num_messages; i++)
- msg.msg_controllen += g_socket_control_message_space (messages[i]);
-
- msg.msg_control = g_alloca (msg.msg_controllen);
-
- cmsg = CMSG_FIRSTHDR (&msg);
- for (i = 0; i < num_messages; i++)
+ /* iov */
+ bufs = g_newa (WSABUF, num_vectors);
+ for (i = 0; i < num_vectors; i++)
{
- g_assert (cmsg != NULL);
- g_socket_control_message_serialise (messages[i], cmsg);
- cmsg = CMSG_NXTHDR (&msg, cmsg);
+ bufs[i].buf = (char *)vectors[i].buffer;
+ bufs[i].len = (gulong)vectors[i].size;
}
- g_assert (cmsg == NULL);
- }
-
- while (1)
- {
- result = sendmsg (socket->priv->fd, &msg, flags);
-
- if (result < 0)
- {
- int errsv = get_socket_errno ();
- if (errsv == EINTR)
- continue;
-
- g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errsv),
- "sendmsg: %s", g_strerror (errsv));
+ /* name */
+ if (address)
+ {
+ addrlen = g_socket_address_get_native_size (address);
+ g_socket_address_to_native (address, &addr, sizeof addr);
+ }
- return -1;
- }
- break;
- }
+ while (1)
+ {
+ if (address)
+ result = WSASendTo (socket->priv->fd,
+ bufs, num_vectors,
+ &bytes_sent, flags,
+ (const struct sockaddr *)&addr, addrlen,
+ NULL, NULL);
+ else
+ result = WSASend (socket->priv->fd,
+ bufs, num_vectors,
+ &bytes_sent, flags,
+ NULL, NULL);
+
+ if (result != 0)
+ {
+ int errsv = get_socket_errno ();
+
+ if (errsv == WSAEINTR)
+ continue;
+
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errsv),
+ "WSASendTo: %s", g_strerror (errsv));
+
+ return -1;
+ }
+ break;
+ }
- return result;
+ return bytes_sent;
+ }
+#endif
}
/**
@@ -1311,173 +1395,245 @@ g_socket_receive_message (GSocket *socket,
gint *flags,
GError **error)
{
- struct msghdr msg;
- gssize result;
- struct sockaddr_storage one_sockaddr;
- struct iovec one_iovec;
+ GInputVector one_vector;
char one_byte;
if (!check_socket (socket, error))
return -1;
- /* name */
+ if (num_vectors == -1)
+ {
+ for (num_vectors = 0;
+ vectors[num_vectors].buffer != NULL;
+ num_vectors++)
+ ;
+ }
+
+ if (num_vectors == 0)
+ {
+ one_vector.buffer = &one_byte;
+ one_vector.size = 1;
+ num_vectors = 1;
+ vectors = &one_vector;
+ }
+
+#ifndef G_OS_WIN32
{
+ struct msghdr msg;
+ gssize result;
+ struct sockaddr_storage one_sockaddr;
+
+ /* name */
if (address)
{
- msg.msg_name = &one_sockaddr;
- msg.msg_namelen = sizeof (struct sockaddr_storage);
+ msg.msg_name = &one_sockaddr;
+ msg.msg_namelen = sizeof (struct sockaddr_storage);
}
else
{
- msg.msg_name = NULL;
- msg.msg_namelen = 0;
- }
- }
-
- /* iov */
- {
- if (num_vectors == 0)
- {
- msg.msg_iov = &one_iovec;
- msg.msg_iov->iov_base = &one_byte;
- msg.msg_iov->iov_len = 1;
- msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
}
+ /* iov */
/* this entire expression will be evaluated at compile time */
- else if (sizeof *msg.msg_iov == sizeof *vectors &&
- sizeof msg.msg_iov->iov_base == sizeof vectors->buffer &&
- G_STRUCT_OFFSET (struct iovec, iov_base) ==
- G_STRUCT_OFFSET (GInputVector, buffer) &&
- sizeof msg.msg_iov->iov_len == sizeof vectors->size &&
- G_STRUCT_OFFSET (struct iovec, iov_len) ==
- G_STRUCT_OFFSET (GInputVector, size))
+ if (sizeof *msg.msg_iov == sizeof *vectors &&
+ sizeof msg.msg_iov->iov_base == sizeof vectors->buffer &&
+ G_STRUCT_OFFSET (struct iovec, iov_base) ==
+ G_STRUCT_OFFSET (GInputVector, buffer) &&
+ sizeof msg.msg_iov->iov_len == sizeof vectors->size &&
+ G_STRUCT_OFFSET (struct iovec, iov_len) ==
+ G_STRUCT_OFFSET (GInputVector, size))
/* ABI is compatible */
{
- msg.msg_iov = (struct iovec *) vectors;
- msg.msg_iovlen = num_vectors;
+ msg.msg_iov = (struct iovec *) vectors;
+ msg.msg_iovlen = num_vectors;
}
-
else
/* ABI is incompatible */
{
- gint i;
-
- msg.msg_iov = g_newa (struct iovec, num_vectors);
- for (i = 0; i < num_vectors; i++)
- {
- msg.msg_iov[i].iov_base = vectors[i].buffer;
- msg.msg_iov[i].iov_len = vectors[i].size;
- }
- msg.msg_iovlen = num_vectors;
+ gint i;
+
+ msg.msg_iov = g_newa (struct iovec, num_vectors);
+ for (i = 0; i < num_vectors; i++)
+ {
+ msg.msg_iov[i].iov_base = vectors[i].buffer;
+ msg.msg_iov[i].iov_len = vectors[i].size;
+ }
+ msg.msg_iovlen = num_vectors;
}
- }
- /* control */
- {
+ /* control */
msg.msg_control = g_alloca (2048);
msg.msg_controllen = 2048;
- }
- /* flags */
- {
+ /* flags */
if (flags != NULL)
msg.msg_flags = *flags;
else
msg.msg_flags = 0;
- }
- /* do it */
- while (1)
- {
- result = recvmsg (socket->priv->fd, &msg, msg.msg_flags);
+ /* do it */
+ while (1)
+ {
+ result = recvmsg (socket->priv->fd, &msg, msg.msg_flags);
- if (result < 0)
- {
- int errsv = get_socket_errno ();
+ if (result < 0)
+ {
+ int errsv = get_socket_errno ();
- if (errsv == EINTR)
- continue;
+ if (errsv == EINTR)
+ continue;
- g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errsv),
- "recvmsg: %s", g_strerror (errsv));
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errsv),
+ "recvmsg: %s", g_strerror (errsv));
- return -1;
- }
- break;
- }
+ return -1;
+ }
+ break;
+ }
- /* decode address */
- {
+ /* decode address */
if (address != NULL)
{
- if (msg.msg_namelen > 0)
- *address = g_socket_address_new_from_native (msg.msg_name,
- msg.msg_namelen);
- else
- *address = NULL;
+ if (msg.msg_namelen > 0)
+ *address = g_socket_address_new_from_native (msg.msg_name,
+ msg.msg_namelen);
+ else
+ *address = NULL;
}
- }
- /* decode control messages */
- {
- GSocketControlMessage **my_messages;
- gint allocated = 0, index = 0;
- const gchar *scm_pointer;
- struct cmsghdr *cmsg;
- gsize scm_size;
+ /* decode control messages */
+ {
+ GSocketControlMessage **my_messages;
+ gint allocated = 0, index = 0;
+ const gchar *scm_pointer;
+ struct cmsghdr *cmsg;
+ gsize scm_size;
+ int decoded_messages;
- scm_pointer = (const gchar *) msg.msg_control;
- scm_size = msg.msg_controllen;
+ scm_pointer = (const gchar *) msg.msg_control;
+ scm_size = msg.msg_controllen;
- for (cmsg = CMSG_FIRSTHDR (&msg); cmsg; cmsg = CMSG_NXTHDR (&msg, cmsg))
- {
- GSocketControlMessage *message;
+ for (cmsg = CMSG_FIRSTHDR (&msg); cmsg; cmsg = CMSG_NXTHDR (&msg, cmsg))
+ {
+ GSocketControlMessage *message;
- message = g_socket_control_message_deserialise (cmsg);
+ message = g_socket_control_message_deserialise (cmsg);
+ if (message == NULL)
+ /* We've already spewed about the problem in the
+ deserialization code, so just continue */
+ continue;
- if G_UNLIKELY (message == NULL)
- g_error ("Incomplete control message received from kernel.");
+ if (index == allocated)
+ {
+ /* estimated 99% case: exactly 1 control message */
+ allocated = MIN (allocated * 2, 1);
+ my_messages = g_new (GSocketControlMessage *, (allocated + 1));
+ allocated = 1;
+ }
- if (index == allocated)
- {
- /* estimated 99% case: exactly 1 control message */
- allocated = MIN (allocated * 2, 1);
- my_messages = g_new (GSocketControlMessage *, (allocated + 1));
- allocated = 1;
- }
+ my_messages[index++] = message;
+ }
- my_messages[index++] = message;
- }
+ if (num_messages)
+ *num_messages = index;
- if (num_messages)
- *num_messages = index;
+ if (messages)
+ {
+ my_messages[index++] = NULL;
+ *messages = my_messages;
+ }
+ else
+ {
+ gint i;
+
+ /* free all those messages we just constructed.
+ * we have to do it this way if the user ignores the
+ * messages so that we will close any received fds.
+ */
+ for (i = 0; i < index; i++)
+ g_object_unref (my_messages[i]);
+ g_free (my_messages);
+ }
+ }
+
+ /* capture the flags */
+ if (flags != NULL)
+ *flags = msg.msg_flags;
- if (messages)
+ return result;
+ }
+#else
+ {
+ struct sockaddr_storage addr;
+ int addrlen;
+ DWORD bytes_recieved;
+ DWORD win_flags;
+ int result;
+ WSABUF *bufs;
+ gint i;
+
+ /* iov */
+ bufs = g_newa (WSABUF, num_vectors);
+ for (i = 0; i < num_vectors; i++)
{
- my_messages[index++] = NULL;
- *messages = my_messages;
+ bufs[i].buf = (char *)vectors[i].buffer;
+ bufs[i].len = (gulong)vectors[i].size;
}
+
+ /* flags */
+ if (flags != NULL)
+ win_flags = *flags;
else
+ win_flags = 0;
+
+ /* do it */
+ while (1)
{
- gint i;
-
- /* free all those messages we just constructed.
- * we have to do it this way if the user ignores the
- * messages so that we will close any received fds.
- */
- for (i = 0; i < index; i++)
- g_object_unref (my_messages[i]);
- g_free (my_messages);
+ addrlen = sizeof addr;
+ if (address)
+ result = WSARecvFrom (socket->priv->fd,
+ bufs, num_vectors,
+ &bytes_recieved, &win_flags,
+ (struct sockaddr *)&addr, &addrlen,
+ NULL, NULL);
+ else
+ result = WSARecv (socket->priv->fd,
+ bufs, num_vectors,
+ &bytes_recieved, &win_flags,
+ NULL, NULL);
+ if (result != 0)
+ {
+ int errsv = get_socket_errno ();
+
+ if (errsv == WSAEINTR)
+ continue;
+
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errsv),
+ "WSARecvFrom: %s", g_strerror (errsv));
+
+ return -1;
+ }
+ break;
}
- }
- /* capture the flags */
- {
+ /* decode address */
+ if (address != NULL)
+ {
+ if (addrlen > 0)
+ *address = g_socket_address_new_from_native (&addr, addrlen);
+ else
+ *address = NULL;
+ }
+
+ /* capture the flags */
if (flags != NULL)
- *flags = msg.msg_flags;
- }
+ *flags = win_flags;
- return result;
+ return bytes_recieved;
+ }
+#endif
}
diff --git a/gio/gsocketcontrolmessage.c b/gio/gsocketcontrolmessage.c
index f4af9a3..c5c4854 100644
--- a/gio/gsocketcontrolmessage.c
+++ b/gio/gsocketcontrolmessage.c
@@ -32,7 +32,12 @@
#include "gsocketcontrolmessage.h"
+#ifndef G_OS_WIN32
#include <sys/socket.h>
+#else
+# include <winsock2.h>
+# include <mswsock.h>
+#endif
G_DEFINE_ABSTRACT_TYPE (GSocketControlMessage,
g_socket_control_message,
@@ -47,7 +52,13 @@ g_socket_control_message_space (GSocketControlMessage *message)
size = G_SOCKET_CONTROL_MESSAGE_GET_CLASS (message)
-> size (message);
+#ifndef G_OS_WIN32
return CMSG_SPACE (size);
+#elif defined (WSA_CMSG_SPACE)
+ return WSA_CMSG_SPACE (size);
+#else
+ return size;
+#endif
}
static void
@@ -76,6 +87,7 @@ g_socket_control_message_serialise (GSocketControlMessage *message,
GSocketControlMessage *
g_socket_control_message_deserialise (gpointer scm_pointer)
{
+#ifndef G_OS_WIN32
struct cmsghdr *cmsg = scm_pointer;
gpointer data;
gssize size;
@@ -93,5 +105,10 @@ g_socket_control_message_deserialise (gpointer scm_pointer)
}
}
- g_error ("unknown message type."); /* XXX make better later */
+ g_warning ("unknown control message type %d:%d",
+ cmsg->cmsg_level, cmsg->cmsg_type);
+#else
+ g_warning ("socket control messages not supported on windows");
+#endif
+ return NULL;
}
diff --git a/gio/gtcpclient.c b/gio/gtcpclient.c
index 41ba5b7..5edd09d 100644
--- a/gio/gtcpclient.c
+++ b/gio/gtcpclient.c
@@ -26,7 +26,12 @@
#include "gtcpclient.h"
#include <string.h>
+#ifdef HAVE_NETDB_H
#include <netdb.h>
+#endif
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
#include <gio/gsimpleasyncresult.h>
#include <gio/gsocketconnectable.h>
@@ -260,15 +265,18 @@ g_tcp_client_get_connectable (const gchar *host,
g_set_error (error, 0, 0, /* XXX */
"Unknown service '%s' specified in hostname '%s'",
port, host);
+#ifdef HAVE_ENDSERVENT
endservent ();
+#endif
g_free (name);
return NULL;
}
- g_assert (0 < entry->s_port && entry->s_port < G_MAXUINT16);
portnum = g_ntohs (entry->s_port);
+#ifdef HAVE_ENDSERVENT
endservent ();
+#endif
}
#if 1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]