cwSocket.cpp : Sockets are now automatically closed when poll() detects HUP or NVAL conditions.

This commit is contained in:
kpl 2020-03-18 19:54:01 -04:00
parent 33aca956da
commit 11f6d38330

View File

@ -370,21 +370,20 @@ namespace cw
// interate through the ports looking for the ones which have data waiting ... // interate through the ports looking for the ones which have data waiting ...
for(unsigned i=0; i<p->sockN; ++i) for(unsigned i=0; i<p->sockN; ++i)
{ {
if( p->sockA[i].pollfd->revents & POLLHUP ) // if the socket was disconnected or is no longer valid
if( cwIsFlag(p->sockA[i].pollfd->revents,POLLHUP) || cwIsFlag(p->sockA[i].pollfd->revents,POLLNVAL) )
{ {
printf("Socket userId:%i connId:%i disconnected.",p->sockA[i].userId,p->sockA[i].connId); printf("Socket userId:%i connId:%i disconnected.\n",p->sockA[i].userId,p->sockA[i].connId);
_closeSock(p,p->sockA+i); _closeSock(p,p->sockA+i);
continue; continue;
} }
if( p->sockA[i].pollfd->revents & POLLERR ) if( p->sockA[i].pollfd->revents & POLLERR )
{ {
printf("ERROR\n"); printf("ERROR on socket user id:%i conn id:%i\n",p->sockA[i].userId,p->sockA[i].connId);
} }
if( p->sockA[i].pollfd->revents & POLLNVAL )
{
}
if( p->sockA[i].pollfd->revents & POLLIN ) if( p->sockA[i].pollfd->revents & POLLIN )
{ {