mirror of
https://github.com/bitinflow/server.git
synced 2026-03-13 13:35:53 +00:00
listen after connecting error handler
This commit is contained in:
24
proxy.js
24
proxy.js
@@ -21,17 +21,6 @@ var Proxy = function(opt, cb) {
|
||||
|
||||
// new tcp server to service requests for this client
|
||||
var client_server = net.createServer();
|
||||
client_server.listen(function() {
|
||||
var port = client_server.address().port;
|
||||
debug('tcp server listening on port: %d', port);
|
||||
|
||||
cb(null, {
|
||||
// port for lt client tcp connections
|
||||
port: port,
|
||||
// maximum number of tcp connections allowed by lt client
|
||||
max_conn_count: max_tcp_sockets
|
||||
});
|
||||
});
|
||||
|
||||
client_server.on('error', function(err) {
|
||||
if (err.code == 'ECONNRESET' || err.code == 'ETIMEDOUT') {
|
||||
@@ -79,7 +68,6 @@ var Proxy = function(opt, cb) {
|
||||
|
||||
// new tcp connection from lt client
|
||||
client_server.on('connection', function(socket) {
|
||||
|
||||
// no more socket connections allowed
|
||||
if (self.sockets.length >= max_tcp_sockets) {
|
||||
return socket.end();
|
||||
@@ -126,6 +114,18 @@ var Proxy = function(opt, cb) {
|
||||
self.next_socket(wait_cb);
|
||||
}
|
||||
});
|
||||
|
||||
client_server.listen(function() {
|
||||
var port = client_server.address().port;
|
||||
debug('tcp server listening on port: %d', port);
|
||||
|
||||
cb(null, {
|
||||
// port for lt client tcp connections
|
||||
port: port,
|
||||
// maximum number of tcp connections allowed by lt client
|
||||
max_conn_count: max_tcp_sockets
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Proxy.prototype.__proto__ = EventEmitter.prototype;
|
||||
|
||||
Reference in New Issue
Block a user