Ticket #1623: licq-6140-connectionlimit.patch

File licq-6140-connectionlimit.patch, 1.5 kB (added by flynd, 9 months ago)

Patch that should fix the descriptor handling.

  • include/licq_socket.h

     
    250250 
    251251  fd_set SocketSet()   {  return m_sSockets.SocketSet(); } 
    252252  int LargestSocket()  {  return m_sSockets.Largest(); } 
     253  unsigned short Num() { return m_sSockets.Num(); } 
    253254 
    254255protected: 
    255256  CSocketSet m_sSockets; 
  • src/icqd-threads.cpp

     
    780780              TCPSocket *newSocket = new TCPSocket(0); 
    781781              tcp->RecvConnection(*newSocket); 
    782782              gSocketManager.DropSocket(tcp); 
    783               gSocketManager.AddSocket(newSocket); 
    784               gSocketManager.DropSocket(newSocket); 
     783 
     784              // Make sure we can handle another socket before accepting it 
     785              if (newSocket->Descriptor() >= FD_SETSIZE || gSocketManager.Num() > 128) 
     786              { 
     787                // Too many sockets, drop this one 
     788                char remoteIp[32]; 
     789                gLog.Warn(tr("%sToo many connected sockets, rejecting connection from %s.\n"), 
     790                    L_WARNxSTR, newSocket->RemoteIpStr(remoteIp)); 
     791                delete newSocket; 
     792              } 
     793              else 
     794              { 
     795                gSocketManager.AddSocket(newSocket); 
     796                gSocketManager.DropSocket(newSocket); 
     797              } 
    785798            } 
    786799          } 
    787800