summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/socket/ssl_client_socket_nss.cc18
-rw-r--r--net/socket/ssl_server_socket_nss.cc18
-rw-r--r--net/socket/ssl_server_socket_unittest.cc45
-rw-r--r--remoting/protocol/jingle_session_unittest.cc9
4 files changed, 64 insertions, 26 deletions
diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc
index 27894c4..0a28439 100644
--- a/net/socket/ssl_client_socket_nss.cc
+++ b/net/socket/ssl_client_socket_nss.cc
@@ -1749,15 +1749,23 @@ void SSLClientSocketNSS::UncorkAfterTimeout() {
} while (nsent > 0);
}
-// Do network I/O between the given buffer and the given socket.
-// Return true if some I/O performed, false otherwise (error or ERR_IO_PENDING)
+// Do as much network I/O as possible between the buffer and the
+// transport socket. Return true if some I/O performed, false
+// otherwise (error or ERR_IO_PENDING).
bool SSLClientSocketNSS::DoTransportIO() {
EnterFunction("");
bool network_moved = false;
if (nss_bufs_ != NULL) {
- int nsent = BufferSend();
- int nreceived = BufferRecv();
- network_moved = (nsent > 0 || nreceived >= 0);
+ int rv;
+ // Read and write as much data as we can. The loop is neccessary
+ // because Write() may return synchronously.
+ do {
+ rv = BufferSend();
+ if (rv > 0)
+ network_moved = true;
+ } while (rv > 0);
+ if (BufferRecv() >= 0)
+ network_moved = true;
}
LeaveFunction(network_moved);
return network_moved;
diff --git a/net/socket/ssl_server_socket_nss.cc b/net/socket/ssl_server_socket_nss.cc
index bdcff2c..83a382e 100644
--- a/net/socket/ssl_server_socket_nss.cc
+++ b/net/socket/ssl_server_socket_nss.cc
@@ -528,14 +528,22 @@ void SSLServerSocketNSS::BufferRecvComplete(int result) {
OnRecvComplete(result);
}
-// Do network I/O between the given buffer and the given socket.
-// Return true if some I/O performed, false otherwise (error or ERR_IO_PENDING)
+// Do as much network I/O as possible between the buffer and the
+// transport socket. Return true if some I/O performed, false
+// otherwise (error or ERR_IO_PENDING).
bool SSLServerSocketNSS::DoTransportIO() {
bool network_moved = false;
if (nss_bufs_ != NULL) {
- int nsent = BufferSend();
- int nreceived = BufferRecv();
- network_moved = (nsent > 0 || nreceived >= 0);
+ int rv;
+ // Read and write as much data as we can. The loop is neccessary
+ // because Write() may return synchronously.
+ do {
+ rv = BufferSend();
+ if (rv > 0)
+ network_moved = true;
+ } while (rv > 0);
+ if (BufferRecv() >= 0)
+ network_moved = true;
}
return network_moved;
}
diff --git a/net/socket/ssl_server_socket_unittest.cc b/net/socket/ssl_server_socket_unittest.cc
index 64b5922..5962cfa 100644
--- a/net/socket/ssl_server_socket_unittest.cc
+++ b/net/socket/ssl_server_socket_unittest.cc
@@ -15,10 +15,14 @@
#include "net/socket/ssl_server_socket.h"
+#include <stdlib.h>
+
#include <queue>
+#include "base/compiler_specific.h"
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/message_loop.h"
#include "base/path_service.h"
#include "crypto/nss_util.h"
#include "crypto/rsa_private_key.h"
@@ -46,7 +50,10 @@ namespace {
class FakeDataChannel {
public:
- FakeDataChannel() : read_callback_(NULL), read_buf_len_(0) {
+ FakeDataChannel()
+ : read_callback_(NULL),
+ read_buf_len_(0),
+ ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) {
}
virtual int Read(IOBuffer* buf, int buf_len,
@@ -63,13 +70,15 @@ class FakeDataChannel {
virtual int Write(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
data_.push(new net::DrainableIOBuffer(buf, buf_len));
- DoReadCallback();
+ MessageLoop::current()->PostTask(
+ FROM_HERE, task_factory_.NewRunnableMethod(
+ &FakeDataChannel::DoReadCallback));
return buf_len;
}
private:
void DoReadCallback() {
- if (!read_callback_)
+ if (!read_callback_ || data_.empty())
return;
int copied = PropogateData(read_buf_, read_buf_len_);
@@ -97,6 +106,8 @@ class FakeDataChannel {
std::queue<scoped_refptr<net::DrainableIOBuffer> > data_;
+ ScopedRunnableMethodFactory<FakeDataChannel> task_factory_;
+
DISALLOW_COPY_AND_ASSIGN(FakeDataChannel);
};
@@ -109,16 +120,19 @@ class FakeSocket : public StreamSocket {
}
virtual ~FakeSocket() {
-
}
virtual int Read(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
+ // Read random number of bytes.
+ buf_len = rand() % buf_len + 1;
return incoming_->Read(buf, buf_len, callback);
}
virtual int Write(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
+ // Write random number of bytes.
+ buf_len = rand() % buf_len + 1;
return outgoing_->Write(buf, buf_len, callback);
}
@@ -204,17 +218,28 @@ TEST(FakeSocketTest, DataTransfer) {
scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(kReadBufSize);
// Write then read.
- EXPECT_EQ(kTestDataSize, server.Write(write_buf, kTestDataSize, NULL));
- EXPECT_EQ(kTestDataSize, client.Read(read_buf, kReadBufSize, NULL));
- EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), kTestDataSize));
+ int written = server.Write(write_buf, kTestDataSize, NULL);
+ EXPECT_GT(written, 0);
+ EXPECT_LE(written, kTestDataSize);
+
+ int read = client.Read(read_buf, kReadBufSize, NULL);
+ EXPECT_GT(read, 0);
+ EXPECT_LE(read, written);
+ EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read));
// Read then write.
TestCompletionCallback callback;
EXPECT_EQ(net::ERR_IO_PENDING,
server.Read(read_buf, kReadBufSize, &callback));
- EXPECT_EQ(kTestDataSize, client.Write(write_buf, kTestDataSize, NULL));
- EXPECT_EQ(kTestDataSize, callback.WaitForResult());
- EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), kTestDataSize));
+
+ written = client.Write(write_buf, kTestDataSize, NULL);
+ EXPECT_GT(written, 0);
+ EXPECT_LE(written, kTestDataSize);
+
+ read = callback.WaitForResult();
+ EXPECT_GT(read, 0);
+ EXPECT_LE(read, written);
+ EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read));
}
class SSLServerSocketTest : public PlatformTest {
diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc
index 504176e..538ef05 100644
--- a/remoting/protocol/jingle_session_unittest.cc
+++ b/remoting/protocol/jingle_session_unittest.cc
@@ -641,8 +641,7 @@ TEST_F(JingleSessionTest, Connect) {
}
// Verify that data can be transmitted over the event channel.
-// TODO(wez): See crbug.com/88726
-TEST_F(JingleSessionTest, FLAKY_TestControlChannel) {
+TEST_F(JingleSessionTest, TestControlChannel) {
CreateServerPair();
ASSERT_TRUE(InitiateConnection());
scoped_refptr<TCPChannelTester> tester(
@@ -657,8 +656,7 @@ TEST_F(JingleSessionTest, FLAKY_TestControlChannel) {
}
// Verify that data can be transmitted over the video channel.
-// TODO(wez): See crbug.com/88726
-TEST_F(JingleSessionTest, FLAKY_TestVideoChannel) {
+TEST_F(JingleSessionTest, TestVideoChannel) {
CreateServerPair();
ASSERT_TRUE(InitiateConnection());
scoped_refptr<TCPChannelTester> tester(
@@ -673,8 +671,7 @@ TEST_F(JingleSessionTest, FLAKY_TestVideoChannel) {
}
// Verify that data can be transmitted over the event channel.
-// TODO(wez): See crbug.com/88726
-TEST_F(JingleSessionTest, FLAKY_TestEventChannel) {
+TEST_F(JingleSessionTest, TestEventChannel) {
CreateServerPair();
ASSERT_TRUE(InitiateConnection());
scoped_refptr<TCPChannelTester> tester(