summaryrefslogtreecommitdiff
path: root/lib/ws.c
diff options
context:
space:
mode:
authorPaul Seligman <pseligman@apple.com>2022-10-07 07:52:31 -0400
committerDaniel Stenberg <daniel@haxx.se>2022-10-09 23:09:58 +0200
commitb261389dbad6d96c193f6885b216e358905b3ecc (patch)
tree0907ad8d4cce4fb792c381794eaa90837125792a /lib/ws.c
parentd905de276911ee5b0dae3feab9793dcb811cf30d (diff)
downloadcurl-b261389dbad6d96c193f6885b216e358905b3ecc.tar.gz
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
Diffstat (limited to 'lib/ws.c')
-rw-r--r--lib/ws.c15
1 files changed, 10 insertions, 5 deletions
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);