aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/inputStream_http.c5
-rw-r--r--src/interface.c5
-rw-r--r--src/listen.c2
-rw-r--r--src/notify.c41
-rw-r--r--src/notify.h2
-rw-r--r--src/utils.c15
-rw-r--r--src/utils.h2
7 files changed, 31 insertions, 41 deletions
diff --git a/src/inputStream_http.c b/src/inputStream_http.c
index 23434beb6..e633b7a66 100644
--- a/src/inputStream_http.c
+++ b/src/inputStream_http.c
@@ -357,7 +357,7 @@ static int initHTTPConnection(InputStream * inStream)
struct addrinfo *ans = NULL;
struct addrinfo *ap = NULL;
struct addrinfo hints;
- int error, flags;
+ int error;
InputStreamHTTPData *data = (InputStreamHTTPData *) inStream->data;
/**
* Setup hints
@@ -397,8 +397,7 @@ static int initHTTPConnection(InputStream * inStream)
return -1;
}
- flags = fcntl(data->sock, F_GETFL, 0);
- fcntl(data->sock, F_SETFL, flags | O_NONBLOCK);
+ set_nonblocking(data->sock);
if (connect(data->sock, ap->ai_addr, ap->ai_addrlen) >= 0
|| errno == EINPROGRESS) {
diff --git a/src/interface.c b/src/interface.c
index a36131cec..00e009307 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -127,8 +127,6 @@ static void set_send_buf_size(Interface * interface)
static void openInterface(Interface * interface, int fd)
{
- int flags;
-
assert(interface->fd < 0);
interface->cmd_list_size = 0;
@@ -137,8 +135,7 @@ static void openInterface(Interface * interface, int fd)
interface->bufferLength = 0;
interface->bufferPos = 0;
interface->fd = fd;
- while ((flags = fcntl(fd, F_GETFL)) < 0 && errno == EINTR) ;
- while (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0 && errno == EINTR) ;
+ set_nonblocking(fd);
interface->lastTime = time(NULL);
interface->cmd_list = NULL;
interface->cmd_list_tail = NULL;
diff --git a/src/listen.c b/src/listen.c
index e2b55a5d3..918bdb4aa 100644
--- a/src/listen.c
+++ b/src/listen.c
@@ -93,7 +93,7 @@ static int establishListen(unsigned int port,
if ((sock = socket(pf, SOCK_STREAM, 0)) < 0)
FATAL("socket < 0\n");
- if (fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK) < 0) {
+ if (set_nonblocking(sock) < 0) {
FATAL("problems setting nonblocking on listen socket: %s\n",
strerror(errno));
}
diff --git a/src/notify.c b/src/notify.c
index 85db46192..d58987470 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -17,40 +17,17 @@
*/
#include "notify.h"
+#include "os_compat.h"
+#include "log.h"
+#include "utils.h"
-#include <assert.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-int set_nonblock(int fd)
-{
- int ret;
-
- assert(fd >= 0);
-
- ret = fcntl(fd, F_GETFL, 0);
- if (ret < 0)
- return ret;
-
- return fcntl(fd, F_SETFL, ret|O_NONBLOCK);
-}
-
-int initNotify(Notify *notify)
+void initNotify(Notify *notify)
{
- int ret;
-
- ret = pipe(notify->fds);
- if (ret < 0)
- return -1;
-
- ret = set_nonblock(notify->fds[1]);
- if (ret < 0) {
- close(notify->fds[0]);
- close(notify->fds[1]);
- return -1;
- }
-
- return 0;
+ if (pipe(notify->fds) < 0)
+ FATAL("Couldn't open pipe: %s", strerror(errno));
+ if (set_nonblocking(notify->fds[1]) < 0)
+ FATAL("Couldn't set non-blocking on notify fd: %s",
+ strerror(errno));
}
int waitNotify(Notify *notify)
diff --git a/src/notify.h b/src/notify.h
index ce6396a96..6c36b019e 100644
--- a/src/notify.h
+++ b/src/notify.h
@@ -38,7 +38,7 @@ typedef struct _Notify {
int fds[2];
} Notify;
-int initNotify(Notify *notify);
+void initNotify(Notify *notify);
int waitNotify(Notify *notify);
diff --git a/src/utils.c b/src/utils.c
index 8f18a80ff..1ff9a1910 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -214,3 +214,18 @@ char *parsePath(char *path)
return newPath;
}
+
+int set_nonblocking(int fd)
+{
+ int ret, flags;
+
+ assert(fd >= 0);
+
+ while ((flags = fcntl(fd, F_GETFL)) < 0 && errno == EINTR) ;
+ if (flags < 0)
+ return flags;
+
+ flags |= O_NONBLOCK;
+ while ((ret = fcntl(fd, F_SETFL, flags)) < 0 && errno == EINTR) ;
+ return ret;
+}
diff --git a/src/utils.h b/src/utils.h
index 564db0fe7..e8a464ad5 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -79,4 +79,6 @@ mpd_malloc void *xcalloc(size_t nmemb, size_t size);
char *parsePath(char *path);
+int set_nonblocking(int fd);
+
#endif