what transfer the question is about, but as there is no such pointer provided
to the callback by libcurl itself, applications that want to use
\fIcurl_ws_meta(3)\fP need to pass it on to the callback on its own.
+
+.SH "struct fields"
+.IP age
+This field specify the age of this struct. It is always zero for now.
+.IP recvflags
+This is a bitmask with the exact same meaning as the \fBrecvflags\fP
+documented for \fIcurl_ws_recv(3)\fP.
.SH EXAMPLE
.nf
+/* we pass a pointer to this struct to the callback */
struct customdata {
CURL *easy;
void *ptr;
{
struct customdata custom;
custom.easy = easy;
+ custom.ptr = NULL;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &custom);
}
return result;
}
else {
- /* TODO: store details about the frame in a struct to be reachable with
- curl_ws_meta() from within the write callback */
+ /* Store details about the frame to be reachable with curl_ws_meta()
+ from within the write callback */
+ ws->ws.handout.age = 0;
+ ws->ws.handout.recvflags = recvflags;
/* deliver the decoded frame to the user callback */
if(data->set.fwrite_func((char *)wsp, 1, wslen, writebody_ptr) != wslen)
}
-CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer, size_t buflen,
- size_t *nread, unsigned int *recvflags)
+CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
+ size_t buflen,
+ size_t *nread, unsigned int *recvflags)
{
size_t bytes;
CURLcode result;
return outi;
}
-CURLcode curl_ws_send(struct Curl_easy *data, const void *buffer,
- size_t buflen, size_t *sent,
- unsigned int sendflags)
+CURL_EXTERN CURLcode curl_ws_send(struct Curl_easy *data, const void *buffer,
+ size_t buflen, size_t *sent,
+ unsigned int sendflags)
{
size_t bytes;
CURLcode result;
Curl_dyn_free(&wsp->buf);
}
+CURL_EXTERN struct curl_ws_metadata *curl_ws_meta(struct Curl_easy *data)
+{
+ /* we only return something for websockets, called from within the callback
+ when not using raw mode */
+ if(GOOD_EASY_HANDLE(data) && Curl_is_in_callback(data) && data->req.p.http &&
+ !data->set.ws_raw_mode)
+ return &data->req.p.http->ws.handout;
+ return NULL;
+}
+
#else
CURL_EXTERN CURLcode curl_ws_recv(CURL *curl, void *buffer, size_t buflen,
return CURLE_OK;
}
+CURL_EXTERN struct curl_ws_metadata *curl_ws_meta(struct Curl_easy *data)
+{
+ (void)data;
+ return NULL;
+}
#endif /* USE_WEBSOCKETS */