"use strict";(function(){var e=0;var r=0;var t=false;"use strict";var o=require("tftp");var s=require("util");var i=require("path");var n=require("events");global.Promise=require("bluebird");var l=require("co");var a=require("./Logger").getLogger("rtpsMgr.js");function c(){var e=false;n.EventEmitter.call(this);if(false===this instanceof c){return new c}}s.inherits(c,n.EventEmitter);function u(e,t,o){var s=false;var n=e;var l=n.server;var a={};l.on("error",function(e){if(!s&&e.code=="EADDRINUSE"){s=true;a=e;l.close()}else{console.error("tftp start error",e);n.emit("error",e)}});l.on("close",function(){n._enable=false;if(a.code=="EADDRINUSE"){s=true;o(a)}});l.on("request",function(e,t){console.log("CONNECTION ["+e.stats.remoteAddress+":"+e.stats.remotePort+"] "+e.method+" "+e.file);e.on("error",function(t){n.emit("req_error",e);if(r){console.error("ERROR ["+e.stats.remoteAddress+":"+e.stats.remotePort+"] "+e.method+" "+e.file+" - "+t.message)}});e.on("close",function(){n.emit("req_close",e);if(r){console.log("CLOSE ["+e.stats.remoteAddress+":"+e.stats.remotePort+"] "+e.method+" "+e.file)}})});l.on("listening",function(){n._enable=true;console.log("listening...");if(!s){s=true;o(null,e)}var t={host:this.host,port:this.port,root:i.resolve(this.root)};n.emit("listen",t);if(r){console.log("Listening on "+this.host+":"+this.port+" (root: '"+i.resolve(this.root)+"')")}});l.listen()}c.prototype.start=function(e,r){var t=this;if(e==undefined){e={}}var s=o.createServer(e);t.server=s;return Promise.promisify(u)(t,e).asCallback(r)};c.prototype.close=function(){this.server.close()};c.prototype.enable=function(){return this._enable};module.exports=c;if(e){var f=new c;var v={root:"./",host:"172.24.0.69",port:69};f.start(v);f.on("listen",function(e){console.log("start_listen",e)});setTimeout(function(){f.close()},5e3)}})();