Переглянути джерело

SeqPacketSocketSource: interpret return value 0 from recv as connection closed. Looks like we can't have zero packets.

ambrop7 15 роки тому
батько
коміт
615cc2cff3
2 змінених файлів з 12 додано та 0 видалено
  1. 10 0
      flow/SeqPacketSocketSource.c
  2. 2 0
      flow/SeqPacketSocketSource.h

+ 10 - 0
flow/SeqPacketSocketSource.c

@@ -60,6 +60,11 @@ static int output_handler_recv (SeqPacketSocketSource *s, uint8_t *data, int *da
         return -1;
     }
     
+    if (res == 0) {
+        report_error(s, SEQPACKETSOCKETSOURCE_ERROR_CLOSED);
+        return -1;
+    }
+    
     *data_len = res;
     return 1;
 }
@@ -82,6 +87,11 @@ static void socket_handler (SeqPacketSocketSource *s, int event)
         return;
     }
     
+    if (res == 0) {
+        report_error(s, SEQPACKETSOCKETSOURCE_ERROR_CLOSED);
+        return;
+    }
+    
     BSocket_DisableEvent(s->bsock, BSOCKET_READ);
     s->out_have = 0;
     

+ 2 - 0
flow/SeqPacketSocketSource.h

@@ -33,6 +33,7 @@
 #include <flow/error.h>
 #include <flow/PacketRecvInterface.h>
 
+#define SEQPACKETSOCKETSOURCE_ERROR_CLOSED 0
 #define SEQPACKETSOCKETSOURCE_ERROR_BSOCKET 1
 
 /**
@@ -57,6 +58,7 @@ typedef struct {
  *
  * @param s the object
  * @param rep error reporting data. Error code is an int. Possible error codes:
+ *              - SEQPACKETSOCKETSOURCE_ERROR_CLOSED: {@link BSocket_Recv} returned 0
  *              - SEQPACKETSOCKETSOURCE_ERROR_BSOCKET: {@link BSocket_Recv} failed
  *                with an unhandled error code
  *            The object must be freed from the error handler.