Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
domain: use AsyncListener API
Browse files Browse the repository at this point in the history
The domain module has been switched over to use the domain module API as
much as currently possible. There are still some hooks in the
EventEmitter, but hopefully we can remove those in the future.
  • Loading branch information
trevnorris committed Oct 31, 2013
1 parent fbe7eec commit bc39bdd
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 603 deletions.
63 changes: 35 additions & 28 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,38 +417,45 @@ function responseOnEnd() {
}
}

function tickOnSocket(req, socket) {
var parser = parsers.alloc();
req.socket = socket;
req.connection = socket;
parser.reinitialize(HTTPParser.RESPONSE);
parser.socket = socket;
parser.incoming = null;
req.parser = parser;

socket.parser = parser;
socket._httpMessage = req;

// Setup "drain" propogation.
httpSocketSetup(socket);

// Propagate headers limit from request object to parser
if (util.isNumber(req.maxHeadersCount)) {
parser.maxHeaderPairs = req.maxHeadersCount << 1;
} else {
// Set default value because parser may be reused from FreeList
parser.maxHeaderPairs = 2000;
}

parser.onIncoming = parserOnIncomingClient;
socket.on('error', socketErrorListener);
socket.on('data', socketOnData);
socket.on('end', socketOnEnd);
socket.on('close', socketCloseListener);
req.emit('socket', socket);
}

ClientRequest.prototype.onSocket = function(socket) {
var req = this;

process.nextTick(function() {
var parser = parsers.alloc();
req.socket = socket;
req.connection = socket;
parser.reinitialize(HTTPParser.RESPONSE);
parser.socket = socket;
parser.incoming = null;
req.parser = parser;

socket.parser = parser;
socket._httpMessage = req;

// Setup "drain" propogation.
httpSocketSetup(socket);

// Propagate headers limit from request object to parser
if (util.isNumber(req.maxHeadersCount)) {
parser.maxHeaderPairs = req.maxHeadersCount << 1;
} else {
// Set default value because parser may be reused from FreeList
parser.maxHeaderPairs = 2000;
}

parser.onIncoming = parserOnIncomingClient;
socket.on('error', socketErrorListener);
socket.on('data', socketOnData);
socket.on('end', socketOnEnd);
socket.on('close', socketCloseListener);
req.emit('socket', socket);
// If a domain was added to the request, attach it to the socket.
if (req.domain)
socket._handle.addAsyncListener(req.domain._listener);
tickOnSocket(req, socket);
});

};
Expand Down
Loading

2 comments on commit bc39bdd

@mscdex
Copy link

@mscdex mscdex commented on bc39bdd Nov 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/domain module API/AsyncListener API/

:-)

@tjfontaine
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, that ship done sailed :)

Please sign in to comment.