summaryrefslogtreecommitdiff
path: root/src/net/SocketUtil.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2016-10-28 10:36:05 +0200
committerMax Kellermann <max@musicpd.org>2016-10-28 21:22:25 +0200
commitaead221184f52e68d161118a925a242f0858f736 (patch)
treea5a41c1db2c60a952d40652a55263bbff315fa1e /src/net/SocketUtil.cxx
parent16d1c9f5d6247a97ba835f5d100fca56806845e7 (diff)
event/ServerSocket: migrate from class Error to C++ exceptions
Diffstat (limited to 'src/net/SocketUtil.cxx')
-rw-r--r--src/net/SocketUtil.cxx24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/net/SocketUtil.cxx b/src/net/SocketUtil.cxx
index 0f89cac1f..a35bd8639 100644
--- a/src/net/SocketUtil.cxx
+++ b/src/net/SocketUtil.cxx
@@ -26,41 +26,35 @@
int
socket_bind_listen(int domain, int type, int protocol,
SocketAddress address,
- int backlog,
- Error &error)
+ int backlog)
{
int fd, ret;
const int reuse = 1;
fd = socket_cloexec_nonblock(domain, type, protocol);
- if (fd < 0) {
- SetSocketError(error);
- error.AddPrefix("Failed to create socket: ");
- return -1;
- }
+ if (fd < 0)
+ throw MakeSocketError("Failed to create socket");
ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
(const char *) &reuse, sizeof(reuse));
if (ret < 0) {
- SetSocketError(error);
- error.AddPrefix("setsockopt() failed: ");
+ auto error = GetSocketError();
close_socket(fd);
- return -1;
+ throw MakeSocketError(error, "setsockopt() failed");
}
ret = bind(fd, address.GetAddress(), address.GetSize());
if (ret < 0) {
- SetSocketError(error);
+ auto error = GetSocketError();
close_socket(fd);
- return -1;
+ throw MakeSocketError(error, "Failed to bind socket");
}
ret = listen(fd, backlog);
if (ret < 0) {
- SetSocketError(error);
- error.AddPrefix("listen() failed: ");
+ auto error = GetSocketError();
close_socket(fd);
- return -1;
+ throw MakeSocketError(error, "Failed to listen on socket");
}
#if defined(HAVE_STRUCT_UCRED) && defined(SO_PASSCRED)