From 73ba4160f6a7086595551e135b3a43868ead1a1e Mon Sep 17 00:00:00 2001 From: "perkj@webrtc.org" Date: Mon, 10 Oct 2011 11:15:35 +0000 Subject: [PATCH] Fix OnClose(socket, NO_ERROR) compile error on Linux. Merge Peerconnection_client_dev with Peerconnection_client. BUG= TEST= Review URL: http://webrtc-codereview.appspot.com/215002 git-svn-id: http://webrtc.googlecode.com/svn/trunk@720 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../samples/client/peer_connection_client.cc | 2 +- .../peerconnection_client/conductor.cc | 37 ++++++++++--------- .../peer_connection_client.cc | 5 ++- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/peerconnection/samples/client/peer_connection_client.cc b/peerconnection/samples/client/peer_connection_client.cc index b3c4ca541..d8a9a4ff2 100644 --- a/peerconnection/samples/client/peer_connection_client.cc +++ b/peerconnection/samples/client/peer_connection_client.cc @@ -291,7 +291,7 @@ bool PeerConnectionClient::ReadIntoBuffer(talk_base::AsyncSocket* socket, socket->Close(); // Since we closed the socket, there was no notification delivered // to us. Compensate by letting ourselves know. - OnClose(socket, NO_ERROR); + OnClose(socket, 0); } } else { // We haven't received everything. Just continue to accept data. diff --git a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc index 15877f5a1..b08647bd0 100644 --- a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc +++ b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc @@ -305,26 +305,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 (!peer_connection_.get()) - peer_id_ = -1; } + + 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(); + } + delete msg; + } + + if (!peer_connection_.get()) + peer_id_ = -1; + break; } diff --git a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/peer_connection_client.cc b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/peer_connection_client.cc index 07e3c7467..3de4c311e 100644 --- a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/peer_connection_client.cc +++ b/third_party_mods/libjingle/source/talk/examples/peerconnection_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, 0); } } 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(); }