curl_ws_meta(3)
π NAME π
okay so bestie, this is the curl_ws_meta(3) page from the Library Functions Manual β it's literally curl_ws_meta for meta data WebSocket information. No cap, this is the one that hands you the tea about the current WebSocket frame. π
β¨ SYNOPSIS β¨
#include <curl/curl.h>
const struct curl_ws_frame *curl_ws_meta(CURL *curl);
π¦ DESCRIPTION π¦
When the write callback (CURLOPT_WRITEFUNCTION(3)) is invoked on received WebSocket traffic, curl_ws_meta(3) can be called from inside the callback to give you extra information about the current frame. β¨
bestie, listen: this function only works from within the callback, and only when receiving WebSocket data. That's the vibe check. π«Ά
This function requires an easy handle as its input argument so libcurl knows which transfer you're asking about, but since libcurl itself does not provide such a pointer to the callback, applications that want to use curl_ws_meta(3) need to pass it on to the callback on their own. Yes, you gotta hand-deliver the easy handle. iconic, honestly. π
π§ struct curl_ws_frame π§
struct curl_ws_frame {
int age;
int flags;
curl_off_t offset;
curl_off_t bytesleft;
size_t len;
};
ageβ this field specifies the age of this struct. It is always zero for now. πflagsβ this is a bitmask with individual bits set that describes the WebSocket data. See the list below. πoffsetβ when this chunk is a continuation of frame data already delivered, this is the offset into the final frame data where this piece belongs. π§©bytesleftβ if this is not a complete fragment, thebytesleftfield tells you how many additional bytes are expected to arrive before this fragment is complete. β³lenβ the length of the current data chunk. π
π₯ FLAGS π₯
The message type flags (CURLWS_TEXT/BINARY/CLOSE/PING/PONG) are mutually exclusive. pick one, bestie β no combo meals. π
CURLWS_TEXTβ this is a message with text data. Note that this makes a difference to WebSocket but libcurl itself does not make any verification of the content or precautions that you actually receive valid UTF-8 content. πCURLWS_BINARYβ this is a message with binary data. π€CURLWS_CLOSEβ this is a close message. No more data follows. βοΈ- It may contain a 2-byte unsigned integer in network byte order that indicates the close reason and may additionally contain up to 123 bytes of further textual payload for a total of at most 125 bytes. libcurl does not verify that the textual description is valid UTF-8. π’
CURLWS_PINGβ this is a ping message. It may contain up to 125 bytes of payload text. libcurl does not verify that the payload is valid UTF-8. π- Upon receiving a ping message, libcurl automatically responds with a pong message unless the
CURLWS_NOAUTOPONGorCURLWS_RAW_MODEbit ofCURLOPT_WS_OPTIONS(3)is set. π€
- Upon receiving a ping message, libcurl automatically responds with a pong message unless the
CURLWS_PONGβ this is a pong message. It may contain up to 125 bytes of payload text. libcurl does not verify that the payload is valid UTF-8. πΈCURLWS_CONTβ can only occur in conjunction withCURLWS_TEXTorCURLWS_BINARY. π§΅- This is not the final fragment of the message, it implies that there is another fragment coming as part of the same message. The application must reassemble the fragments to receive the complete message. π§©
- Only a single fragmented message can be transmitted at a time, but it may be interrupted by
CURLWS_CLOSE,CURLWS_PINGorCURLWS_PONGframes. β‘
π PROTOCOLS π
This functionality affects ws only. that's it, that's the protocol. π«
π EXAMPLE π
/* we pass a pointer to this struct to the callback */
struct customdata {
CURL *easy;
void *ptr;
};
static size_t writecb(char *buffer, size_t size, size_t nitems, void *p)
{
struct customdata *c = (struct customdata *)p;
const struct curl_ws_frame *m = curl_ws_meta(c->easy);
printf("flags: %x\n", m->flags);
return 0;
}
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
struct customdata custom;
custom.easy = curl;
custom.ptr = NULL;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &custom);
curl_easy_perform(curl);
}
return 0;
}
β AVAILABILITY β
Added in curl 7.86.0. yes bestie, exact version. π
π RETURN VALUE π
This function returns a pointer to a curl_ws_frame struct with read-only information that is valid for this specific callback invocation. If it cannot return this information, or if the function is called in the wrong context, it returns NULL. π no info, no pointer, periodt. π
π SEE ALSO π
mwah π β this sassy lil page comes from libcurl, dated 2026-10-12, and the manual name is curl_ws_meta(3) πβ¨
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms