After sending a lot, my call to send () causes my program to stop completely. How is this possible?

So basically I create an MMO server in C ++ that runs on linux. At first it works fine, but after 40 seconds with 50 clients it will completely stop. When I debug it, I found that basically the last frame before it stops responding is syscall (), after which it disappears into the kernel. Once it disappears into the kernel, it does not even return a value ... it is completely puzzling.

Each of the 50 clients sends 23 bytes every 250 milliseconds. Then these 23 bytes are transferred to all other 49 clients. This process starts to slow down and then eventually ends when the kernel never returns from syscall for the send () command. What are the possible reasons? It really turns me on!

One option I found is the Nagle algorithm, which delays delays. I tried switching to it, but it will happen anyway.

Edit: The program is stuck here. In particular, in send, which in turn calls syscall ()

bool EpollManager::s_send(int curFD, unsigned char buf[], int bufLen, int flag) 
//     Meant to counteract partial sends
{
    int sendRetVal = 0;
    int bytesSent = 0;
    while(bytesSent != bufLen)
    {
 print_buffer(buf, bufLen);
        sendRetVal = send(curFD, buf + bytesSent, bufLen - bytesSent, flag); 

        cout << sendRetVal << " ";
        if(sendRetVal == -1)
        {
            perror("Sending failed");
            return false;
        }
        else
            bytesSent += sendRetVal;
    }
    return true;
}

It is also a method that calls s_send.

    void EpollManager::broadcast(unsigned char msg[], int bytesRead, int sender)
    {
 for(iMap = connections.begin(); iMap != connections.end(); iMap++)
 {
  if(sender != iMap->first)
  {
   if(s_send(iMap->first, msg, bytesRead, 0)) // MSG_NOSIGNAL
   {
       if(debug)
       {
                    print_buffer(msg, bytesRead);
                    cout << "sent on file descriptor " << iMap->first << '\n';
       }
   }
  }
 }
 if(connections.find(sender) != connections.end())
        connections[sender]->reset_batch();
    }

boost unordered_map. , , . , , , -, .

+3
2

. , . ?

+1

TCP, , ( SO_SNDBUF) send() .

- , . Linux poll() , Windows -. , , libevent - - Windows IOCP, Boost: ASIO ++.

IO C10K.

, Nagle -, - .

+2

All Articles