Thu, 15 Jan 2015 21:03:48 +0100
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.)
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 }