Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(914)

Unified Diff: net/base/tcp_listen_socket_unittest.cc

Issue 10389007: Change TCPListenSocket::SendInternal to use a non-blocking implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« net/base/tcp_listen_socket.cc ('K') | « net/base/tcp_listen_socket_unittest.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/tcp_listen_socket_unittest.cc
===================================================================
--- net/base/tcp_listen_socket_unittest.cc (revision 135347)
+++ net/base/tcp_listen_socket_unittest.cc (working copy)
@@ -119,10 +119,9 @@
void TCPListenSocketTester::Listen() {
server_ = DoListen();
- if (server_) {
- server_->AddRef();
- ReportAction(TCPListenSocketTestAction(ACTION_LISTEN));
- }
+ ASSERT_TRUE(server_);
+ server_->AddRef();
+ ReportAction(TCPListenSocketTestAction(ACTION_LISTEN));
}
void TCPListenSocketTester::SendFromTester() {
@@ -179,6 +178,38 @@
ASSERT_STREQ(buf, kHelloWorld);
}
+void TCPListenSocketTester::TestServerSendMultiple() {
+ // Send enough data to exceed the socket receive window. 20kb is probably a
+ // safe bet.
+ int send_count = (1024*20) / (sizeof(kHelloWorld)-1);
+ int i;
+
+ // Send multiple writes. Since no reading is occuring the data should be
+ // buffered in TCPListenSocket.
+ for (i = 0; i < send_count; ++i) {
+ loop_->PostTask(FROM_HERE, base::Bind(
+ &TCPListenSocketTester::SendFromTester, this));
+ NextAction();
+ ASSERT_EQ(ACTION_SEND, last_action_.type());
+ }
+
+ // Make multiple reads. All of the data should eventually be returned.
+ char buf[sizeof(kHelloWorld)];
+ const int buf_len = sizeof(kHelloWorld);
+ for (i = 0; i < send_count; ++i) {
+ unsigned recv_len = 0;
+ do {
+ int r = HANDLE_EINTR(recv(test_socket_, buf, buf_len-1, 0));
mmenke 2012/05/09 19:20:08 Looks to me like we never enter the message loop h
michaeln 2012/05/09 20:55:34 A separate thread is running the listener-side of
mmenke 2012/05/09 21:08:21 Ahh, thanks! I didn't even notice. So used to se
+ ASSERT_GE(r, 0);
+ recv_len += static_cast<unsigned>(r);
+ if (!r)
+ break;
+ } while (recv_len < buf_len-1);
+ buf[recv_len] = 0;
+ ASSERT_STREQ(buf, kHelloWorld);
+ }
+}
+
bool TCPListenSocketTester::Send(SOCKET sock, const std::string& str) {
int len = static_cast<int>(str.length());
int send_len = HANDLE_EINTR(send(sock, str.data(), len, 0));
@@ -248,4 +279,8 @@
tester_->TestServerSend();
}
+TEST_F(TCPListenSocketTest, ServerSendMultiple) {
+ tester_->TestServerSendMultiple();
+}
+
} // namespace net
« net/base/tcp_listen_socket.cc ('K') | « net/base/tcp_listen_socket_unittest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698