diff --git a/peerconnection/samples/client/conductor.cc b/peerconnection/samples/client/conductor.cc index e8cf73f5a7..bb81411425 100644 --- a/peerconnection/samples/client/conductor.cc +++ b/peerconnection/samples/client/conductor.cc @@ -326,26 +326,27 @@ void Conductor::UIThreadCallback(int msg_id, void* data) { case SEND_MESSAGE_TO_PEER: { LOG(INFO) << "SEND_MESSAGE_TO_PEER"; std::string* msg = reinterpret_cast(data); - if (client_->IsSendingMessage()) { - ASSERT(msg != NULL); + if (msg) { + // For convenience, we always run the message through the queue. + // This way we can be sure that messages are sent to the server + // in the same order they were signaled without much hassle. pending_messages_.push_back(msg); - } else { - if (!msg && !pending_messages_.empty()) { - msg = pending_messages_.front(); - pending_messages_.pop_front(); - } - if (msg) { - bool ok = client_->SendToPeer(peer_id_, *msg); - if (!ok && peer_id_ != -1) { - LOG(LS_ERROR) << "SendToPeer failed"; - DisconnectFromServer(); - } - delete msg; + } + + if (!pending_messages_.empty() && !client_->IsSendingMessage()) { + msg = pending_messages_.front(); + pending_messages_.pop_front(); + + if (!client_->SendToPeer(peer_id_, *msg) && peer_id_ != -1) { + LOG(LS_ERROR) << "SendToPeer failed"; + DisconnectFromServer(); } - if (!peer_connection_.get()) - peer_id_ = -1; + delete msg; } + + if (!peer_connection_.get()) + peer_id_ = -1; break; } diff --git a/peerconnection/samples/client/peer_connection_client.cc b/peerconnection/samples/client/peer_connection_client.cc index a0e30e9676..b3c4ca5414 100644 --- a/peerconnection/samples/client/peer_connection_client.cc +++ b/peerconnection/samples/client/peer_connection_client.cc @@ -289,6 +289,9 @@ bool PeerConnectionClient::ReadIntoBuffer(talk_base::AsyncSocket* socket, if (GetHeaderValue(*data, i, kConnection, &should_close) && should_close.compare("close") == 0) { socket->Close(); + // Since we closed the socket, there was no notification delivered + // to us. Compensate by letting ourselves know. + OnClose(socket, NO_ERROR); } } else { // We haven't received everything. Just continue to accept data. @@ -472,7 +475,7 @@ void PeerConnectionClient::OnClose(talk_base::AsyncSocket* socket, int err) { callback_->OnMessageSent(err); } } else { - // Failed to connect to the server. + LOG(WARNING) << "Failed to connect to the server"; Close(); callback_->OnDisconnected(); }