EarthScope / ringserver

Apache License 2.0
30 stars 16 forks source link

close websocket properly even on error #39

Open crotwell opened 1 year ago

crotwell commented 1 year ago

If a websocket datalink client sends a command that results in an error, a ERROR datalink packet is sent back with a reason, which is helpful. But the ringserver also closes the connection without going through the websocket close handshake, ie sending a CLOSE frame and waiting for the corresponding CLOSE response.

In clients.c about line 404 there is code to close the regular socket:

  /* Close client socket */
  if (cinfo->socket)
  {
    shutdown (cinfo->socket, SHUT_RDWR);
    close (cinfo->socket);
    cinfo->socket = 0;
  }

but as far as I can see no corresponding code to close a websocket nicely. It would be nice if the websocket could be closed gracefully even in the case of errors.

Docs on CLOSE are here: https://www.rfc-editor.org/rfc/rfc6455#section-5.5.1