Posted by
| Nick Gammon
Australia (22,989 posts) bio
Forum Administrator |
Message
| Is this SMAUG?
Your problem vaguely rang a bell with me, and a bit of research revealed I had a similar problem a while back, however this was with a MUD from Ron Penton's book "MUD Game Programming".
It would compile OK, and start up, but when I connected, nothing happened (however no CPU loop either).
Some lengthy debugging revealed an "out by one" error in the code that handled new connections.
These are the diffs of the change:
diff -c -r Libraries/SocketLib/SocketSet.h Libraries.fixed/SocketLib/SocketSet.h
*** Libraries/SocketLib/SocketSet.h 2005-12-07 13:22:58.000000000 +1100
--- Libraries.fixed/SocketLib/SocketSet.h 2005-12-07 13:19:18.000000000 +1100
***************
*** 39,46 ****
#ifdef WIN32
return select( 0, &m_activityset, 0, 0, &t );
#else
! if( m_socketdescs.size() == 0 ) return 0;
! return select( *(m_socketdescs.rbegin()), &m_activityset, 0, 0, &t );
#endif
}
--- 39,46 ----
#ifdef WIN32
return select( 0, &m_activityset, 0, 0, &t );
#else
! if( m_socketdescs.size() == 0 ) return 0;
! return select( *(m_socketdescs.rbegin()) + 1, &m_activityset, 0, 0, &t );
#endif
}
Now if this is stock SMAUG it won't help much, however it might help to put some debugging displays around where it does the select.
Effectively what is happening here is that the new connection triggers off a call to the part that checks which sockets have connected, but the select call does not check enough of them. From "man select":
int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout);
And the explanation of "n" is:
n is the highest-numbered descriptor in any of the three sets, plus 1.
The code I had was giving the highest numbered descriptor, so I added 1 so it would be "plus 1".
Maybe that won't help. But maybe if someone is trying to get Ron Penton's MUD working, it might. :) |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|