diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2009-10-28 16:11:40 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2010-02-22 14:12:50 +0000 |
commit | 4f7e76768e97dbe98ac5f5f0de3525a2ba897c41 (patch) | |
tree | e824265dd075e6543b7a2ad1bca04bf9a590eda5 /lib | |
parent | bdc2d946436da84ac114174ab1396c159306aea1 (diff) |
gibber_socket_set_error etc.: add wrappers for Winsock not returning errors in errno
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gibber/gibber-sockets.c | 54 | ||||
-rw-r--r-- | lib/gibber/gibber-sockets.h | 4 |
2 files changed, 58 insertions, 0 deletions
diff --git a/lib/gibber/gibber-sockets.c b/lib/gibber/gibber-sockets.c index e77f6f87c..af1ecc255 100644 --- a/lib/gibber/gibber-sockets.c +++ b/lib/gibber/gibber-sockets.c @@ -23,6 +23,9 @@ #include <errno.h> +#define DEBUG_FLAG DEBUG_NET +#include "gibber-debug.h" + gboolean gibber_connect_errno_requires_retry (void) { @@ -35,6 +38,57 @@ gibber_connect_errno_requires_retry (void) #endif } +static gint +gibber_socket_errno (void) +{ +#ifdef G_OS_WIN32 + return WSAGetLastError (); +#else + return errno; +#endif +} + +static const gchar * +gibber_socket_strerror (void) +{ +#ifdef G_OS_WIN32 + return "[no strerror() in winsock :-(]"; +#else + return g_strerror (errno); +#endif +} + +gboolean +gibber_socket_errno_is_eafnosupport (void) +{ +#ifdef G_OS_WIN32 + return (WSAGetLastError () == WSAEAFNOSUPPORT); +#else + return (errno == EAFNOSUPPORT); +#endif +} + +gboolean +gibber_socket_errno_is_eaddrinuse (void) +{ +#ifdef G_OS_WIN32 + return (WSAGetLastError () == WSAEADDRINUSE); +#else + return (errno == EADDRINUSE); +#endif +} + +void +gibber_socket_set_error (GError **error, const gchar *context, + GQuark domain, gint code) +{ + gint err = gibber_socket_errno (); + const gchar *str = gibber_socket_strerror (); + + DEBUG ("%s: #%d %s", context, err, str); + g_set_error (error, domain, code, "%s: #%d %s", context, err, str); +} + GIOChannel * gibber_io_channel_new_from_socket (gint sockfd) { diff --git a/lib/gibber/gibber-sockets.h b/lib/gibber/gibber-sockets.h index 96ba7358d..fcc1984e0 100644 --- a/lib/gibber/gibber-sockets.h +++ b/lib/gibber/gibber-sockets.h @@ -33,6 +33,10 @@ G_BEGIN_DECLS gboolean gibber_connect_errno_requires_retry (void); +gboolean gibber_socket_errno_is_eafnosupport (void); +gboolean gibber_socket_errno_is_eaddrinuse (void); +void gibber_socket_set_error (GError **error, const gchar *context, + GQuark domain, gint code); GIOChannel *gibber_io_channel_new_from_socket (gint sockfd); |