netwerk/test/unit/test_addr_in_use_error.js

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     1 // Opening a second listening socket on the same address as an extant
     2 // socket should elicit NS_ERROR_SOCKET_ADDRESS_IN_USE on non-Windows
     3 // machines.
     5 const CC = Components.Constructor;
     7 const ServerSocket = CC("@mozilla.org/network/server-socket;1",
     8                         "nsIServerSocket",
     9                         "init");
    11 function testAddrInUse()
    12 {
    13   // Windows lets us have as many sockets listening on the same address as
    14   // we like, evidently.
    15   if ("@mozilla.org/windows-registry-key;1" in Cc) {
    16     return;
    17   }
    19   // Create listening socket:
    20   // any port (-1), loopback only (true), default backlog (-1)
    21   let listener = ServerSocket(-1, true, -1);
    22   do_check_true(listener instanceof Ci.nsIServerSocket);
    24   // Try to create another listening socket on the same port, whatever that was.
    25   do_check_throws_nsIException(() => ServerSocket(listener.port, true, -1),
    26                                "NS_ERROR_SOCKET_ADDRESS_IN_USE");
    27 }
    29 function run_test()
    30 {
    31   testAddrInUse();
    32 }

mercurial