michael@0: // Opening a second listening socket on the same address as an extant michael@0: // socket should elicit NS_ERROR_SOCKET_ADDRESS_IN_USE on non-Windows michael@0: // machines. michael@0: michael@0: const CC = Components.Constructor; michael@0: michael@0: const ServerSocket = CC("@mozilla.org/network/server-socket;1", michael@0: "nsIServerSocket", michael@0: "init"); michael@0: michael@0: function testAddrInUse() michael@0: { michael@0: // Windows lets us have as many sockets listening on the same address as michael@0: // we like, evidently. michael@0: if ("@mozilla.org/windows-registry-key;1" in Cc) { michael@0: return; michael@0: } michael@0: michael@0: // Create listening socket: michael@0: // any port (-1), loopback only (true), default backlog (-1) michael@0: let listener = ServerSocket(-1, true, -1); michael@0: do_check_true(listener instanceof Ci.nsIServerSocket); michael@0: michael@0: // Try to create another listening socket on the same port, whatever that was. michael@0: do_check_throws_nsIException(() => ServerSocket(listener.port, true, -1), michael@0: "NS_ERROR_SOCKET_ADDRESS_IN_USE"); michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: testAddrInUse(); michael@0: }