vijayyande / spserver

Automatically exported from code.google.com/p/spserver
Other
0 stars 0 forks source link

SP_IocpServer::shutdown does not send FIN or RST to clients #45

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When you call SP_IocpServer::shutdown the clients don't receive FIN or RST 
packets. Therefore the connection remains open at the clients' end eventhough 
the server does not accept incoming packets anymore. You should see a FIN or 
RST packet sent to clients so that they can close the connections properly.

To reproduce:
1. Call SP_IocpServer::shutdown
2. Look at network log (from Wireshark, for example) and note that no FIN or 
RST packets were returned to clients.

I'm using version 0.95 of spserver. My operating system is Windows 7. My build 
environment is MinGW's gcc toolchain. I had to make a custom makefile for the 
project for MinGW. I can see from the debugger that closesocket (sp_close 
macro) is called when shutdown is called, but it doesn't result in FIN or RST 
packet. So this may actually be a problem in Windows itself (?).

Does this occur with other build environments?

Original issue reported on code.google.com by mmikk...@gmail.com on 15 Jun 2011 at 1:35

GoogleCodeExporter commented 9 years ago
Only when the whole process is quit, RST packet will be sent.

Original comment by mmikk...@gmail.com on 15 Jun 2011 at 1:38

GoogleCodeExporter commented 9 years ago
I think you have to close the client connections separately, too. Closing the 
listening port is not enough. I added something like this in spiocpserver.cpp, 
SP_IocpServer :: start() (after while( 0 == mIsShutdown ) loop) and that did 
the trick:

        SP_Sid_t sid;
        SP_Session * session;
        if( eventArg.getSessionManager()->getIteratorBegin(&sid) )
        {
            do
            {
                session = eventArg.getSessionManager()->get(sid.mKey,&sid.mSeq);
                SP_IocpEventHelper::close(session);
            }while(eventArg.getSessionManager()->getIteratorNext(sid, &sid));

        }

I added that getIteratorBegin in SP_SessionManager class and it gets the first 
sid in mArray, and getIteratorNext gets the next. They both return boolean 
true/false if there's success/failure respectively.

Maybe the developers could do this in a more sophisticated way? It's probably 
bad practise to make these functions in SP_SessionManager(?). There seems to be 
a doClose function in SP_IocpEventHelper, which adds some sort of closing task, 
so maybe this could be used. But what do I know, I'm not an expert on this.

Original comment by mmikk...@gmail.com on 18 Jun 2011 at 1:20