diff options
Diffstat (limited to '')
-rw-r--r-- | src/SocketUtil.cxx | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/SocketUtil.cxx b/src/SocketUtil.cxx index 6974c0df3..33ea4e2fe 100644 --- a/src/SocketUtil.cxx +++ b/src/SocketUtil.cxx @@ -19,11 +19,11 @@ #include "config.h" #include "SocketUtil.hxx" +#include "SocketError.hxx" #include "fd_util.h" #include <glib.h> -#include <errno.h> #include <unistd.h> #ifndef G_OS_WIN32 @@ -37,49 +37,42 @@ #include <string.h> #endif -static GQuark -listen_quark(void) -{ - return g_quark_from_static_string("listen"); -} - int socket_bind_listen(int domain, int type, int protocol, const struct sockaddr *address, size_t address_length, int backlog, - GError **error) + GError **error_r) { int fd, ret; const int reuse = 1; fd = socket_cloexec_nonblock(domain, type, protocol); if (fd < 0) { - g_set_error(error, listen_quark(), errno, - "Failed to create socket: %s", g_strerror(errno)); + SetSocketError(error_r); + g_prefix_error(error_r, "Failed to create socket"); return -1; } ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *) &reuse, sizeof(reuse)); if (ret < 0) { - g_set_error(error, listen_quark(), errno, - "setsockopt() failed: %s", g_strerror(errno)); + SetSocketError(error_r); + g_prefix_error(error_r, "setsockopt() failed"); close_socket(fd); return -1; } ret = bind(fd, address, address_length); if (ret < 0) { - g_set_error(error, listen_quark(), errno, - "%s", g_strerror(errno)); + SetSocketError(error_r); close_socket(fd); return -1; } ret = listen(fd, backlog); if (ret < 0) { - g_set_error(error, listen_quark(), errno, - "listen() failed: %s", g_strerror(errno)); + SetSocketError(error_r); + g_prefix_error(error_r, "listen() failed"); close_socket(fd); return -1; } |