Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
src.emit('data', chunk);
// if anyone needs a drain, then we have to wait for that.
if (state.awaitDrain > 0)
return;
}
// if every destination was unpiped, either before entering this
// function, or in the while loop, then stop flowing.
//
// NB: This is a pretty rare edge case.
if (state.pipesCount === 0) {
state.flowing = false;
// if there were data event listeners added, then switch to old mode.
if (EE.listenerCount(src, 'data') > 0)
emitDataEvents(src);
return;
}
// at this point, no one needed a drain, so we just ran out of data
// on the next readable event, start it over again.
state.ranOut = true;
}
function readAll() {
// Try to read an item while there are still data listeners
var item;
while (EventEmitter.listenerCount(self, 'data') !== 0 &&
(item = self.read()) !== null)
self.emit('data', item);
// Detach the listener if nobody is listening anymore
if (EventEmitter.listenerCount(self, 'data') === 0) {
self.removeListener('readable', readAll);
self.removeListener('newListener', waitForDataListener); // A listener could already be attached
self.addListener('newListener', waitForDataListener);
}
}
this.removeListener('readable', readAll); // A listener could already be attached
req._hadError = true;
} else if (parser.incoming && parser.incoming.upgrade) {
// Upgrade or CONNECT
var bytesParsed = ret;
var res = parser.incoming;
req.res = res;
socket.ondata = null;
socket.onend = null;
parser.finish();
// This is start + byteParsed
var bodyHead = d.slice(start + bytesParsed, end);
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
if (EventEmitter.listenerCount(req, eventName) > 0) {
req.upgradeOrConnect = true;
// detach the socket
socket.emit('agentRemove');
socket.removeListener('close', socketCloseListener);
socket.removeListener('error', socketErrorListener);
req.emit(eventName, res, socket, bodyHead);
req.emit('close');
} else {
// Got Upgrade header or CONNECT method, but have no handler.
socket.destroy();
}
freeParser(parser, req);
} else if (parser.incoming && parser.incoming.complete &&
// When the status code is 100 (Continue), the server will
if (r) emitKeys(stream, r);
} else {
// Nobody's watching anyway
stream.removeListener('data', onData);
stream.on('newListener', onNewListener);
}
}
function onNewListener(event) {
if (event == 'keypress') {
stream.on('data', onData);
stream.removeListener('newListener', onNewListener);
}
}
if (EventEmitter.listenerCount(stream, 'keypress') > 0) {
stream.on('data', onData);
} else {
stream.on('newListener', onNewListener);
}
}
exports.emitKeypressEvents = emitKeypressEvents;
function onerror(er) {
cleanup();
if (EE.listenerCount(this, 'error') === 0) {
throw er; // Unhandled stream error in pipe.
}
}
if (r) emitKeys(stream, r);
} else {
// Nobody's watching anyway
stream.removeListener('data', onData);
stream.on('newListener', onNewListener);
}
}
function onNewListener(event) {
if (event == 'keypress') {
stream.on('data', onData);
stream.removeListener('newListener', onNewListener);
}
}
if (EventEmitter.listenerCount(stream, 'keypress') > 0) {
stream.on('data', onData);
} else {
stream.on('newListener', onNewListener);
}
}
exports.emitKeypressEvents = emitKeypressEvents;
httpClient.request(opts, null, function(error, resp){
var token = JSON.parse(resp.body).token;
assert.ok(token, "Token exists");
var socket = new TokenSocket();
tokenServer.socketServer._connection(socket);
assert.property(socket, "sid", "Socket as UUID");
assert.property(socket, "created", "Server tracks socket created timestamp");
assert.isObject(socket.channels, "Socket tracks channels");
assert.notOk(socket.auth, "Socket does not start in auth state");
assert.lengthOf(Object.keys(tokenServer._sockets), 1, "Server has one connected socket");
assert.equal(EventEmitter.listenerCount(socket._emitter, "data"), 1, "Socket on data has one listener");
assert.equal(EventEmitter.listenerCount(socket._emitter, "close"), 1, "Socket on close has one listener");
socket._emit("close");
assert.lengthOf(Object.keys(tokenServer._sockets), 0, "Server ends with zero connected sockets");
done();
});
});
Log.prototype.trace = function (method, requestUrl, body, responseBody, responseStatus) {
if (EventEmitter.listenerCount(this, 'trace')) {
if (typeof requestUrl === 'object') {
requestUrl = _.formatUrl(requestUrl);
}
return this.emit('trace', method, requestUrl, body, responseBody, responseStatus);
}
};
function _cleanupWaiter() {
clearTimeout(timeout);
stateReporter.removeListener(state, _gotState);
log.trace({
count: EventEmitter.listenerCount(stateReporter, state),
state: state,
vmUuid: vmUuid
}, 'stateReporter listeners after cleanup');
}
return function() {
var state = src._readableState;
debug('pipeOnDrain', state.awaitDrain);
if (state.awaitDrain)
state.awaitDrain--;
if (state.awaitDrain === 0 && EE.listenerCount(src, 'data')) {
state.flowing = true;
flow(src);
}
};
}