Skip to content

Commit

Permalink
Drop packets when io pending is received for UDP sockets.
Browse files Browse the repository at this point in the history
On Windows UDP sockets will return a WOULDBLOCK but a writeable
notification will never happen in libjingle code. When we receive
such error in the glue code we should report a success and drop
the packets.

BUG=None
TEST=Connect to a windows box to itself, network will be alright.

Review URL: http://codereview.chromium.org/7380003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94281 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hclam@chromium.org committed Jul 27, 2011
1 parent aeebebb commit 87185ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 8 additions & 4 deletions jingle/glue/channel_socket_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,18 @@ int TransportChannelSocketAdapter::Write(
int result;
if (channel_->writable()) {
result = channel_->SendPacket(buffer->data(), buffer_size);
if (result < 0)
if (result < 0) {
result = net::MapSystemError(channel_->GetError());

// If the underlying socket returns IO pending where it shouldn't we
// pretend the packet is dropped and return as succeeded because no
// writeable callback will happen.
if (result == net::ERR_IO_PENDING)
result = net::OK;
}
} else {
// Channel is not writable yet.
result = net::ERR_IO_PENDING;
}

if (result == net::ERR_IO_PENDING) {
write_callback_ = callback;
write_buffer_ = buffer;
write_buffer_size_ = buffer_size;
Expand Down
14 changes: 5 additions & 9 deletions jingle/glue/channel_socket_adapter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,20 @@ TEST_F(TransportChannelSocketAdapterTest, Write) {
EXPECT_EQ(kTestDataSize, result);
}

// Verify that the message is still send if Write() is called while
// socket is not open yet, and that the callback is called.
// Verify that the message is still sent if Write() is called while
// socket is not open yet. The result is the packet is lost.
TEST_F(TransportChannelSocketAdapterTest, WritePending) {
scoped_refptr<IOBuffer> buffer(new IOBuffer(kTestDataSize));

EXPECT_CALL(channel_, SendPacket(buffer->data(), kTestDataSize))
.Times(2)
.WillOnce(Return(SOCKET_ERROR))
.WillOnce(Return(kTestDataSize));
.Times(1)
.WillOnce(Return(SOCKET_ERROR));

EXPECT_CALL(channel_, GetError())
.WillOnce(Return(EWOULDBLOCK));

int result = target_->Write(buffer, kTestDataSize, &callback_);
ASSERT_EQ(net::ERR_IO_PENDING, result);

channel_.SignalWritableState(&channel_);
EXPECT_EQ(kTestDataSize, callback_result_);
ASSERT_EQ(net::OK, result);
}

} // namespace jingle_glue

0 comments on commit 87185ec

Please sign in to comment.