]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ws: unstick connect-only shutdown
authorDaniel Stenberg <daniel@haxx.se>
Mon, 30 Jan 2023 08:35:39 +0000 (09:35 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 30 Jan 2023 14:39:04 +0000 (15:39 +0100)
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

lib/http.c
lib/urldata.h
lib/ws.c
lib/ws.h

index a33251e5d3d1d13e2d75a348a69d53289951a69e..3c1711ab374feaf7fd2570b19576a1e1eafd6fe0 100644 (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 */
index 2dfe196699bd92729b5bd74d0e540ce0185ccfa6..7610b237ae396c7a93802be0ae91913d4bca1492 100644 (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);
index 30b5f19ac2fa9be505a8a024efededef6649c2b6..18d7193862d025d827acaa0f165b343c942bd16d 100644 (file)
--- a/lib/ws.c
+++ b/lib/ws.c
@@ -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
index f07ddb6056b48ea9c03e18dfe14334b3c25a635f..9775a04b9426963744ee3a5368d0dbe93b483255 100644 (file)
--- a/lib/ws.h
+++ b/lib/ws.h
@@ -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