Results 1 to 5 of 5

Thread: ClanLib 2.0.3 CL_NetGameServer CPU 100% when client disconnects

  1. #1

    Default ClanLib 2.0.3 CL_NetGameServer CPU 100% when client disconnects

    As topic says: when CL_NetGameClient disconnects from CL_NetGameServer the CPU usage rises to 100%. This happends only if clients disconnects in dirty way (e.g. process kill). When invoking CL_NetGameClient::disconect() earlier then everything is just fine.

    Oh, and network is initialized on client and server too :-)

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    I'm sorry, I am unable to reproduce this behaviour. Could you provide us with a minimal example demonstrating this effect ?

  3. #3

    Default

    Sure! Here it is:

    Code:
    #include <ClanLib/core.h>
    #include <ClanLib/network.h>
    #include <ClanLib/application.h>
    
    class ServerApplication {
        public:
            static int main(const std::vector<CL_String> &args);
    };
    
    CL_ClanApplication app(&ServerApplication::main);
    
    int ServerApplication::main(const std::vector<CL_String> &args) {
        CL_SetupCore setup_core;
        CL_SetupNetwork setup_network;
        
        CL_NetGameServer server;
        server.start("1234");
    
        while (true) {
            CL_KeepAlive::process();
            CL_System::sleep(10);
        }
    }
    I must tell that the same behavior can be observed in Examples/NetGame

    And btw I am working on Ubuntu 9.04 :-)

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    The problem is here:
    Code:
    int CL_IODeviceProvider_TCPConnection::receive(void *data, int len, bool receive_all)
    {
    	if (!receive_all)
    	{
    		return socket.receive(data, len);
    	}
    	else
    	{
    		char *d = (char *) data;
    		int pos = 0;
    		while (pos < len)
    		{
    			if (!read_event.wait(timeout))
    				throw CL_Exception(cl_text("Receive timed out"));
    			pos += socket.receive(d+pos, len-pos);
    		}
    		return pos;
    	}
    }
    When the client unexpectedly disconnects, socket.receive() returns 0
    So, there will be a 15 second timeout.

    I don't know of the best way to fix it.

  5. #5
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    The read function should throw an exception if receive_all is set to true and its unable to retrieve the full amount of data, which it is when it received a 'connection closed' 0 byte marker.

    I've committed a fix for this bug. Thanks for tracking it down.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •