www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 59fe54da0177ef6a77581dcaa16d8d0c98c8a736
parent 90d57c4afef625dbcad4d9b6ee038cccfe71e1d4
Author: Aurimas Vinckevicius <aurimas.dev@gmail.com>
Date:   Tue,  3 Jun 2014 01:45:03 -0500

Release server port when shutting down (e.g. switching to Connector mode)

Diffstat:
Mchrome/content/zotero/xpcom/server.js | 21+++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/chrome/content/zotero/xpcom/server.js b/chrome/content/zotero/xpcom/server.js @@ -24,7 +24,7 @@ */ Zotero.Server = new function() { - var _onlineObserverRegistered; + var _onlineObserverRegistered, serv; this.responseCodes = { 200:"OK", 201:"Created", @@ -47,8 +47,13 @@ Zotero.Server = new function() { return; } + if(serv) { + Zotero.debug("Already listening on port " + serv.port); + return; + } + // start listening on socket - var serv = Components.classes["@mozilla.org/network/server-socket;1"] + serv = Components.classes["@mozilla.org/network/server-socket;1"] .createInstance(Components.interfaces.nsIServerSocket); try { // bind to a random port on loopback only @@ -56,14 +61,26 @@ Zotero.Server = new function() { serv.asyncListen(Zotero.Server.SocketListener); Zotero.debug("HTTP server listening on "+(bindAllAddr ? "*": " 127.0.0.1")+":"+serv.port); + + Zotero.addShutdownListener(this.close.bind(this)); } catch(e) { Zotero.debug("Not initializing HTTP server"); + serv = undefined; } _registerOnlineObserver() } /** + * releases bound port + */ + this.close = function() { + if(!serv) return; + serv.close(); + serv = undefined; + }; + + /** * Parses a query string into a key => value object * @param {String} queryString Query string */