Bug 960296 - Update buffered stun socket size when flushes happen. r=abr, a=bajaj
authorEKR <ekr@rtfm.com>
Thu, 16 Jan 2014 08:29:00 -0800
changeset 176017 ddb0773a7ce8a80297a8f65b084f18a28f974ede
parent 176016 824b7285697d84535ced3d8339531d5323f596ac
child 176018 20e10d9d645f776ff11c268fd70b9b0826191b5d
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersabr, bajaj
bugs960296
milestone28.0a2
Bug 960296 - Update buffered stun socket size when flushes happen. r=abr, a=bajaj
media/mtransport/test/buffered_stun_socket_unittest.cpp
media/mtransport/third_party/nICEr/src/stun/nr_socket_buffered_stun.c
--- a/media/mtransport/test/buffered_stun_socket_unittest.cpp
+++ b/media/mtransport/test/buffered_stun_socket_unittest.cpp
@@ -269,16 +269,49 @@ TEST_F(BufferedStunSocketTest, TestSendT
 
   dummy_->CheckWriteBuffer(nullptr, 0);
 
   dummy_->SetWritable(kStunMessageLen);
   dummy_->FireWritableCb();
   dummy_->CheckWriteBuffer(kStunMessage, kStunMessageLen);
 }
 
+TEST_F(BufferedStunSocketTest, TestSendFullThenDrain) {
+  dummy_->SetWritable(0);
+
+  for (;;) {
+    int r = nr_socket_sendto(test_socket_,
+                             kStunMessage,
+                             kStunMessageLen,
+                             0, &remote_addr_);
+    if (r == R_WOULDBLOCK)
+      break;
+
+    ASSERT_EQ(0, r);
+  }
+
+  // Nothing was written.
+  dummy_->CheckWriteBuffer(nullptr, 0);
+
+  // Now flush.
+  dummy_->SetWritable(kStunMessageLen);
+  dummy_->FireWritableCb();
+  dummy_->ClearWriteBuffer();
+
+  // Verify we can write something.
+  int r = nr_socket_sendto(test_socket_,
+                             kStunMessage,
+                             kStunMessageLen,
+                             0, &remote_addr_);
+  ASSERT_EQ(0, r);
+
+  // And that it appears.
+  dummy_->CheckWriteBuffer(kStunMessage, kStunMessageLen);
+}
+
 TEST_F(BufferedStunSocketTest, TestSendToPartialBuffered) {
   dummy_->SetWritable(10);
 
   int r = nr_socket_sendto(test_socket_,
                            kStunMessage,
                            kStunMessageLen,
                            0, &remote_addr_);
   ASSERT_EQ(0, r);
--- a/media/mtransport/third_party/nICEr/src/stun/nr_socket_buffered_stun.c
+++ b/media/mtransport/third_party/nICEr/src/stun/nr_socket_buffered_stun.c
@@ -372,24 +372,28 @@ static void nr_socket_buffered_stun_writ
     if ((r=nr_socket_write(sock->inner, n1->data + n1->r_offset,
                            n1->length - n1->r_offset,
                            &written, 0))) {
 
       ABORT(r);
     }
 
     n1->r_offset += written;
+    assert(sock->pending >= written);
+    sock->pending -= written;
+
     if (n1->r_offset < n1->length) {
       /* We wrote something, but not everything */
       ABORT(R_WOULDBLOCK);
     }
 
     /* We are done with this p_buf */
     STAILQ_REMOVE_HEAD(&sock->pending_writes, entry);
     nr_p_buf_free(sock->p_bufs, n1);
   }
 
+  assert(!sock->pending);
   _status=0;
 abort:
   if (_status && _status != R_WOULDBLOCK) {
     /* TODO(ekr@rtfm.com): Mark the socket as failed */
   }
 }