Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redable stream 'end' event emitting and object lost on net socket. #106

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/iotjs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ namespace iotjs {

static bool InitJerry() {

uint32_t jerry_flag = JERRY_FLAG_ABORT_ON_FAIL;

#ifdef ENABLE_JERRY_MEM_STATS
jerry_init(JERRY_FLAG_MEM_STATS | JERRY_FLAG_SHOW_OPCODES);
#else
jerry_init(JERRY_FLAG_EMPTY);
jerry_flag |= JERRY_FLAG_MEM_STATS;
jerry_flag |= JERRY_FLAG_SHOW_OPCODES;
#endif

jerry_init(jerry_flag);

InitJerryMagicStringEx();

if (!jerry_parse("", 0)) {
Expand Down
9 changes: 9 additions & 0 deletions src/js/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ Socket.prototype._onread = function(nread, isEOF, buffer) {

Socket.prototype._onclose = function() {
this.emit('close');

if (this.server) {
var sockets = this.server._sockets;
var idx = sockets.indexOf(this);
delete sockets[idx];
}
};


Expand Down Expand Up @@ -258,6 +264,7 @@ function Server(options, connectionListener) {
}

this._handle = null;
this._sockets = [];
}

// Server inherits EventEmitter.
Expand Down Expand Up @@ -359,6 +366,8 @@ Server.prototype._onconnection = function(status, clientHandle) {
socket.server = this;
onSocketConnect(socket);

this._sockets.push(socket);

this.emit('connection', socket);
};

Expand Down
11 changes: 5 additions & 6 deletions src/js/stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ function emitEnd(stream) {

if (!state.endEmitted) {
state.endEmitted = true;
process.nextTick(function(){
stream.emit('end');
})
stream.emit('end');
}
};

Expand All @@ -223,10 +221,11 @@ function emitError(stream, er) {
function onEof(stream) {
var state = stream._readableState;

if (state.ended) {
return;
}
state.ended = true;

if (state.length == 0) {
emitEnd(stream);
}
};


Expand Down
8 changes: 6 additions & 2 deletions test/run_pass/test_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ readable.on('data', function(data) {
d += data.toString();
});

readable.on('end', function() {
e += 'e';
});


readable.pause();
readable.push('abcde');
Expand Down Expand Up @@ -66,8 +70,8 @@ assert.equal(e, '');

readable.push(null);
assert.equal(d, 'abcde12345a1b2c3d4');
assert.equal(e, '');
assert.equal(e, 'e');

readable.push('push after eof');
assert.equal(d, 'abcde12345a1b2c3d4');
assert.equal(e, '.');
assert.equal(e, 'e.');