DevTools: Fixed suspected bug in port forwarding

Port forwarding tunnel test revealed a bug in stream_listen_socket on Windows. The last packet was not delivered to DidRead, DidClose was called instead.

BUG=356617

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271985 0039d316-1c4b-4281-b951-d872f2087c98
parent 7e4c3314
...@@ -61,7 +61,7 @@ class PortForwardingTest: public InProcessBrowserTest { ...@@ -61,7 +61,7 @@ class PortForwardingTest: public InProcessBrowserTest {
}; };
IN_PROC_BROWSER_TEST_F(PortForwardingTest, IN_PROC_BROWSER_TEST_F(PortForwardingTest,
DISABLED_LoadPageWithStyleAnsScript) { LoadPageWithStyleAnsScript) {
Profile* profile = browser()->profile(); Profile* profile = browser()->profile();
AndroidDeviceManager::DeviceProviders device_providers; AndroidDeviceManager::DeviceProviders device_providers;
......
...@@ -120,8 +120,14 @@ class SocketTunnel : public base::NonThreadSafe { ...@@ -120,8 +120,14 @@ class SocketTunnel : public base::NonThreadSafe {
return; return;
} }
++pending_writes_; // avoid SelfDestruct in first Pump
Pump(host_socket_.get(), remote_socket_.get()); Pump(host_socket_.get(), remote_socket_.get());
Pump(remote_socket_.get(), host_socket_.get()); --pending_writes_;
if (pending_destruction_) {
SelfDestruct();
} else {
Pump(remote_socket_.get(), host_socket_.get());
}
} }
void Pump(net::StreamSocket* from, net::StreamSocket* to) { void Pump(net::StreamSocket* from, net::StreamSocket* to) {
......
...@@ -149,7 +149,7 @@ class SocketPump : public net::StreamListenSocket::Delegate { ...@@ -149,7 +149,7 @@ class SocketPump : public net::StreamListenSocket::Delegate {
} }
void SelfDestruct() { void SelfDestruct() {
if (wire_buffer_->offset() != wire_buffer_size_) { if (wire_buffer_ && wire_buffer_->offset() != wire_buffer_size_) {
pending_destruction_ = true; pending_destruction_ = true;
return; return;
} }
......
...@@ -252,14 +252,11 @@ void StreamListenSocket::OnObjectSignaled(HANDLE object) { ...@@ -252,14 +252,11 @@ void StreamListenSocket::OnObjectSignaled(HANDLE object) {
return; return;
} }
if (ev.lNetworkEvents & FD_CLOSE) { if (!(ev.lNetworkEvents & FD_CLOSE)) {
Close(); // The object was reset by WSAEnumNetworkEvents. Watch for the next signal.
// Close might have deleted this object. We should return immediately. watcher_.StartWatching(object, this);
return;
} }
// The object was reset by WSAEnumNetworkEvents. Watch for the next signal.
watcher_.StartWatching(object, this);
if (ev.lNetworkEvents == 0) { if (ev.lNetworkEvents == 0) {
// Occasionally the event is set even though there is no new data. // Occasionally the event is set even though there is no new data.
...@@ -274,10 +271,14 @@ void StreamListenSocket::OnObjectSignaled(HANDLE object) { ...@@ -274,10 +271,14 @@ void StreamListenSocket::OnObjectSignaled(HANDLE object) {
has_pending_reads_ = true; has_pending_reads_ = true;
} else { } else {
Read(); Read();
// Read() might call Close() internally and 'this' can be invalid here // Read doesn't call Close() in Windows case. We keep going.
return;
} }
} }
if (ev.lNetworkEvents & FD_CLOSE) {
Close();
// Close might have deleted this object. We should return immediately.
return;
}
} }
#elif defined(OS_POSIX) #elif defined(OS_POSIX)
void StreamListenSocket::OnFileCanReadWithoutBlocking(int fd) { void StreamListenSocket::OnFileCanReadWithoutBlocking(int fd) {
......
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