Skip to content

Commit

Permalink
fix js client ping/pong dead loop
Browse files Browse the repository at this point in the history
  • Loading branch information
lesismal committed Oct 6, 2023
1 parent 6439d2c commit 9b56db4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
9 changes: 6 additions & 3 deletions examples/httprpc/arpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
if (this._keepaliveInited) return;
this._keepaliveInited = true;
if (!timeout) timeout = 1000 * 30;
setInterval(this.ping, timeout);
this.keepaliveIntervalID = setInterval(this.ping, timeout);
}

this.write = function(cmd, method, arg, cb, isHttp) {
Expand Down Expand Up @@ -190,6 +190,9 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
this.shutdown = function() {
this.ws.close();
this.state = _SOCK_STATE_CLOSED;
if (!!this.keepaliveIntervalID) {
clearInterval(this.keepaliveIntervalID);
}
}

this.request = function(data, cb) {
Expand Down Expand Up @@ -246,9 +249,9 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
switch (cmd) {
case _CmdPing:
client.pong();
continue;
return;
case _CmdPong:
continue;
return;
}

if (methodLen == 0) {
Expand Down
9 changes: 6 additions & 3 deletions examples/protocols/websocket/jsclient/arpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
if (this._keepaliveInited) return;
this._keepaliveInited = true;
if (!timeout) timeout = 1000 * 30;
setInterval(this.ping, timeout);
this.keepaliveIntervalID = setInterval(this.ping, timeout);
}

this.write = function(cmd, method, arg, cb, isHttp) {
Expand Down Expand Up @@ -190,6 +190,9 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
this.shutdown = function() {
this.ws.close();
this.state = _SOCK_STATE_CLOSED;
if (!!this.keepaliveIntervalID) {
clearInterval(this.keepaliveIntervalID);
}
}

this.request = function(data, cb) {
Expand Down Expand Up @@ -246,9 +249,9 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
switch (cmd) {
case _CmdPing:
client.pong();
continue;
return;
case _CmdPong:
continue;
return;
}

if (methodLen == 0) {
Expand Down
9 changes: 6 additions & 3 deletions examples/webchat/arpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
if (this._keepaliveInited) return;
this._keepaliveInited = true;
if (!timeout) timeout = 1000 * 30;
setInterval(this.ping, timeout);
this.keepaliveIntervalID = setInterval(this.ping, timeout);
}

this.write = function(cmd, method, arg, cb, isHttp) {
Expand Down Expand Up @@ -190,6 +190,9 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
this.shutdown = function() {
this.ws.close();
this.state = _SOCK_STATE_CLOSED;
if (!!this.keepaliveIntervalID) {
clearInterval(this.keepaliveIntervalID);
}
}

this.request = function(data, cb) {
Expand Down Expand Up @@ -246,9 +249,9 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
switch (cmd) {
case _CmdPing:
client.pong();
continue;
return;
case _CmdPong:
continue;
return;
}

if (methodLen == 0) {
Expand Down
9 changes: 6 additions & 3 deletions extension/jsclient/arpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
if (this._keepaliveInited) return;
this._keepaliveInited = true;
if (!timeout) timeout = 1000 * 30;
setInterval(this.ping, timeout);
this.keepaliveIntervalID = setInterval(this.ping, timeout);
}

this.write = function(cmd, method, arg, cb, isHttp) {
Expand Down Expand Up @@ -190,6 +190,9 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
this.shutdown = function() {
this.ws.close();
this.state = _SOCK_STATE_CLOSED;
if (!!this.keepaliveIntervalID) {
clearInterval(this.keepaliveIntervalID);
}
}

this.request = function(data, cb) {
Expand Down Expand Up @@ -246,9 +249,9 @@ function ArpcClient(url, codec, httpUrl, httpMethod) {
switch (cmd) {
case _CmdPing:
client.pong();
continue;
return;
case _CmdPong:
continue;
return;
}

if (methodLen == 0) {
Expand Down

0 comments on commit 9b56db4

Please sign in to comment.