Exemple #1
0
void AsyncTCPSocket::OnReadEvent(AsyncSocket* socket) {
  ASSERT(socket == socket_);

  if (listen_) {
    txmpp::SocketAddress address;
    txmpp::AsyncSocket* new_socket = socket->Accept(&address);
    if (!new_socket) {
      // TODO: Do something better like forwarding the error
      // to the user.
      LOG(LS_ERROR) << "TCP accept failed with error " << socket_->GetError();
      return;
    }

    SignalNewConnection(this, new AsyncTCPSocket(new_socket, false));

    // Prime a read event in case data is waiting.
    new_socket->SignalReadEvent(new_socket);
  } else {
    int len = socket_->Recv(inbuf_ + inpos_, insize_ - inpos_);
    if (len < 0) {
      // TODO: Do something better like forwarding the error to the user.
      if (!socket_->IsBlocking()) {
        LOG(LS_ERROR) << "Recv() returned error: " << socket_->GetError();
      }
      return;
    }

    inpos_ += len;

    ProcessInput(inbuf_, inpos_);

    if (inpos_ >= insize_) {
      LOG(LS_ERROR) << "input buffer overflow";
      ASSERT(false);
      inpos_ = 0;
    }
  }
}
void AsyncTCPSocketNormal::HandleIncomingConnection(talk_base::AsyncSocket* socket) {
    SignalNewConnection(this, new AsyncTCPSocketNormal(socket, false));
}