Artifactspublic-v0

curl

master
ply4 git calls386 ms288 KiB2 cachedprotocol v2
102 lines3.1 KiBRaw

NAME

curl_easy_send - sends raw data over an "easy" connection

SYNOPSIS

c
#include <curl/curl.h>

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

DESCRIPTION

This function sends arbitrary data over the established connection. You may use it together with curl_easy_recv(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 the data of length buflen that you want sent. The variable n points to receives the number of sent 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_send(3) does not work on connections that were created without this option.

The call returns CURLE_AGAIN if it is not possible to send data right now and the call should be retried later with the same buffer-content and a buflen no smaller than the original buflen.

  • the socket is used in non-blocking mode internally. When CURLE_AGAIN is returned, use your operating system facilities like select(2) to wait until the socket is writable. The socket may be obtained using curl_easy_getinfo(3) with CURLINFO_ACTIVESOCKET(3).

Furthermore if you wait on the socket and it tells you it is writable, curl_easy_send(3) may return CURLE_AGAIN if the only data that was sent was for internal SSL processing, and no other data could be sent.

%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) {
      curl_socket_t sockfd;
      size_t sent;
      /* Extract the socket from the curl handle - we need it for waiting. */
      result = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);

      /* send data */
      result = curl_easy_send(curl, "hello", 5, &sent);
    }
  }
}

%AVAILABILITY%

RETURN VALUE

On success, returns CURLE_OK and stores the number of bytes actually sent into *n. Note that this may be less than the amount you wanted to send.

On failure, returns the appropriate error code.

This function may return CURLE_AGAIN. In this case, use your operating system facilities to wait until the socket is writable, and retry. The buffer passed to the retry call should hold the same data as the original one and buflen should be no smaller than before.

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_send
5Section: 3
6Source: libcurl
7See-also:
8 - curl_easy_getinfo (3)
9 - curl_easy_perform (3)
10 - curl_easy_recv (3)
11 - curl_easy_setopt (3)
12Protocol:
13 - All
14Added-in: 7.18.2
15---
17# NAME
19curl_easy_send - sends raw data over an "easy" connection
21# SYNOPSIS
23~~~c
24#include <curl/curl.h>
26CURLcode curl_easy_send(CURL *curl, const void *buffer,
27 size_t buflen, size_t *n);
28~~~
30# DESCRIPTION
32This function sends arbitrary data over the established connection. You may
33use it together with curl_easy_recv(3) to implement custom protocols
34using libcurl. This functionality can be particularly useful if you use
35proxies and/or SSL encryption: libcurl takes care of proxy negotiation and
36connection setup.
38**buffer** is a pointer to the data of length **buflen** that you want
39sent. The variable **n** points to receives the number of sent 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_send(3) does not work on connections that were created without
44this option.
46The call returns **CURLE_AGAIN** if it is not possible to send data right now
47and the call should be retried later with the same **buffer**-content and a
48**buflen** no smaller than the original **buflen**.
49- the socket is used in non-blocking mode internally. When **CURLE_AGAIN**
50is returned, use your operating system facilities like *select(2)* to wait
51until the socket is writable. The socket may be obtained using
52curl_easy_getinfo(3) with CURLINFO_ACTIVESOCKET(3).
54Furthermore if you wait on the socket and it tells you it is writable,
55curl_easy_send(3) may return **CURLE_AGAIN** if the only data that was sent
56was for internal SSL processing, and no other data could be sent.
58# %PROTOCOLS%
60# EXAMPLE
62~~~c
63int main(void)
65 CURL *curl = curl_easy_init();
66 if(curl) {
67 CURLcode result;
68 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
69 /* Do not do the transfer - only connect to host */
70 curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
71 result = curl_easy_perform(curl);
73 if(result == CURLE_OK) {
74 curl_socket_t sockfd;
75 size_t sent;
76 /* Extract the socket from the curl handle - we need it for waiting. */
77 result = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
79 /* send data */
80 result = curl_easy_send(curl, "hello", 5, &sent);
81 }
82 }
84~~~
86# %AVAILABILITY%
88# RETURN VALUE
90On success, returns **CURLE_OK** and stores the number of bytes actually
91sent into ***n**. Note that this may be less than the amount you wanted to
92send.
94On failure, returns the appropriate error code.
96This function may return **CURLE_AGAIN**. In this case, use your operating
97system facilities to wait until the socket is writable, and retry.
98The **buffer** passed to the retry call should hold the _same data_
99as the original one and **buflen** should be _no smaller_ than before.
101If there is no socket available to use from the previous transfer, this
102function returns **CURLE_UNSUPPORTED_PROTOCOL**.
Diagnostics4 git calls · 386 ms
CallStatusSizeTime0386 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=1
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 · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=381
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
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.5 KiB381 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1587
git.response.cache=MISS
git.response.duration_ms=381
git.fetch.wants=924f3e455c075a7809c19731bc42a8785122e4b6
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=1587
git.pkt.payload.max=1566
git.sideband.band1.bytes=1565
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
a5e3258408f898f1
Request
e101f69a…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format