Commit b5316535 authored by deuce's avatar deuce
Browse files

Since we're supporting TLS now, use the sock.recv() timeout parameter instead

of poll()ing for each byte.
parent 60c5adda
...@@ -948,50 +948,16 @@ BinkP.prototype.recvFrame = function(timeout) ...@@ -948,50 +948,16 @@ BinkP.prototype.recvFrame = function(timeout)
if (this.partialFrame === undefined) { if (this.partialFrame === undefined) {
ret = new this.Frame(); ret = new this.Frame();
switch(this.sock.poll(timeout)) { buf = this.sock.recv(1, timeout);
case 0: // Timeout
if (timeout) {
log(LOG_WARNING, "Timed out receiving packet header!");
this.sock.close();
this.sock = undefined;
return undefined;
}
return null;
default:
log(LOG_ERROR, "Error select()ing socket.");
this.sock.close();
this.sock = undefined;
return undefined;
case 1:
break;
}
buf = this.sock.recv(1);
if (buf === null || buf.length !== 1) { if (buf === null || buf.length !== 1) {
log(LOG_INFO, "Remote disconnected"); log(LOG_INFO, "Error in recv() timeout or disconnect");
this.sock.close(); this.sock.close();
this.sock = undefined; this.sock = undefined;
return undefined; return undefined;
} }
switch(this.sock.poll(timeout)) { buf += this.sock.recv(1, timeout);
case 0: // Timeout
if (timeout) {
log(LOG_WARNING, "Timed out receiving second byte of packet header!");
this.sock.close();
this.sock = undefined;
return undefined;
}
return null;
default:
log(LOG_ERROR, "Error select()ing socket.");
this.sock.close();
this.sock = undefined;
return undefined;
case 1:
break;
}
buf += this.sock.recv(1);
if (buf.length !== 2) { if (buf.length !== 2) {
log(LOG_ERROR, "Remote disconnected before sending second byte of packet header!"); log(LOG_ERROR, "Remote disconnected or timed out before sending second byte of packet header!");
this.sock.close(); this.sock.close();
this.sock = undefined; this.sock = undefined;
return undefined; return undefined;
...@@ -1005,34 +971,14 @@ BinkP.prototype.recvFrame = function(timeout) ...@@ -1005,34 +971,14 @@ BinkP.prototype.recvFrame = function(timeout)
else else
ret = this.partialFrame; ret = this.partialFrame;
switch(this.sock.poll(timeout)) { i = this.recv_buf(this.sock.recv(ret.length - ret.data.length));
case 1: if (i == null || i.length == 0) {
avail = this.sock.nread; log(LOG_ERROR, "Remote disconnected or timed out while receiving packet data!");
if (avail == 0) { this.sock.close();
if (this.sock.is_connected) this.sock = undefined;
log(LOG_ERROR, "Poll returned data available, but no data available on connected socket!"); return undefined;
this.sock.close();
this.sock = undefined;
return undefined;
}
if (avail > (ret.length - ret.data.length))
avail = ret.length - ret.data.length;
ret.data += this.recv_buf(this.sock.recv(avail));
break;
case 0:
if (timeout) {
log(LOG_ERROR, "Timed out receiving packet data!");
this.sock.close();
this.sock = undefined;
return undefined;
}
break;
default:
log(LOG_ERROR, "Error select()ing socket.");
this.sock.close();
this.sock = undefined;
return undefined;
} }
ret.data += i;
if (ret.data.length < ret.length) if (ret.data.length < ret.length)
this.partialFrame = ret; this.partialFrame = ret;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment