Logo Search packages:      
Sourcecode: verlihub version File versions

int nServer::cAsyncConn::ReadAll (  ) 

reads all available data from the socket and stores it into a static member buffer

Definition at line 281 of file casyncconn.cpp.

References CloseNow(), nUtils::cTime::Get(), GetType(), cObj::Log(), cObj::LogStream(), mAddrIN, mBufEnd, mBufReadPos, msBuffer, mSockDesc, mWritable, and ok.

Referenced by nDirectConnect::cServerDC::DoRegisterInHublist(), and nServer::cAsyncSocketServer::input().

{
      int buf_len = 0 , i=0, addr_len = sizeof(struct sockaddr);
      mBufReadPos = 0;
      mBufEnd = 0;
      bool udp = (this->GetType() == eCT_CLIENTUDP);
      
      if(!ok || !mWritable) return -1;

      if(!udp)
      {
            while(
                  ((buf_len = recv(mSockDesc, msBuffer, MAX_MESS_SIZE, 0)) == -1) &&
                  ((errno == EAGAIN) || (errno == EINTR))
                  && (i++ <= 100)
            )     {
#if ! defined _WIN32
          ::usleep(5);
#endif
            }
      }
      else
      {
            //cout << "cAsyncConn::ReadAll (udp)" << endl;
            while(
                  ((buf_len = recvfrom(mSockDesc, msBuffer, MAX_MESS_SIZE, 0, (struct sockaddr *)&mAddrIN, (socklen_t *)&addr_len)) == -1) &&
                  (i++ <= 100)
            ) {
#if ! defined _WIN32
                  ::usleep(5);
#endif
            }
            //cout << "cAsyncConn::ReadAll (udp read bytes: " << buf_len << " )" << endl;
      }

      if(buf_len <= 0)
      {
            if(!udp)
            {
                  if(buf_len == 0)
                  {
                        /* Connection closed - hung up*/
                        if(Log(2)) LogStream() << "User hung up.." << endl;
                        CloseNow();
                        return -1;
                  }
                  else
                  {
                        if(Log(2)) LogStream() << "Read IO Error: " << errno << " : " << strerror(errno) << endl;
                        switch(errno)
                        {
                              case ECONNRESET:/* connection reset by peer */ break;
                              case ETIMEDOUT:/* connection timed out */break;
                              case EHOSTUNREACH:/* No route to host */ break;
                              default:break;
                        } // end switch
                  }
                  CloseNow();
                  return -1;
            }
      }
      else
      {
            // received data
            mBufEnd = buf_len;
            mBufReadPos = 0;
            msBuffer[mBufEnd]='\0'; // end the string
            mTimeLastIOAction.Get();
      }
      return buf_len;
}


Generated by  Doxygen 1.6.0   Back to index