Artifactspublic-v0

curl

master
ply4 git calls291 ms288 KiB2 cachedprotocol v2
106 lines3.2 KiBRaw

NAME

curl_easy_recv - receives raw data on an "easy" connection

SYNOPSIS

c
#include <curl/curl.h>

CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, size_t *n);

DESCRIPTION

This function receives raw data from the established connection. You may use it together with curl_easy_send(3) to implement custom protocols using libcurl. This functionality can be particularly useful if you use proxies and/or SSL encryption: libcurl takes care of proxy negotiation and connection setup.

buffer is a pointer to your buffer memory that gets populated by the received data. buflen is the maximum amount of data you can get in that buffer. The variable n points to receives the number of received bytes.

To establish the connection, set CURLOPT_CONNECT_ONLY(3) option before calling curl_easy_perform(3) or curl_multi_perform(3). Note that curl_easy_recv(3) does not work on connections that were created without this option.

The call returns CURLE_AGAIN if there is no data to read - the socket is used in non-blocking mode internally. When CURLE_AGAIN is returned, use your operating system facilities like select(2) to wait for data. The socket may be obtained using curl_easy_getinfo(3) with CURLINFO_ACTIVESOCKET(3).

Wait on the socket only if curl_easy_recv(3) returns CURLE_AGAIN. The reason for this is libcurl or the SSL library may internally cache some data, therefore you should call curl_easy_recv(3) until all data is read which would include any cached data.

Furthermore if you wait on the socket and it tells you there is data to read, curl_easy_recv(3) may return CURLE_AGAIN if the only data that was read was for internal SSL processing, and no other data is available.

%PROTOCOLS%

EXAMPLE

c
int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
    /* Do not do the transfer - only connect to host */
    curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
    result = curl_easy_perform(curl);

    if(result == CURLE_OK) {
      char buf[256];
      size_t nread;
      curl_socket_t sockfd;

      /* Extract the socket from the curl handle - we need it for waiting. */
      result = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);

      /* read data */
      result = curl_easy_recv(curl, buf, sizeof(buf), &nread);
    }
  }
}

%AVAILABILITY%

RETURN VALUE

On success, returns CURLE_OK, stores the received data into buffer, and the number of bytes it actually read into *n.

On failure, returns the appropriate error code.

The function may return CURLE_AGAIN. In this case, use your operating system facilities to wait until data can be read, and retry.

Reading exactly 0 bytes indicates a closed connection.

If there is no socket available to use from the previous transfer, this function returns CURLE_UNSUPPORTED_PROTOCOL.

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_easy_recv
5Section: 3
6Source: libcurl
7See-also:
8 - curl_easy_getinfo (3)
9 - curl_easy_perform (3)
10 - curl_easy_send (3)
11 - curl_easy_setopt (3)
12Protocol:
13 - All
14Added-in: 7.18.2
15---
17# NAME
19curl_easy_recv - receives raw data on an "easy" connection
21# SYNOPSIS
23~~~c
24#include <curl/curl.h>
26CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, size_t *n);
27~~~
29# DESCRIPTION
31This function receives raw data from the established connection. You may use
32it together with curl_easy_send(3) to implement custom protocols using
33libcurl. This functionality can be particularly useful if you use proxies
34and/or SSL encryption: libcurl takes care of proxy negotiation and connection
35setup.
37**buffer** is a pointer to your buffer memory that gets populated by the
38received data. **buflen** is the maximum amount of data you can get in that
39buffer. The variable **n** points to receives the number of received bytes.
41To establish the connection, set CURLOPT_CONNECT_ONLY(3) option before
42calling curl_easy_perform(3) or curl_multi_perform(3). Note that
43curl_easy_recv(3) does not work on connections that were created without
44this option.
46The call returns **CURLE_AGAIN** if there is no data to read - the socket is
47used in non-blocking mode internally. When **CURLE_AGAIN** is returned, use
48your operating system facilities like *select(2)* to wait for data. The
49socket may be obtained using curl_easy_getinfo(3) with
50CURLINFO_ACTIVESOCKET(3).
52Wait on the socket only if curl_easy_recv(3) returns **CURLE_AGAIN**.
53The reason for this is libcurl or the SSL library may internally cache some
54data, therefore you should call curl_easy_recv(3) until all data is
55read which would include any cached data.
57Furthermore if you wait on the socket and it tells you there is data to read,
58curl_easy_recv(3) may return **CURLE_AGAIN** if the only data that was
59read was for internal SSL processing, and no other data is available.
61# %PROTOCOLS%
63# EXAMPLE
65~~~c
66int main(void)
68 CURL *curl = curl_easy_init();
69 if(curl) {
70 CURLcode result;
71 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
72 /* Do not do the transfer - only connect to host */
73 curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
74 result = curl_easy_perform(curl);
76 if(result == CURLE_OK) {
77 char buf[256];
78 size_t nread;
79 curl_socket_t sockfd;
81 /* Extract the socket from the curl handle - we need it for waiting. */
82 result = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
84 /* read data */
85 result = curl_easy_recv(curl, buf, sizeof(buf), &nread);
86 }
87 }
89~~~
91# %AVAILABILITY%
93# RETURN VALUE
95On success, returns **CURLE_OK**, stores the received data into
96**buffer**, and the number of bytes it actually read into ***n**.
98On failure, returns the appropriate error code.
100The function may return **CURLE_AGAIN**. In this case, use your operating
101system facilities to wait until data can be read, and retry.
103Reading exactly 0 bytes indicates a closed connection.
105If there is no socket available to use from the previous transfer, this
106function returns **CURLE_UNSUPPORTED_PROTOCOL**.
Diagnostics4 git calls · 291 ms
CallStatusSizeTime0291 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit27 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=27
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2001.6 KiB261 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=261
git.response.bytes=1619
git.response.cache=MISS
git.response.duration_ms=261
git.fetch.wants=aeb16c0ce5354b19396a76ecfbf59d59bdcb496a
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1619
git.pkt.payload.max=1598
git.sideband.band1.bytes=1597
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e36660d8621de6
Request
800f14f0…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format