From a3cae2b7a3dfe8120f2a65a1fae8640bb4f095a5 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 12 Nov 2014 19:53:06 +0100 Subject: Use non-blocking sockets for client communication This approach is better than using blocking sockets and select() since there's no guarantee that send() doesn't block. Plus we're using poll() anyway so send() and recv() will only be called if the socket is actually ready for writing/reading. --- src/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index b1f4eeb..2e4439c 100644 --- a/src/main.c +++ b/src/main.c @@ -82,6 +82,15 @@ static int create_socket(void) { return -1; } + int flags = fcntl(listenfd, F_GETFL, 0); + if (flags < 0) { + usbmuxd_log(LL_FATAL, "ERROR: Could not get flags for socket"); + } else { + if (fcntl(listenfd, F_SETFL, flags | O_NONBLOCK) < 0) { + usbmuxd_log(LL_FATAL, "ERROR: Could not set socket to non-blocking"); + } + } + bzero(&bind_addr, sizeof(bind_addr)); bind_addr.sun_family = AF_UNIX; strcpy(bind_addr.sun_path, socket_path); -- cgit v1.1-32-gdbae