Permalink
Browse files

Merge "Merge branch '0.3.x' of ssh://pomelo.163.com:29418/pomelo into…

… 0.3.x"
  • Loading branch information...
Charlie Edward Gerrit Code Review
Charlie Edward authored and Gerrit Code Review committed Jan 22, 2013
2 parents 9a4dd40 + 9d55f53 commit 9b0b268cca648c71a6595ff4117f90b77bc50807
Showing with 15 additions and 14 deletions.
  1. +2 −2 lib/connectors/hybi/tcpsocket.js
  2. +3 −3 lib/connectors/hybiconnector.js
  3. +10 −9 lib/connectors/hybisocket.js
@@ -57,8 +57,8 @@ var Socket = function(socket, opts) {
util.inherits(Socket, Stream);
Socket.prototype.send = function() {
this._socket.write.apply(this._socket, arguments);
Socket.prototype.send = function(msg) {
this._socket.write(msg);
};
Socket.prototype.close = function() {
@@ -44,13 +44,13 @@ Connector.prototype.start = function() {
var hybisocket = new HybiSocket(curId++, socket);
hybisocket.on('handshake',
self.handshake.handle.bind(self.handshake, socket));
self.handshake.handle.bind(self.handshake, hybisocket));
hybisocket.on('heartbeat',
self.heartbeat.handle.bind(self.heartbeat, socket));
self.heartbeat.handle.bind(self.heartbeat, hybisocket));
hybisocket.on('disconnect',
self.hearbeat.clear.bind(self.hearbeat, socket.id));
self.hearbeat.clear.bind(self.hearbeat, hybisocket.id));
self.emit('connection', hybisocket);
});
@@ -11,8 +11,9 @@ var ST_CLOSED = 3;
* Package types
*/
var PKG_HANDSHAKE = 1; // handshake package
var PKG_HEARTBEAT = 2; // heartbeat package
var PKG_DATA = 3; // data package
var PKG_HANDSHAKE_ACK = 2; // handshake ack package
var PKG_HEARTBEAT = 3; // heartbeat package
var PKG_DATA = 4; // data package
/**
* Socket class that wraps socket and websocket to provide unified interface for up level.
@@ -51,7 +52,7 @@ Socket.prototype.send = function(msg) {
if(this.state !== ST_WORKING) {
return;
}
this.socket.send(msg);
this.socket.send(msg, {binary: true});
};
/**
@@ -63,7 +64,7 @@ Socket.prototype.sendForce = function(msg) {
if(this.state === ST_CLOSED) {
return;
}
this.socket.send(msg);
this.socket.send(msg, {binary: true});
};
/**
@@ -112,8 +113,8 @@ var handleData = function(socket, msg) {
socket.emit('message', msg.buffer);
};
var handlers = {
PKG_HANDSHAKE: handleHandshake,
PKG_HEARTBEAT: handleHeartbeat,
PKG_DATA: handleData
};
var handlers = {};
handlers[PKG_HANDSHAKE] = handleHandshake;
handlers[PKG_HANDSHAKE_ACK] = handleHandshakeAck;
handlers[PKG_HEARTBEAT] = handleHeartbeat;
handlers[PKG_DATA] = handleData;

0 comments on commit 9b0b268

Please sign in to comment.