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
This commit is contained in:
Daniel Stenberg 2022-12-12 13:37:55 +01:00
parent 845f020ea5
commit 734c1f8909
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 15 additions and 6 deletions

View 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), "

View File

@ -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);