[gnio] Use WSAGetLastError not errno on win32
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnio] Use WSAGetLastError not errno on win32
- Date: Tue, 28 Apr 2009 06:09:38 -0400 (EDT)
commit a2fe3816f3250048c8212c73526c9acd9c396751
Author: Alexander Larsson <alexl redhat com>
Date: Tue Apr 28 12:06:45 2009 +0200
Use WSAGetLastError not errno on win32
Socket errors are not reported via errno on win32, so introduce a
get_socket_errno() function that gets it from the right place
depending on the platform. All cross-platform references to errno
should go via this call.
---
gio/gsocket.c | 63 +++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/gio/gsocket.c b/gio/gsocket.c
index ca40bb6..33b9732 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -77,6 +77,16 @@ struct _GSocketPrivate
gboolean closed;
};
+static int
+get_socket_errno (void)
+{
+#ifndef G_OS_WIN32
+ return errno;
+#else
+ return WSAGetLastError ();
+#endif
+}
+
static gboolean
check_socket (GSocket *socket,
GError **error)
@@ -112,7 +122,7 @@ g_socket_details_from_fd (GSocket *socket)
optlen = sizeof value;
if (getsockopt (fd, SOL_SOCKET, SO_TYPE, &value, &optlen) != 0)
{
- errsv = errno;
+ errsv = get_socket_errno ();
switch (errsv)
{
@@ -151,7 +161,7 @@ g_socket_details_from_fd (GSocket *socket)
addrlen = sizeof address;
if (getsockname (fd, (struct sockaddr *) &address, &addrlen) != 0)
{
- errsv = errno;
+ errsv = get_socket_errno ();
goto err;
}
@@ -184,7 +194,7 @@ g_socket_details_from_fd (GSocket *socket)
result = fcntl (fd, F_GETFL, NULL);
if (result == -1)
{
- errsv = errno;
+ errsv = get_socket_errno ();
goto err;
}
socket->priv->blocking = !(result & O_NONBLOCK);
@@ -262,7 +272,7 @@ g_socket_create_socket (GSocketFamily family,
if (fd < 0)
{
- gint errsv = errno;
+ int errsv = get_socket_errno ();
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
"unable to create socket: %s", g_strerror (errsv));
@@ -562,7 +572,8 @@ g_socket_set_blocking (GSocket *socket,
if (ioctlsocket (socket->priv->fd, FIONBIO, &arg) == SOCKET_ERROR)
#endif
{
- g_warning ("Error setting socket status flags: %s", g_strerror (errno));
+ int errsv = get_socket_errno ();
+ g_warning ("Error setting socket status flags: %s", g_strerror (errsv));
return; /* Don't change blocking */
}
@@ -594,7 +605,8 @@ g_socket_set_reuse_address (GSocket *socket,
if (setsockopt (socket->priv->fd, SOL_SOCKET, SO_REUSEADDR,
(gpointer) &value, sizeof (value)) < 0)
{
- g_warning ("error setting reuse address: %s", g_strerror (errno));
+ int errsv = get_socket_errno ();
+ g_warning ("error setting reuse address: %s", g_strerror (errsv));
return;
}
@@ -626,7 +638,8 @@ g_socket_set_keepalive (GSocket *socket,
if (setsockopt (socket->priv->fd, SOL_SOCKET, SO_KEEPALIVE,
(gpointer) &value, sizeof (value)) < 0)
{
- g_warning ("error setting keepalive: %s", g_strerror (errno));
+ int errsv = get_socket_errno ();
+ g_warning ("error setting keepalive: %s", g_strerror (errsv));
return;
}
@@ -677,7 +690,9 @@ g_socket_get_local_address (GSocket *socket,
if (getsockname (socket->priv->fd, (struct sockaddr *) buffer, &len) < 0)
{
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "could not get local address: %s", g_strerror (errno));
+ int errsv = get_socket_errno ();
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
+ "could not get local address: %s", g_strerror (errsv));
return NULL;
}
@@ -699,7 +714,9 @@ g_socket_get_remote_address (GSocket *socket,
if (getpeername (socket->priv->fd, (struct sockaddr *) buffer, &len) < 0)
{
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "could not get remote address: %s", g_strerror (errno));
+ int errsv = get_socket_errno ();
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
+ "could not get remote address: %s", g_strerror (errsv));
return NULL;
}
@@ -741,7 +758,7 @@ g_socket_listen (GSocket *socket,
if (listen (socket->priv->fd, socket->priv->listen_backlog) < 0)
{
- int errsv = errno;
+ int errsv = get_socket_errno ();
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
"could not listen: %s", g_strerror (errsv));
@@ -767,11 +784,13 @@ g_socket_bind (GSocket *socket,
if (!g_socket_address_to_native (address, addr, sizeof addr))
return FALSE;
- if (bind (socket->priv->fd, (struct sockaddr *) addr, g_socket_address_get_native_size (address)) < 0)
+ if (bind (socket->priv->fd, (struct sockaddr *) addr,
+ g_socket_address_get_native_size (address)) < 0)
{
+ int errsv = get_socket_errno ();
g_set_error (error,
- G_IO_ERROR, g_io_error_from_errno (errno),
- "error binding to address: %s", g_strerror (errno));
+ G_IO_ERROR, g_io_error_from_errno (errsv),
+ "error binding to address: %s", g_strerror (errsv));
return FALSE;
}
@@ -796,7 +815,7 @@ g_socket_accept (GSocket *socket,
{
if ((ret = accept (socket->priv->fd, NULL, 0)) < 0)
{
- int errsv = errno;
+ int errsv = get_socket_errno ();
if (errsv == EINTR)
continue;
@@ -831,7 +850,7 @@ g_socket_connect (GSocket *socket,
if (connect (socket->priv->fd, (struct sockaddr *) buffer,
g_socket_address_get_native_size (address)) < 0)
{
- int errsv = errno;
+ int errsv = get_socket_errno ();
if (errsv == EINTR)
continue;
@@ -875,7 +894,7 @@ g_socket_receive (GSocket *socket,
{
if ((ret = recv (socket->priv->fd, buffer, size, 0)) < 0)
{
- int errsv = errno;
+ int errsv = get_socket_errno ();
if (errsv == EINTR)
continue;
@@ -908,7 +927,7 @@ g_socket_send (GSocket *socket,
{
if ((ret = send (socket->priv->fd, buffer, size, 0)) < 0)
{
- int errsv = errno;
+ int errsv = get_socket_errno ();
if (errsv == EINTR)
continue;
@@ -947,7 +966,7 @@ g_socket_close (GSocket *socket,
#endif
if (res == -1)
{
- int errsv = errno;
+ int errsv = get_socket_errno ();
if (errsv == EINTR)
continue;
@@ -1012,7 +1031,7 @@ g_socket_condition_check (GSocket *socket,
do
result = g_poll (&poll_fd, 1, 0);
- while (result == -1 && errno == EINTR);
+ while (result == -1 && get_socket_errno () == EINTR);
return poll_fd.revents;
}
@@ -1056,7 +1075,7 @@ g_socket_condition_wait (GSocket *socket,
do
result = g_poll (poll_fd, num, -1);
- while (result == -1 && errno == EINTR);
+ while (result == -1 && get_socket_errno () == EINTR);
return cancellable == NULL ||
!g_cancellable_set_error_if_cancelled (cancellable, error);
@@ -1168,7 +1187,7 @@ g_socket_send_message (GSocket *socket,
if (result < 0)
{
- gint errsv = errno;
+ int errsv = get_socket_errno ();
if (errsv == EINTR)
continue;
@@ -1327,7 +1346,7 @@ g_socket_receive_message (GSocket *socket,
if (result < 0)
{
- gint errsv = errno;
+ int errsv = get_socket_errno ();
if (errsv == EINTR)
continue;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]