info: fix drain_request to not block
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 3 Jan 2017 10:10:16 +0000 (11:10 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 4 Jan 2017 08:47:11 +0000 (09:47 +0100)
Otherwise the whole of olsrd is blocked, since it's single-threaded

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/info/olsrd_info.c

index 75fa076..9ba73ba 100644 (file)
@@ -716,7 +716,17 @@ static char * checkCommandPrefixes(char * req, size_t *len, bool *add_headers) {
 static void drain_request(int ipc_connection) {
   static char drain_buffer[AUTOBUFCHUNK];
 
-  while (recv(ipc_connection, (void *) &drain_buffer, sizeof(drain_buffer), 0) == sizeof(drain_buffer)) {}
+  ssize_t r;
+  do {
+#ifdef _WIN32
+    r = recv(ipc_connection, (void *) &drain_buffer, sizeof(drain_buffer), MSG_PEEK);
+    if (r > 0) {
+      r = recv(ipc_connection, (void *) &drain_buffer, sizeof(drain_buffer), 0);
+    }
+#else
+    r = recv(ipc_connection, (void *) &drain_buffer, sizeof(drain_buffer), MSG_DONTWAIT);
+#endif
+  } while ((r > 0) && (r <= (ssize_t) sizeof(drain_buffer)));
 }
 
 static void ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int flags __attribute__ ((unused))) {