]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ws: if no connection is around, return error
authorDaniel Stenberg <daniel@haxx.se>
Mon, 12 Dec 2022 12:37:55 +0000 (13:37 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 13 Dec 2022 14:13:03 +0000 (15:13 +0100)
- curl_ws_send returns CURLE_SEND_ERROR if data->conn is gone

- curl_ws_recv returns CURLE_GOT_NOTHING on connection close

- curl_ws_recv.3: mention new return code for connection close + example
  embryo

Closes #10084

docs/libcurl/curl_ws_recv.3
lib/ws.c

index 3cbb5e6f9798f894493067460c87d6cb37b6569c..3fd71c3e7c668c7e1dda1c318af7e4bcc5a2cc2a 100644 (file)
@@ -48,12 +48,17 @@ contains information about the received data. See the \fIcurl_ws_meta(3)\fP
 for details on that struct.
 .SH EXAMPLE
 .nf
-
+  size_t rlen;
+  struct curl_ws_frame *meta;
+  char buffer[256];
+  CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
 .fi
 .SH AVAILABILITY
 Added in 7.86.0.
 .SH RETURN VALUE
-
+Returns \fBCURLE_OK\fP if everything is okay, and a non-zero number for
+errors. Returns \fBCURLE_GOT_NOTHING\fP if the associated connection is
+closed.
 .SH "SEE ALSO"
 .BR curl_easy_setopt "(3), " curl_easy_perform "(3), "
 .BR curl_easy_getinfo "(3), "
index 708504ba62228da429516d7cfc2f091606b87bfc..c1b2622a71c9b31058db8ca2a440ab775428133b 100644 (file)
--- a/lib/ws.c
+++ b/lib/ws.c
@@ -420,8 +420,8 @@ CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
       if(result)
         return result;
       if(!n)
-        /* still have nothing */
-        goto out;
+        /* connection closed */
+        return CURLE_GOT_NOTHING;
       wsp->stillb = data->state.buffer;
       wsp->stillblen = n;
     }
@@ -483,7 +483,6 @@ CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
         wsp->stillb = NULL;
     }
   }
-out:
   *metap = &wsp->frame;
   return CURLE_OK;
 }
@@ -632,9 +631,14 @@ CURL_EXTERN CURLcode curl_ws_send(struct Curl_easy *data, const void *buffer,
       return CURLE_OK;
     /* raw mode sends exactly what was requested, and this is from within
        the write callback */
-    if(Curl_is_in_callback(data))
+    if(Curl_is_in_callback(data)) {
+      if(!data->conn) {
+        failf(data, "No associated connection");
+        return CURLE_SEND_ERROR;
+      }
       result = Curl_write(data, data->conn->writesockfd, buffer, buflen,
                           &written);
+    }
     else
       result = Curl_senddata(data, buffer, buflen, &written);