diff --git a/support/aphlict/server/aphlict_server.js b/support/aphlict/server/aphlict_server.js index ef85c6fcfe..82cec664a2 100644 --- a/support/aphlict/server/aphlict_server.js +++ b/support/aphlict/server/aphlict_server.js @@ -12,17 +12,6 @@ JX.require('lib/AphlictFlashPolicyServer', __dirname); JX.require('lib/AphlictListenerList', __dirname); JX.require('lib/AphlictLog', __dirname); -var debug = new JX.AphlictLog() - .addConsole(console); - -var clients = new JX.AphlictListenerList(); - -var config = parse_command_line_arguments(process.argv); - -if (config.logfile) { - debug.addLogfile(config.logfile); -} - function parse_command_line_arguments(argv) { var config = { port: 22280, @@ -50,6 +39,17 @@ function parse_command_line_arguments(argv) { return config; } +var debug = new JX.AphlictLog() + .addConsole(console); + +var clients = new JX.AphlictListenerList(); + +var config = parse_command_line_arguments(process.argv); + +if (config.logfile) { + debug.addLogfile(config.logfile); +} + if (process.getuid() !== 0) { console.log( "ERROR: " + @@ -161,6 +161,26 @@ var messages_out = 0; var messages_in = 0; var start_time = new Date().getTime(); +function transmit(msg) { + var listeners = clients.getListeners().filter(function(client) { + return client.isSubscribedToAny(msg.subscribers); + }); + + for (var i = 0; i < listeners.length; i++) { + var listener = listeners[i]; + + try { + listener.writeMessage(msg); + + ++messages_out; + debug.log('<%s> Wrote Message', listener.getDescription()); + } catch (error) { + clients.removeListener(listener); + debug.log('<%s> Write Error: %s', listener.getDescription(), error); + } + } +} + http.createServer(function(request, response) { // Publishing a notification. if (request.url == '/') { @@ -233,26 +253,6 @@ http.createServer(function(request, response) { } }).listen(config.admin, config.host); -function transmit(msg) { - var listeners = clients.getListeners().filter(function(client) { - return client.isSubscribedToAny(msg.subscribers); - }); - - for (var i = 0; i < listeners.length; i++) { - var listener = listeners[i]; - - try { - listener.writeMessage(msg); - - ++messages_out; - debug.log('<%s> Wrote Message', listener.getDescription()); - } catch (error) { - clients.removeListener(listener); - debug.log('<%s> Write Error: %s', listener.getDescription(), error); - } - } -} - // If we're configured to drop permissions, get rid of them now that we've // bound to the ports we need and opened logfiles. if (config.user) {