diff options
author | Max Kellermann <max@duempel.org> | 2013-01-15 22:27:24 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-15 22:42:15 +0100 |
commit | 8917264110fb684ef1fa87fdab14dd78902e8bba (patch) | |
tree | cb20bdc26252f98ce781e92a5e41f31763461ad6 /src/SocketUtil.cxx | |
parent | e90d606f0ad56146e8686acfdfd357005fa5b4a6 (diff) | |
download | mpd-8917264110fb684ef1fa87fdab14dd78902e8bba.tar.gz mpd-8917264110fb684ef1fa87fdab14dd78902e8bba.tar.xz mpd-8917264110fb684ef1fa87fdab14dd78902e8bba.zip |
ServerSocket, SocketUtil: use the SocketError library
Use WinSock errors on Windows.
Diffstat (limited to 'src/SocketUtil.cxx')
-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; } |