AsyncTCPSocket: try sending outgoing data until EWOULDBLOCK
The AsyncTCPSocket is an AsyncPacketSocket which means it
emulates UDP-like (packet) semantics via a TCP stream. When
sending, if the entire packet could not be written then the
packet socket should indicate it wrote the whole thing and
flush out the remaining later when the socket is available.
The WriteEvent signal was already wired up but was not getting
fired (at least with the virtual sockets) since it would not
call Send() enough on the underlying socket to get an
EWOULDBLOCK that would register the async event.
This changes AsyncTCPSocket to repeatedly call Send() on the
underlying socket until the entire packet has been written
or EWOULDBLOCK was returned.
Bug: webrtc:6655
Change-Id: I41e81e0c106c9b3e712a8a0f792d28745d93f2d2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168083
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30449}
diff --git a/p2p/base/async_stun_tcp_socket_unittest.cc b/p2p/base/async_stun_tcp_socket_unittest.cc
index 4f693a5..d1dfac1 100644
--- a/p2p/base/async_stun_tcp_socket_unittest.cc
+++ b/p2p/base/async_stun_tcp_socket_unittest.cc
@@ -106,10 +106,10 @@
bool Send(const void* data, size_t len) {
rtc::PacketOptions options;
- size_t ret =
+ int ret =
send_socket_->Send(reinterpret_cast<const char*>(data), len, options);
vss_->ProcessMessagesUntilIdle();
- return (ret == len);
+ return (ret == static_cast<int>(len));
}
bool CheckData(const void* data, int len) {
@@ -224,10 +224,6 @@
// Verifying a legal large turn message.
TEST_F(AsyncStunTCPSocketTest, TestMaximumSizeTurnPacket) {
- // We have problem in getting the SignalWriteEvent from the virtual socket
- // server. So increasing the send buffer to 64k.
- // TODO(mallinath) - Remove this setting after we fix vss issue.
- vss_->set_send_buffer_capacity(64 * 1024);
unsigned char packet[65539];
packet[0] = 0x40;
packet[1] = 0x00;
@@ -238,10 +234,6 @@
// Verifying a legal large stun message.
TEST_F(AsyncStunTCPSocketTest, TestMaximumSizeStunPacket) {
- // We have problem in getting the SignalWriteEvent from the virtual socket
- // server. So increasing the send buffer to 64k.
- // TODO(mallinath) - Remove this setting after we fix vss issue.
- vss_->set_send_buffer_capacity(64 * 1024);
unsigned char packet[65552];
packet[0] = 0x00;
packet[1] = 0x01;
@@ -250,8 +242,9 @@
EXPECT_TRUE(Send(packet, sizeof(packet)));
}
-// Investigate why WriteEvent is not signaled from VSS.
-TEST_F(AsyncStunTCPSocketTest, DISABLED_TestWithSmallSendBuffer) {
+// Test that a turn message is sent completely even if it exceeds the socket
+// send buffer capacity.
+TEST_F(AsyncStunTCPSocketTest, TestWithSmallSendBuffer) {
vss_->set_send_buffer_capacity(1);
Send(kTurnChannelDataMessageWithOddLength,
sizeof(kTurnChannelDataMessageWithOddLength));