]> git.seodisparate.com - UDPConnection/commitdiff
Add check for no pkt received (non-blocking)
authorStephen Seo <seo.disparate@gmail.com>
Mon, 4 Mar 2019 06:27:01 +0000 (15:27 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 4 Mar 2019 06:27:01 +0000 (15:27 +0900)
src/UDPConnection.c

index 609cddcd266b69b8dffa6b5ed87d3790f1b42f75..50b61f8fdb6ef218fb74262339f4c15c6ceb26b0 100644 (file)
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <errno.h>
 
 UDPC_Context* UDPC_init(uint16_t listenPort, int isClient)
 {
@@ -460,6 +461,13 @@ void UDPC_update(UDPC_Context *ctx)
         0,
         (struct sockaddr*) &receivedData,
         &receivedDataSize);
+
+    if(bytes == 0 && (errno == EAGAIN || errno == EWOULDBLOCK))
+    {
+        // expected result for non-blocking socket
+        return;
+    }
+
     if(bytes < 20)
     {
         UDPC_INTERNAL_log(ctx, 2, "Got invalid packet from %s port %d (too small)",