netwerk/test/unit/test_addr_in_use_error.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial