The port scanner is a free app I found named "Angry IP Scanner". What it does is, first, it sends several pings to module's IP address and the module replies normally. Second, it sends several "NBNS" packets (whatever that is), the module replies with "Destination unreachable (Port unreachable)". Then it attempts a TCP connection, and the module replies with an accept and ACK. The scanner then immediately closes the connection, and is done.
At this point the module is locked up. I verified that the app never returns from accept. I my guess is that, the scanner closed the connection before the call to accept has completed and that accepts blocks forever because the timeout value was set to zero.
Original call:
Code: Select all
int fd = accept( listener, &addr, NULL, 0 );
Code: Select all
int fd = accept( listener, &addr, NULL, TICKS_PER_SECOND / 2);
if ( fd <=0 ) return;
To determine whether to call accept, I check to see if a connection request is pending. This is the way I've handled TCP connections for years.
Code: Select all
if ( !IsSocketReadable( listener ) ) return;
int fd = accept( listener, &addr, NULL, TICKS_PER_SECOND / 2);
if ( fd <=0 ) return;
Code: Select all
bool IsSocketReadable( int fd )
{
static fd_set fds_list;
FD_ZERO( &fds_list ); // reset file descriptor list.
FD_SET( fd, &fds_list ); // add us to list, to be checked for readability.
return ZeroWaitSelect( FD_SETSIZE, &fds_list, NULL, NULL ) != 0; // check for readability and return immediately.
}