Permalink
Browse files

websocket, feat: close a closed socket not throw error.

  • Loading branch information...
xicilion committed Oct 28, 2017
1 parent 353d9a7 commit e033057f5c4678d949bfec977de1819ff57b6535
Showing with 4 additions and 3 deletions.
  1. +3 −3 fibjs/src/websocket/WebSocket.cpp
  2. +1 −0 test/ws_test.js
@@ -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;
}
View
@@ -519,6 +519,7 @@ describe('ws', () => {
assert.equal(s.readyState, ws.OPEN);
s.close();
s.close();
});
it('send/onmessage', () => {

0 comments on commit e033057

Please sign in to comment.