mirror of
https://github.com/curl/curl.git
synced 2024-11-21 01:16:58 +08:00
e3f335148a
curl_ws_recv() now receives data to fill up the provided buffer, but can return a partial fragment. The function now also get a pointer to a curl_ws_frame struct with metadata that also mentions the offset and total size of the fragment (of which you might be receiving a smaller piece). This way, large incoming fragments will be "streamed" to the application. When the curl_ws_frame struct field 'bytesleft' is 0, the final fragment piece has been delivered. curl_ws_recv() was also adjusted to work with a buffer size smaller than the fragment size. (Possibly needless to say as the fragment size can now be 63 bit large). curl_ws_send() now supports sending a piece of a fragment, in a streaming manner, in addition to sending the entire fragment in a single call if it is small enough. To send a huge fragment, curl_ws_send() can be used to send it in many small calls by first telling libcurl about the total expected fragment size, and then send the payload in N number of separate invokes and libcurl will stream those over the wire. The struct curl_ws_meta() returns is now called 'curl_ws_frame' and it has been extended with two new fields: *offset* and *bytesleft*. To help describe the passed on data chunk when a fragment is delivered in many smaller pieces. The documentation has been updated accordingly. Closes #9636
70 lines
2.6 KiB
C
70 lines
2.6 KiB
C
#ifndef HEADER_CURL_WS_H
|
|
#define HEADER_CURL_WS_H
|
|
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
#include "curl_setup.h"
|
|
|
|
#ifdef USE_WEBSOCKETS
|
|
|
|
#ifdef USE_HYPER
|
|
#define REQTYPE void
|
|
#else
|
|
#define REQTYPE struct dynbuf
|
|
#endif
|
|
|
|
/* this is the largest single fragment size we support */
|
|
#define MAX_WS_SIZE 65535
|
|
|
|
/* part of 'struct HTTP', when used in the 'struct SingleRequest' in the
|
|
Curl_easy struct */
|
|
struct websocket {
|
|
bool contfragment; /* set TRUE if the previous fragment sent was not final */
|
|
unsigned char mask[4]; /* 32 bit mask for this connection */
|
|
struct Curl_easy *data; /* used for write callback handling */
|
|
struct dynbuf buf;
|
|
size_t usedbuf; /* number of leading bytes in 'buf' the most recent complete
|
|
websocket frame uses */
|
|
struct curl_ws_frame frame; /* the struct used for frame state */
|
|
curl_off_t oleft; /* outstanding number of payload bytes left from the
|
|
server */
|
|
curl_off_t stillbuffer; /* number of bytes left in the buffer to deliver in
|
|
the next curl_ws_recv() call */
|
|
char *stillb; /* the stillbuffer pending bytes are here */
|
|
curl_off_t sleft; /* outstanding number of payload bytes left to send */
|
|
unsigned int xori; /* xor index */
|
|
};
|
|
|
|
CURLcode Curl_ws_request(struct Curl_easy *data, REQTYPE *req);
|
|
CURLcode Curl_ws_accept(struct Curl_easy *data);
|
|
|
|
size_t Curl_ws_writecb(char *buffer, size_t size, size_t nitems, void *userp);
|
|
void Curl_ws_done(struct Curl_easy *data);
|
|
|
|
#else
|
|
#define Curl_ws_request(x,y) CURLE_OK
|
|
#define Curl_ws_done(x) Curl_nop_stmt
|
|
#endif
|
|
|
|
#endif /* HEADER_CURL_WS_H */
|