Permalink
Browse files

Emit 'end' and 'close' events only when main connection closes

  • Loading branch information...
1 parent 2af0833 commit aac8d5a7d5a1109f3347c099b185bbac3ff11200 @unkernet unkernet committed with Nov 29, 2011
Showing with 6 additions and 4 deletions.
  1. +6 −4 oscar.js
View
@@ -788,10 +788,11 @@ function end_handler(oscar) {
var self = oscar, conn = this;
conn.isConnected = false;
if (!conn.isTransferring) {
- if (conn === self._state.connections.main)
+ if (conn === self._state.connections.main) {
self._resetState();
+ self.emit('end');
+ }
debug('(' + conn.remoteAddress + ') [' + getConnSvcNames(conn) + '] FIN packet received. Disconnecting...');
- self.emit('end');
}
}
@@ -810,10 +811,11 @@ function close_handler(oscar, had_error) {
var self = oscar, conn = this;
conn.isConnected = false;
if (!conn.isTransferring || had_error) {
- if (conn === self._state.connections.main)
+ if (conn === self._state.connections.main) {
self._resetState();
+ self.emit('close', had_error);
+ }
debug('(' + conn.remoteAddress + ') [' + getConnSvcNames(conn) + '] Connection forcefully closed.');
- self.emit('close', had_error);
}
}

0 comments on commit aac8d5a

Please sign in to comment.