|
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. |
|
4 |
|
5 const CC = Components.Constructor; |
|
6 |
|
7 const ServerSocket = CC("@mozilla.org/network/server-socket;1", |
|
8 "nsIServerSocket", |
|
9 "init"); |
|
10 |
|
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 } |
|
18 |
|
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); |
|
23 |
|
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 } |
|
28 |
|
29 function run_test() |
|
30 { |
|
31 testAddrInUse(); |
|
32 } |