aboutsummaryrefslogtreecommitdiffstats
path: root/src/listen.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-03-14 18:29:38 +0100
committerMax Kellermann <max@duempel.org>2009-03-14 18:29:38 +0100
commitc8c392050069f9a6b922ccd8ea8a4c71dda4a2c8 (patch)
tree37aedc11cd4fc5a7a77fe7e0cb93835a33e2520b /src/listen.c
parentdccb973cfef9664644e4945fbddedb3eee8c215b (diff)
downloadmpd-c8c392050069f9a6b922ccd8ea8a4c71dda4a2c8.tar.gz
mpd-c8c392050069f9a6b922ccd8ea8a4c71dda4a2c8.tar.xz
mpd-c8c392050069f9a6b922ccd8ea8a4c71dda4a2c8.zip
socket_util: added socket_bind_listen()
Moved code from listen_add_address() (listen.c) to socket_util.c.
Diffstat (limited to 'src/listen.c')
-rw-r--r--src/listen.c45
1 files changed, 4 insertions, 41 deletions
diff --git a/src/listen.c b/src/listen.c
index 4b0326264..e4d8ea796 100644
--- a/src/listen.c
+++ b/src/listen.c
@@ -18,6 +18,7 @@
*/
#include "listen.h"
+#include "socket_util.h"
#include "client.h"
#include "conf.h"
#include "utils.h"
@@ -45,8 +46,6 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "listen"
-#define ALLOW_REUSE 1
-
#define DEFAULT_PORT 6600
struct listen_socket {
@@ -73,49 +72,13 @@ static bool
listen_add_address(int pf, const struct sockaddr *addrp, socklen_t addrlen,
GError **error)
{
- int fd, ret;
- const int reuse = ALLOW_REUSE;
-#ifdef HAVE_STRUCT_UCRED
- int passcred = 1;
-#endif
+ int fd;
struct listen_socket *ls;
GIOChannel *channel;
- fd = socket(pf, SOCK_STREAM, 0);
- if (fd < 0) {
- g_set_error(error, listen_quark(), errno,
- "Failed to create socket: %s", strerror(errno));
+ fd = socket_bind_listen(pf, SOCK_STREAM, 0, addrp, addrlen, 5, error);
+ if (fd < 0)
return false;
- }
-
- ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
- &reuse, sizeof(reuse));
- if (ret < 0) {
- g_set_error(error, listen_quark(), errno,
- "setsockopt() failed: %s", strerror(errno));
- close(fd);
- return false;
- }
-
- ret = bind(fd, addrp, addrlen);
- if (ret < 0) {
- g_set_error(error, listen_quark(), errno,
- "%s", strerror(errno));
- close(fd);
- return false;
- }
-
- ret = listen(fd, 5);
- if (ret < 0) {
- g_set_error(error, listen_quark(), errno,
- "listen() failed: %s", strerror(errno));
- close(fd);
- return false;
- }
-
-#ifdef HAVE_STRUCT_UCRED
- setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &passcred, sizeof(passcred));
-#endif
ls = g_new(struct listen_socket, 1);
ls->fd = fd;