Commit 42df6101 authored by sergeyu's avatar sergeyu Committed by Commit bot

Fix LibjingleTransport not to wait for channel to be writable.

Previously LibjingleTransport was waiting for channel to be become
writable before considering it to be connected. As result it was loosing
all data that's received before the channel is marked as writable.

BUG=477142

Review URL: https://codereview.chromium.org/1080633005

Cr-Commit-Position: refs/heads/master@{#325347}
parent f54d5df0
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include "base/callback.h" #include "base/callback.h"
#include "base/callback_helpers.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h" #include "base/thread_task_runner_handle.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
...@@ -56,7 +57,7 @@ class LibjingleTransport ...@@ -56,7 +57,7 @@ class LibjingleTransport
public sigslot::has_slots<> { public sigslot::has_slots<> {
public: public:
LibjingleTransport(cricket::PortAllocator* port_allocator, LibjingleTransport(cricket::PortAllocator* port_allocator,
const NetworkSettings& network_settings); const NetworkSettings& network_settings);
~LibjingleTransport() override; ~LibjingleTransport() override;
// Called by JingleTransportFactory when it has fresh Jingle info. // Called by JingleTransportFactory when it has fresh Jingle info.
...@@ -104,7 +105,6 @@ class LibjingleTransport ...@@ -104,7 +105,6 @@ class LibjingleTransport
std::list<cricket::Candidate> pending_candidates_; std::list<cricket::Candidate> pending_candidates_;
scoped_ptr<cricket::P2PTransportChannel> channel_; scoped_ptr<cricket::P2PTransportChannel> channel_;
bool channel_was_writable_;
int connect_attempts_left_; int connect_attempts_left_;
base::RepeatingTimer<LibjingleTransport> reconnect_timer_; base::RepeatingTimer<LibjingleTransport> reconnect_timer_;
...@@ -122,7 +122,6 @@ LibjingleTransport::LibjingleTransport(cricket::PortAllocator* port_allocator, ...@@ -122,7 +122,6 @@ LibjingleTransport::LibjingleTransport(cricket::PortAllocator* port_allocator,
rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH)), rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH)),
ice_password_(rtc::CreateRandomString(cricket::ICE_PWD_LENGTH)), ice_password_(rtc::CreateRandomString(cricket::ICE_PWD_LENGTH)),
can_start_(false), can_start_(false),
channel_was_writable_(false),
connect_attempts_left_(kMaxReconnectAttempts), connect_attempts_left_(kMaxReconnectAttempts),
weak_factory_(this) { weak_factory_(this) {
DCHECK(!ice_username_fragment_.empty()); DCHECK(!ice_username_fragment_.empty());
...@@ -204,6 +203,10 @@ void LibjingleTransport::DoStart() { ...@@ -204,6 +203,10 @@ void LibjingleTransport::DoStart() {
reconnect_timer_.Start( reconnect_timer_.Start(
FROM_HERE, base::TimeDelta::FromSeconds(kReconnectDelaySeconds), FROM_HERE, base::TimeDelta::FromSeconds(kReconnectDelaySeconds),
this, &LibjingleTransport::TryReconnect); this, &LibjingleTransport::TryReconnect);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&LibjingleTransport::NotifyConnected,
weak_factory_.GetWeakPtr()));
} }
void LibjingleTransport::NotifyConnected() { void LibjingleTransport::NotifyConnected() {
...@@ -212,10 +215,7 @@ void LibjingleTransport::NotifyConnected() { ...@@ -212,10 +215,7 @@ void LibjingleTransport::NotifyConnected() {
new jingle_glue::TransportChannelSocketAdapter(channel_.get())); new jingle_glue::TransportChannelSocketAdapter(channel_.get()));
socket->SetOnDestroyedCallback(base::Bind( socket->SetOnDestroyedCallback(base::Bind(
&LibjingleTransport::OnChannelDestroyed, base::Unretained(this))); &LibjingleTransport::OnChannelDestroyed, base::Unretained(this)));
base::ResetAndReturn(&callback_).Run(socket.Pass());
Transport::ConnectedCallback callback = callback_;
callback_.Reset();
callback.Run(socket.Pass());
} }
void LibjingleTransport::AddRemoteCandidate( void LibjingleTransport::AddRemoteCandidate(
...@@ -274,13 +274,6 @@ void LibjingleTransport::OnWritableState( ...@@ -274,13 +274,6 @@ void LibjingleTransport::OnWritableState(
DCHECK_EQ(channel, channel_.get()); DCHECK_EQ(channel, channel_.get());
if (channel->writable()) { if (channel->writable()) {
if (!channel_was_writable_) {
channel_was_writable_ = true;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&LibjingleTransport::NotifyConnected,
weak_factory_.GetWeakPtr()));
}
connect_attempts_left_ = kMaxReconnectAttempts; connect_attempts_left_ = kMaxReconnectAttempts;
reconnect_timer_.Stop(); reconnect_timer_.Stop();
...@@ -288,17 +281,15 @@ void LibjingleTransport::OnWritableState( ...@@ -288,17 +281,15 @@ void LibjingleTransport::OnWritableState(
// writable. Notify the event handler about the current route once the // writable. Notify the event handler about the current route once the
// channel is writable. // channel is writable.
NotifyRouteChanged(); NotifyRouteChanged();
} else if (!channel->writable() && channel_was_writable_) { } else {
reconnect_timer_.Reset(); reconnect_timer_.Reset();
TryReconnect(); TryReconnect();
} }
} }
void LibjingleTransport::OnChannelDestroyed() { void LibjingleTransport::OnChannelDestroyed() {
if (is_connected()) { // The connection socket is being deleted, so delete the transport too.
// The connection socket is being deleted, so delete the transport too. delete this;
delete this;
}
} }
void LibjingleTransport::NotifyRouteChanged() { void LibjingleTransport::NotifyRouteChanged() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment