Bug 1051685: increase SCTP window size from 128K to 1M. r=lgrahl
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Tue, 16 Oct 2018 21:12:34 +0000
changeset 489949 f7d1fd195963da3c729622e97599debeb425c335
parent 489948 ce783284cca7bb33684bf6fbf197387afcd2c3b4
child 489950 d7a0a0e0173e23074808c47db4c9178e8f50708a
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerslgrahl
bugs1051685
milestone64.0a1
Bug 1051685: increase SCTP window size from 128K to 1M. r=lgrahl Differential Revision: https://phabricator.services.mozilla.com/D8906
dom/media/tests/mochitest/dataChannel.js
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_dataChannel_dataOnlyBufferedAmountLow.html
netwerk/sctp/datachannel/DataChannel.cpp
--- a/dom/media/tests/mochitest/dataChannel.js
+++ b/dom/media/tests/mochitest/dataChannel.js
@@ -185,28 +185,27 @@ var commandsCheckDataChannel = [
       is(channels.indexOf(result.channel), channels.length - 1, "Last channel used");
       is(result.data, message, "Received message has the correct content.");
     });
   }
 ];
 
 var commandsCheckLargeXfer = [
   function SEND_BIG_BUFFER(test) {
-    var size = 512*1024; // SCTP internal buffer is 256K, so we'll have ~256K queued
+    var size = 2*1024*1024; // SCTP internal buffer is now 1MB, so use 2MB to ensure the buffer gets full
     var buffer = new ArrayBuffer(size);
     // note: type received is always blob for binary data
     var options = {};
     options.bufferedAmountLowThreshold = 64*1024;
     info("Sending arraybuffer");
     return test.send(buffer, options).then(result => {
       ok(result.data instanceof Blob, "Received data is of instance Blob");
       is(result.data.size, size, "Received data has the correct size.");
     });
   },
 ];
 
 function addInitialDataChannel(chain) {
   chain.insertBefore('PC_LOCAL_CREATE_OFFER', commandsCreateDataChannel);
   chain.insertBefore('PC_LOCAL_WAIT_FOR_MEDIA_FLOW', commandsWaitForDataChannel);
   chain.removeAfter('PC_REMOTE_CHECK_ICE_CONNECTIONS');
-  chain.append(commandsCheckLargeXfer);
   chain.append(commandsCheckDataChannel);
 }
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -35,16 +35,18 @@ skip-if = android_version == '18' # andr
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_basicAudioVideoCombined.html]
 skip-if = toolkit == 'android'  # Bug 1189784
 [test_dataChannel_basicDataOnly.html]
 [test_dataChannel_basicVideo.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_bug1013809.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
+[test_dataChannel_dataOnlyBufferedAmountLow.html]
+skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_noOffer.html]
 [test_enumerateDevices.html]
 [test_enumerateDevices_iframe.html]
 skip-if = true # needed by test_enumerateDevices.html on builders
 [test_enumerateDevices_navigation.html]
 [test_ondevicechange.html]
 skip-if = os == 'android' || verify
 [test_getUserMedia_active_autoplay.html]
copy from dom/media/tests/mochitest/test_dataChannel_basicDataOnly.html
copy to dom/media/tests/mochitest/test_dataChannel_dataOnlyBufferedAmountLow.html
--- a/dom/media/tests/mochitest/test_dataChannel_basicDataOnly.html
+++ b/dom/media/tests/mochitest/test_dataChannel_dataOnlyBufferedAmountLow.html
@@ -2,23 +2,24 @@
 <html>
 <head>
   <script type="application/javascript" src="pc.js"></script>
 </head>
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
-    bug: "796894",
-    title: "Basic datachannel only connection"
+    bug: "1051685",
+    title: "Verify bufferedAmountLowThreshold works"
   });
 
   var test;
   runNetworkTest(function (options) {
     test = new PeerConnectionTest(options);
     addInitialDataChannel(test.chain);
+    test.chain.insertAfter('PC_REMOTE_CHECK_ICE_CONNECTIONS', commandsCheckLargeXfer);
     test.run();
   });
 
 </script>
 </pre>
 </body>
 </html>
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -496,16 +496,29 @@ DataChannelConnection::Init(unsigned sho
 
   // Open sctp with a callback
   if ((mMasterSocket = usrsctp_socket(
          AF_CONN, SOCK_STREAM, IPPROTO_SCTP, receive_cb, threshold_event,
          usrsctp_sysctl_get_sctp_sendspace() / 2, this)) == nullptr) {
     return false;
   }
 
+  int buf_size = 1024 * 1024;
+
+  if (usrsctp_setsockopt(mMasterSocket, SOL_SOCKET, SO_RCVBUF,
+                         (const void *)&buf_size, sizeof(buf_size)) < 0) {
+    LOG(("Couldn't change receive buffer size on SCTP socket"));
+    goto error_cleanup;
+  }
+  if (usrsctp_setsockopt(mMasterSocket, SOL_SOCKET, SO_SNDBUF,
+                         (const void *)&buf_size, sizeof(buf_size)) < 0) {
+    LOG(("Couldn't change send buffer size on SCTP socket"));
+    goto error_cleanup;
+  }
+
   // Make non-blocking for bind/connect.  SCTP over UDP defaults to non-blocking
   // in associations for normal IO
   if (usrsctp_set_non_blocking(mMasterSocket, 1) < 0) {
     LOG(("Couldn't set non_blocking on SCTP socket"));
     // We can't handle connect() safely if it will block, not that this will
     // even happen.
     goto error_cleanup;
   }