Clarify on_error/on_close behavior
Async client/server
on_error calls if there some error befor ws handshake done (IO error/SSL handshake/Invalid token/ protocol) . And in this case on_close did not call.
on_close calls if ws handshake done. In case of IO error we call on_close with (false, 1001, "Going away"). And in this caseon_error` did not call.
Is it correct behavior?
I think on_close should be called when the client will not be able to work with the ws any more.
You raised one good question: If the connection has never been open, should on_close and on_error be called anyways?
I tend to call on_close and on_error also when the connection failed. This would make async error handling easier.
BTW: on_error should always be calls before on_close. (This is how node.js does it with sockets).
May be we should call on_close only if there was on_open event.
And call on_error on any errors.
But there may be cases when other side just close connection and in this case may be we shuld just call on_close with status 1001?
ok, agree.