Skip to content

Commit

Permalink
websocket, feat: close a closed socket not throw error.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed Oct 28, 2017
1 parent 353d9a7 commit e033057
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fibjs/src/websocket/WebSocket.cpp
Expand Up @@ -499,12 +499,12 @@ result_t WebSocket::get_readyState(int32_t& retVal)

result_t WebSocket::close(int32_t code, exlib::string reason)
{
if (m_readyState.CompareAndSwap(ws_base::_OPEN, ws_base::_CLOSING) != ws_base::_OPEN)
return CHECK_ERROR(CALL_E_INVALID_CALL);

if (code != 1000 && (code < 3000 || code > 4999))
return CHECK_ERROR(Runtime::setError("websocket: The code must be either 1000, or between 3000 and 4999."));

if (m_readyState.CompareAndSwap(ws_base::_OPEN, ws_base::_CLOSING) != ws_base::_OPEN)
return 0;

new asyncSend(this, code, reason);
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions test/ws_test.js
Expand Up @@ -519,6 +519,7 @@ describe('ws', () => {
assert.equal(s.readyState, ws.OPEN);

s.close();
s.close();
});

it('send/onmessage', () => {
Expand Down

0 comments on commit e033057

Please sign in to comment.