have been looking at the donkey code, online in-depth analysis of the article is not much, perhaps this and donkey's code is too large, the code quality is not high may be related. But more may be do not want to share, reluctant to share. In fact, it is the open source of the people do not share the slow to see can understand. Due to the time relationship I will be the analysis of the article post, and share with you netizens, but also hope that we make a discussion of brick to share your experience. Series Analysis articles if not specifically noted with easy mule 0.47 as the standard
The role of the Clistensocket class is to listen to the socket waiting for the client to come and maintain the incoming socket to add accept socket to the list
The function is to create a local listensocket, whether the accept connection is driven by the Winsock message
BOOL Clistensocket::startlistening ()
{
Blistening = true;
Creating the socket with SO_REUSEADDR could solve lowid issues if emule was restarted
Quickly or started after a crash, but (!) It'll also create another problem. If the
The socket is already used by some application (e.g. a 2nd emule), we though bind
To, the socket leading to the situation, 2 applications are listening at the same
port!
if (! Create (Theprefs.getport (), Sock_stream, Fd_accept, Theprefs.getbindaddra (), false/*breuseaddr*/))
return false;
if (! Listen ())
return false;
M_port = Theprefs.getport ();
return true;
}
This function is renamed restartaccept more appropriate
It was meant to start again accepting connections.
Why do I need to start accepting connections again because there are too many connections
Temporarily stoplisteing (blistening set to false;),
When the number of connections is low, the connection restartlistening will start again;
It should be noted that this pause and restart does not actually close/open the local listen port, just set a bool flag
void Clistensocket::restartlistening ()
{
Blistening = true;
ASSERT (m_npendingconnections >= 0);
if (m_npendingconnections > 0)
{
m_npendingconnections--;
OnAccept (0);
}
}