Node.js: added async request execution.
This commit is contained in:
@@ -232,7 +232,6 @@ ServerResponse.prototype.write = function write(chunk, encoding, callback) {
|
||||
|
||||
ServerResponse.prototype.end = function end(chunk, encoding, callback) {
|
||||
this._writeBody(chunk, encoding, callback);
|
||||
unit_lib.unit_response_end(this)
|
||||
|
||||
this.finished = true;
|
||||
|
||||
@@ -290,10 +289,10 @@ function Server(requestListener) {
|
||||
EventEmitter.call(this);
|
||||
|
||||
this.unit = new unit_lib.Unit();
|
||||
this.unit.createServer();
|
||||
|
||||
this.unit.server = this;
|
||||
|
||||
this.unit.createServer();
|
||||
|
||||
this.socket = Socket;
|
||||
this.request = ServerRequest;
|
||||
this.response = ServerResponse;
|
||||
@@ -318,10 +317,32 @@ Server.prototype.listen = function () {
|
||||
this.unit.listen();
|
||||
};
|
||||
|
||||
Server.prototype.run_events = function (server, req, res) {
|
||||
/* Important!!! setImmediate starts the next iteration in Node.js loop. */
|
||||
setImmediate(function () {
|
||||
server.emit("request", req, res);
|
||||
|
||||
Promise.resolve().then(() => {
|
||||
let buf = server.unit._read(req.socket.req_pointer);
|
||||
|
||||
if (buf.length != 0) {
|
||||
req.emit("data", buf);
|
||||
}
|
||||
|
||||
req.emit("end");
|
||||
});
|
||||
|
||||
Promise.resolve().then(() => {
|
||||
if (res.finished) {
|
||||
unit_lib.unit_response_end(res);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function connectionListener(socket) {
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
STATUS_CODES: http.STATUS_CODES,
|
||||
Server,
|
||||
|
||||
Reference in New Issue
Block a user