ws: unstick connect-only shutdown

As this mode uses blocking sockets, it must set them back to
non-blocking in disconnect to avoid the risk of getting stuck.

Closes #10366
This commit is contained in:
Daniel Stenberg 2023-01-30 09:35:39 +01:00
parent 097544959a
commit 4c48fb4933
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
4 changed files with 18 additions and 4 deletions

View File

@ -151,7 +151,7 @@ const struct Curl_handler Curl_handler_ws = {
http_getsock_do, /* doing_getsock */
ZERO_NULL, /* domore_getsock */
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
Curl_ws_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
@ -205,7 +205,7 @@ const struct Curl_handler Curl_handler_wss = {
http_getsock_do, /* doing_getsock */
ZERO_NULL, /* domore_getsock */
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
Curl_ws_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */

View File

@ -765,8 +765,8 @@ struct Curl_handler {
/* This function *MAY* be set to a protocol-dependent function that is run
* by the curl_disconnect(), as a step in the disconnection. If the handler
* is called because the connection has been considered dead,
* dead_connection is set to TRUE. The connection is already disassociated
* from the transfer here.
* dead_connection is set to TRUE. The connection is (again) associated with
* the transfer here.
*/
CURLcode (*disconnect)(struct Curl_easy *, struct connectdata *,
bool dead_connection);

View File

@ -710,6 +710,17 @@ void Curl_ws_done(struct Curl_easy *data)
Curl_dyn_free(&wsp->buf);
}
CURLcode Curl_ws_disconnect(struct Curl_easy *data,
struct connectdata *conn,
bool dead_connection)
{
(void)data;
(void)dead_connection;
/* make sure this is non-blocking to avoid getting stuck in shutdown */
(void)curlx_nonblock(conn->sock[FIRSTSOCKET], TRUE);
return CURLE_OK;
}
CURL_EXTERN struct curl_ws_frame *curl_ws_meta(struct Curl_easy *data)
{
/* we only return something for websocket, called from within the callback

View File

@ -60,6 +60,9 @@ CURLcode Curl_ws_accept(struct Curl_easy *data);
size_t Curl_ws_writecb(char *buffer, size_t size, size_t nitems, void *userp);
void Curl_ws_done(struct Curl_easy *data);
CURLcode Curl_ws_disconnect(struct Curl_easy *data,
struct connectdata *conn,
bool dead_connection);
#else
#define Curl_ws_request(x,y) CURLE_OK