|
@@ -16,6 +16,7 @@
|
|
|
#include <sys/socket.h>
|
|
|
#include <netinet/in.h>
|
|
|
#include <sys/socketvar.h>
|
|
|
+#include <sys/ioctl.h>
|
|
|
#include <unistd.h> // read, write, close
|
|
|
#define CLOSESOCKET(S) close(S)
|
|
|
#define IOCTLSOCKET ioctl
|
|
@@ -242,7 +243,13 @@ void worksocks(NetworklayerTCP *layer, UA_Server *server, UA_UInt32 workamount)
|
|
|
// read from established sockets
|
|
|
for(UA_UInt32 i=0;i<layer->connectionsSize && workamount > 0;i++) {
|
|
|
if(FD_ISSET(layer->connections[i].sockfd, &layer->fdset)) {
|
|
|
- readConnection(layer, server, &layer->connections[i]);
|
|
|
+ int n = 0;
|
|
|
+ IOCTLSOCKET(layer->connections[i].sockfd, FIONREAD, &n);
|
|
|
+ if(n==0){ /* the socket has been closed by the client - remove the socket from the socket list */
|
|
|
+ layer->connections[i].connection.close(layer->connections[i].connection.callbackHandle);
|
|
|
+ }else{
|
|
|
+ readConnection(layer, server, &layer->connections[i]);
|
|
|
+ }
|
|
|
workamount--;
|
|
|
}
|
|
|
}
|