From b261389dbad6d96c193f6885b216e358905b3ecc Mon Sep 17 00:00:00 2001 From: Paul Seligman Date: Fri, 7 Oct 2022 07:52:31 -0400 Subject: ws: minor fixes for web sockets without the CONNECT_ONLY flag - Fixed an issue where is_in_callback was getting cleared when using web sockets with debug logging enabled - Ensure the handle is is_in_callback when calling out to fwrite_func - Change the write vs. send_data decision to whether or not the handle is in CONNECT_ONLY mode. - Account for buflen not including the header length in curl_ws_send Closes #9665 --- lib/ws.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/ws.c') diff --git a/lib/ws.c b/lib/ws.c index dbe8788da..cfd267ee2 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -334,6 +334,7 @@ size_t Curl_ws_writecb(char *buffer, size_t size /* 1 */, else if(nitems) { unsigned char *frame = NULL; size_t flen = 0; + size_t wrote = 0; CURLcode result; unsigned char *endp; curl_off_t oleft; @@ -383,7 +384,10 @@ size_t Curl_ws_writecb(char *buffer, size_t size /* 1 */, } else { /* deliver the decoded frame to the user callback */ - if(data->set.fwrite_func((char *)frame, 1, flen, writebody_ptr) != flen) + Curl_set_in_callback(data, true); + wrote = data->set.fwrite_func((char *)frame, 1, flen, writebody_ptr); + Curl_set_in_callback(data, false); + if(wrote != flen) return 0; } if(oleft) @@ -681,12 +685,13 @@ CURL_EXTERN CURLcode curl_ws_send(struct Curl_easy *data, const void *buffer, out = data->state.ulbuf; if(buflen) /* for PING and PONG etc there might not be a payload */ - ws_xor(data, buffer, (unsigned char *)out + headlen, buflen - headlen); - if(Curl_is_in_callback(data)) + ws_xor(data, buffer, (unsigned char *)out + headlen, buflen); + + if(data->set.connect_only) + result = Curl_senddata(data, out, buflen + headlen, &written); + else result = Curl_write(data, data->conn->writesockfd, out, buflen + headlen, &written); - else - result = Curl_senddata(data, out, buflen + headlen, &written); infof(data, "WS: wanted to send %zu bytes, sent %zu bytes", headlen + buflen, written); -- cgit v1.2.1