Skip to content
Snippets Groups Projects
Commit c0d715ac authored by deuce's avatar deuce
Browse files

Log when connect() fails.

Make timeouts at different points in the protocol use different log messages.
When a frame is sent, use a single send() call to avoid small packets on the
wire.
parent 43303df2
No related branches found
No related tags found
No related merge requests found
...@@ -238,6 +238,7 @@ BinkP.prototype.connect = function(addr, password, auth_cb, port) ...@@ -238,6 +238,7 @@ BinkP.prototype.connect = function(addr, password, auth_cb, port)
if(!this.sock.connect(addr.inet_host, port)) { if(!this.sock.connect(addr.inet_host, port)) {
this.sock = undefined; this.sock = undefined;
log(LOG_INFO, "Connection to "+addr.inet_host+":"+port+" failed.");
return false; return false;
} }
...@@ -447,7 +448,7 @@ BinkP.prototype.session = function() ...@@ -447,7 +448,7 @@ BinkP.prototype.session = function()
case this.command.M_GOT: case this.command.M_GOT:
args = this.parseArgs(pkt.data); args = this.parseArgs(pkt.data);
for (i=0; i<this.pending_ack.length; i++) { for (i=0; i<this.pending_ack.length; i++) {
if (this.pending_ack[i].sendas == args[0]) { if (this.pending_ack[i].sendas === args[0]) {
this.sent_files.push(this.pending_ack[i].file.name); this.sent_files.push(this.pending_ack[i].file.name);
if (this.tx_callback !== undefined) if (this.tx_callback !== undefined)
this.tx_callback(this.pending_ack[i], this); this.tx_callback(this.pending_ack[i], this);
...@@ -597,11 +598,8 @@ BinkP.prototype.sendCmd = function(cmd, data) ...@@ -597,11 +598,8 @@ BinkP.prototype.sendCmd = function(cmd, data)
} }
var len = data.length+1; var len = data.length+1;
len |= 0x8000; len |= 0x8000;
if (!this.sock.sendBin(len, 2)) // We'll send it all in one go to avoid sending small packets...
return false; if (!this.sock.send(ascii((len & 0xff00)>>8) + ascii(len & 0xff) + ascii(cmd) + data))
if (!this.sock.sendBin(cmd, 1))
return false;
if (!this.sock.send(data))
return false; return false;
switch(cmd) { switch(cmd) {
case this.command.M_EOB: case this.command.M_EOB:
...@@ -630,9 +628,8 @@ BinkP.prototype.sendData = function(data) ...@@ -630,9 +628,8 @@ BinkP.prototype.sendData = function(data)
return false; return false;
if (this.debug) if (this.debug)
log(LOG_DEBUG, "Sending "+data.length+" bytes of data"); log(LOG_DEBUG, "Sending "+data.length+" bytes of data");
if (!this.sock.sendBin(len, 2)) // We'll send it all in one go to avoid sending small packets...
return false; if (!this.sock.send(ascii((len & 0xff00)>>8) + ascii(len & 0xff) + data))
if (!this.sock.send(data))
return false; return false;
return true; return true;
}; };
...@@ -667,7 +664,7 @@ BinkP.prototype.recvFrame = function(timeout) ...@@ -667,7 +664,7 @@ BinkP.prototype.recvFrame = function(timeout)
switch(this.sock.poll(timeout)) { switch(this.sock.poll(timeout)) {
case 0: // Timeout case 0: // Timeout
if (timeout) { if (timeout) {
log(LOG_ERROR, "Timed out receiving packet!"); log(LOG_ERROR, "Timed out receiving packet header!");
this.sock.close(); this.sock.close();
this.sock = undefined; this.sock = undefined;
return undefined; return undefined;
...@@ -705,7 +702,7 @@ BinkP.prototype.recvFrame = function(timeout) ...@@ -705,7 +702,7 @@ BinkP.prototype.recvFrame = function(timeout)
break; break;
case 0: case 0:
if (timeout) { if (timeout) {
log(LOG_ERROR, "Timed out receiving packet!"); log(LOG_ERROR, "Timed out receiving packet data!");
this.sock.close(); this.sock.close();
this.sock = undefined; this.sock = undefined;
return undefined; return undefined;
...@@ -840,4 +837,5 @@ BinkP.prototype.addFile = function(path, sendas) ...@@ -840,4 +837,5 @@ BinkP.prototype.addFile = function(path, sendas)
if (this.debug) if (this.debug)
log(LOG_DEBUG, "Adding '"+path+"' as '"+sendas+"'"); log(LOG_DEBUG, "Adding '"+path+"' as '"+sendas+"'");
this.tx_queue.push({file:file, sendas:sendas}); this.tx_queue.push({file:file, sendas:sendas});
return true;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment