summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
e7d6adb)
If a connection fails, we get back the resultCode, but we never actually
check it. That means we lie to the higher layers and say we're connected
when we're not really.
Also pass that code to the higher levels if they've requested notification.
*/
TcpClient.prototype.disconnect = function() {
socket.disconnect(this.socketId);
*/
TcpClient.prototype.disconnect = function() {
socket.disconnect(this.socketId);
- clearInterval(this.pollerId);
- this.pollerId = null;
- this.isConnected = false;
+ if (this.isConnected) {
+ clearInterval(this.pollerId);
+ this.pollerId = null;
+ this.isConnected = false;
+ }
this.socketId = createInfo.socketId;
if (this.socketId > 0) {
socket.connect(this.socketId, this.host, this.port, this._onConnectComplete.bind(this));
this.socketId = createInfo.socketId;
if (this.socketId > 0) {
socket.connect(this.socketId, this.host, this.port, this._onConnectComplete.bind(this));
- this.isConnected = true;
} else {
error('Unable to create socket');
}
} else {
error('Unable to create socket');
}
* @param {Number} resultCode Indicates whether the connection was successful
*/
TcpClient.prototype._onConnectComplete = function(resultCode) {
* @param {Number} resultCode Indicates whether the connection was successful
*/
TcpClient.prototype._onConnectComplete = function(resultCode) {
+ log('resultCode: ' + resultCode);
+
+ // XXX: Can this ever be positive ?
+ this.isConnected = (resultCode >= 0);
+
// Start polling for reads.
clearInterval(this.pollerId);
// Start polling for reads.
clearInterval(this.pollerId);
- this.pollerId = setInterval(this.poll.bind(this), 500);
+ if (this.isConnected) {
+ this.pollerId = setInterval(this.poll.bind(this), 500);
+ }
if (this.callbacks.connect) {
log('connect complete');
if (this.callbacks.connect) {
log('connect complete');
- this.callbacks.connect();
+ this.callbacks.connect(resultCode);
}
log('onConnectComplete');
};
}
log('onConnectComplete');
};
* Wrapper function for logging
*/
function log(msg) {
* Wrapper function for logging
*/
function log(msg) {
- //console.log('tcp-client: ', msg);
+ //console.log('tcp-client:', msg);
}
/**
* Wrapper function for error logging
*/
function error(msg) {
}
/**
* Wrapper function for error logging
*/
function error(msg) {
- console.error('tcp-client: ', msg);
+ console.error('tcp-client:', msg);
}
exports.TcpClient = TcpClient;
}
exports.TcpClient = TcpClient;