From 734c1f8909d75549a36c604796098cd117826e06 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 12 Dec 2022 13:37:55 +0100 Subject: ws: if no connection is around, return error - 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 --- lib/ws.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/ws.c') diff --git a/lib/ws.c b/lib/ws.c index 708504ba6..c1b2622a7 100644 --- 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); -- cgit v1.2.1