Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixed unset consumer; fixed connection logic
  • Loading branch information
dvv committed Jun 10, 2011
commit afe0a50e58a48654e1414d168fb96c72b26be466
2 changes: 1 addition & 1 deletion lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ Manager.prototype.handleClient = function (data, req) {
if (count == 1) {
// initialize the socket for all namespaces
for (var i in self.namespaces) {
self.namespaces[i].socket(data.id, true);
self.handlePacket(data.id, {type: 'connect'});
}

// handle packets for the client (all namespaces)
Expand Down
7 changes: 2 additions & 5 deletions lib/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ SocketNamespace.prototype.emit = function (name) {
SocketNamespace.prototype.socket = function (sid, readable) {
if (!this.sockets[sid]) {
this.sockets[sid] = new Socket(this.manager, sid, this, readable);
if (this.name === '') {
this.emit('connection', this.sockets[sid]);
}
}

return this.sockets[sid];
Expand All @@ -200,7 +197,7 @@ SocketNamespace.prototype.socket = function (sid, readable) {
*/

SocketNamespace.prototype.handlePacket = function (sessid, packet) {
var socket = this.socket(sessid)
var socket = this.socket(sessid, true) // readable
Copy link
Contributor

Choose a reason for hiding this comment

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

When the packet is handled, the socket should have already been initialized in a readable state. What's the need for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the call to SocketNamespace#socket is moved to manager and done with explicit true, no need remains.

, dataAck = packet.ack == 'data'
, self = this;

Expand All @@ -216,7 +213,7 @@ SocketNamespace.prototype.handlePacket = function (sessid, packet) {
switch (packet.type) {
case 'connect':
this.store.join(sessid, this.name, function () {
self.emit('connection', self.sockets[sessid]);
self.emit('connection', socket);
});
break;

Expand Down
2 changes: 0 additions & 2 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ Socket.prototype.$emit = EventEmitter.prototype.emit;
*/

Socket.prototype.emit = function (ev) {
console.log('DVV:Socket#emit?', arguments);
if (events[ev]) {
return this.$emit.apply(this, arguments);
}
Expand All @@ -304,6 +303,5 @@ console.log('DVV:Socket#emit?', arguments);

packet.args = args;

console.log('DVV:Socket#emit', packet);
return this.packet(packet);
};
5 changes: 2 additions & 3 deletions lib/stores/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,12 @@ Client.prototype.count = function (fn) {
*/

Client.prototype.consume = function (fn) {
this.consumer = fn;
this.paused = false;

if (this.buffer.length) {
fn(this.buffer, null);
this.buffer = [];
} else {
this.consumer = fn;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This was probably creating problems in certain circumstances. However, it never came up with our test suite. Any chance you can create a test to avoid a regression for this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, still can't run tests -- they just timeout, because of ECONNREFUSED, because of client should connect to server only when server is bound for real. Mac has magical kernel, it listen()s synchronously, PC's doesn't ;)

update:
Client#consume is called only once. If it happens that client is paused at that moment, the value of consumer function is lost forever. This occurs (to me) if i sent back a packet during connection event, say.
I can't formalize it so far to constitute a test, but since the logic of this.consumer assignment is conditional, it surely will fail (and fails) under some conditions.


return this;
Expand All @@ -283,7 +282,7 @@ Client.prototype.consume = function (fn) {
*/

Client.prototype.publish = function (msg) {
if (this.paused || !this.consumer) {
if (this.paused) {
this.buffer.push(msg);
} else {
this.consumer(null, msg);
Expand Down
16 changes: 8 additions & 8 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ Transport.prototype.setHeartbeatTimeout = function () {
var self = this;

this.heartbeatTimeout = setTimeout(function () {
self.log.debug('fired heartbeat timeout for client', self.id);
//DVV self.log.debug('fired heartbeat timeout for client', self.id);
self.heartbeatTimeout = null;
self.end(false, 'heartbeat timeout');
}, this.manager.get('heartbeat timeout') * 1000);

this.log.debug('set heartbeat timeout for client', this.id);
//DVV this.log.debug('set heartbeat timeout for client', this.id);
}
};

Expand All @@ -238,7 +238,7 @@ Transport.prototype.clearHeartbeatTimeout = function () {
if (this.heartbeatTimeout) {
clearTimeout(this.heartbeatTimeout);
this.heartbeatTimeout = null;
this.log.debug('cleared heartbeat timeout for client', this.id);
//DVV this.log.debug('cleared heartbeat timeout for client', this.id);
}
};

Expand All @@ -257,7 +257,7 @@ Transport.prototype.setHeartbeatInterval = function () {
self.heartbeat();
}, this.manager.get('heartbeat interval') * 1000);

this.log.debug('set heartbeat interval for client', this.id);
//DVV this.log.debug('set heartbeat interval for client', this.id);
}
};

Expand All @@ -281,7 +281,7 @@ Transport.prototype.clearTimeouts = function () {

Transport.prototype.heartbeat = function () {
if (this.open) {
this.log.debug('emitting heartbeat for client', this.id);
//DVV this.log.debug('emitting heartbeat for client', this.id);
this.packet({ type: 'heartbeat' });
this.setHeartbeatTimeout();
}
Expand All @@ -298,10 +298,10 @@ Transport.prototype.heartbeat = function () {

Transport.prototype.onMessage = function (packet) {
if ('heartbeat' == packet.type) {
this.log.debug('got heartbeat packet');
//DVV this.log.debug('got heartbeat packet');
this.store.heartbeat(this.id);
} else if ('disconnect' == packet.type && packet.endpoint == '') {
this.log.debug('got disconnection packet');
//DVV this.log.debug('got disconnection packet');
this.store.disconnect(this.id, true);
} else {
this.log.debug('got packet');
Expand Down Expand Up @@ -329,7 +329,7 @@ Transport.prototype.clearHeartbeatInterval = function () {
if (this.heartbeatInterval) {
clearTimeout(this.heartbeatInterval);
this.heartbeatInterval = null;
this.log.debug('cleared heartbeat interval for client', this.id);
//DVV this.log.debug('cleared heartbeat interval for client', this.id);
}
};

Expand Down