info: do not block when receiving the request
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 3 Jan 2017 10:15:25 +0000 (11:15 +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.

Note: this will effectively disallow user-operated telnet connection, since
      the code will not wait for input and expects the request to be there
      once it tries to receive data.
      A normal telnet connection did not work before (v0.6.8.1 was checked)
      so no surprises here.

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

index 0334333..68c9361 100644 (file)
@@ -790,7 +790,14 @@ static void ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int
     return;
   }
 
-  rx_count = recv(ipc_connection, req, sizeof(req_buffer), 0);
+#ifdef _WIN32
+  rx_count = recv(ipc_connection, req, sizeof(req_buffer), MSG_PEEK);
+  if (rx_count > 0) {
+    rx_count = recv(ipc_connection, req, sizeof(req_buffer), 0);
+  }
+#else
+  rx_count = recv(ipc_connection, req, sizeof(req_buffer), MSG_DONTWAIT);
+#endif
 
   /* Upon successful completion, recv() shall return the length of the message
    * in bytes. If no messages are available to be received and the peer has