diff --git a/src/UDPConnection.c b/src/UDPConnection.c index 50b61f8..4cde3ab 100644 --- a/src/UDPConnection.c +++ b/src/UDPConnection.c @@ -462,7 +462,7 @@ void UDPC_update(UDPC_Context *ctx) (struct sockaddr*) &receivedData, &receivedDataSize); - if(bytes == 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) + if(bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) { // expected result for non-blocking socket return; diff --git a/src/test/UDPC_NetworkTest.c b/src/test/UDPC_NetworkTest.c index 87666c3..73f1ebb 100644 --- a/src/test/UDPC_NetworkTest.c +++ b/src/test/UDPC_NetworkTest.c @@ -10,12 +10,27 @@ void printUsage() printf("Usage: [-c] -a -p -l \n"); } +void conCallback(void *userdata, uint32_t addr) +{ + *((int*)userdata) = 1; +} + +void discCallback(void *userdata, uint32_t addr) +{ + *((int*)userdata) = 0; +} + +void recCallback(void *userdata, char *data, uint32_t size) +{ +} + int main(int argc, char** argv) { int isClient = 0; uint32_t targetAddress = 0; uint16_t targetPort = 0; uint16_t listenPort = 0; + int isConnected = 0; --argc; ++argv; while(argc > 0) @@ -51,6 +66,9 @@ int main(int argc, char** argv) if(UDPC_get_error(ctx) == UDPC_SUCCESS) { UDPC_set_logging_type(ctx, 4); + UDPC_set_callback_connected(ctx, conCallback, &isConnected); + UDPC_set_callback_disconnected(ctx, discCallback, &isConnected); + UDPC_set_callback_received(ctx, recCallback, NULL); while(UDPC_get_error(ctx) == UDPC_SUCCESS) { if(isClient)