Artifactspublic-v0

curl

master
ply4 git calls341 ms289 KiB2 cachedprotocol v2
157 lines4.5 KiBRaw

NAME

CURLMOPT_SOCKETFUNCTION - callback informed about what to wait for

SYNOPSIS

c
#include <curl/curl.h>

int socket_callback(CURL *easy,
                    curl_socket_t socket,
                    int what,
                    void *clientp,
                    void *socketp);

CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETFUNCTION,
                            socket_callback);

DESCRIPTION

Pass a pointer to your callback function, which should match the prototype shown above.

When the curl_multi_socket_action(3) function is called, it uses this callback to inform the application about updates in the socket (file descriptor) status by doing none, one, or multiple calls to the socket_callback. The callback function gets status updates with changes since the previous time the callback was called. If the given callback pointer is set to NULL, no callback is called.

libcurl then expects the application to monitor the sockets for the specific activities and tell libcurl again when something happens on one of them. Tell libcurl by calling curl_multi_socket_action(3).

This callback may get invoked at any time when interacting with libcurl. This may even happen after all transfers are done and is likely to happen during a call to curl_multi_cleanup(3) when cached connections are shut down.

libcurl may use a number of internal file descriptors for name resolving, Happy Eyeballs racing, internal communication and more, in addition to the main sockets used for network transfers. All of those file descriptors might get passed to this callback as "sockets".

CALLBACK ARGUMENTS

easy identifies the specific transfer for which this update is related. Since this callback manages a whole multi handle, an application should not make assumptions about which particular handle that is passed here. It might even be an internal easy handle that the application did not add itself.

socket is the specific socket this function invocation concerns. If the what argument is not CURL_POLL_REMOVE then it holds information about what activity on this socket the application is supposed to monitor. Subsequent calls to this callback might update the what bits for a socket that is already monitored.

The socket callback should return 0 on success, and -1 on error. If this callback returns error, all transfers currently in progress in this multi handle are aborted and made to fail.

clientp is set with CURLMOPT_SOCKETDATA(3).

socketp is set with curl_multi_assign(3) or NULL.

The what parameter informs the callback on the status of the given socket. It can hold one of these values:

CURL_POLL_IN

Wait for incoming data. For the socket to become readable.

CURL_POLL_OUT

Wait for outgoing data. For the socket to become writable.

CURL_POLL_INOUT

Wait for incoming and outgoing data. For the socket to become readable or writable.

CURL_POLL_REMOVE

The specified socket or file descriptor is no longer used by libcurl for any active transfer. It might soon be added again.

When a socket is given a CURL_POLL_REMOVE value, it might be because libcurl is going to close it, but it might also mean that it does not need any more monitoring for the moment. An application cannot assume either. The same socket might appear soon in a call asking for monitoring again.

A socket that is removed like this loses its assigned pointer as set with curl_multi_assign(3).

DEFAULT

NULL (no callback)

%PROTOCOLS%

EXAMPLE

c
struct priv {
  void *ours;
};

static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
{
  struct priv *p = cbp;
  printf("our ptr: %p\n", p->ours);

  if(what == CURL_POLL_REMOVE) {
    /* remove the socket from our collection */
  }
  if(what & CURL_POLL_IN) {
    /* wait for read on this socket */
  }
  if(what & CURL_POLL_OUT) {
    /* wait for write on this socket */
  }

  return 0;
}

int main(void)
{
  struct priv setup;
  CURLM *multi = curl_multi_init();
  /* ... use socket callback and custom pointer */
  curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
  curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
}

%AVAILABILITY%

RETURN VALUE

Returns CURLM_OK.

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLMOPT_SOCKETFUNCTION
5Section: 3
6Source: libcurl
7See-also:
8 - CURLMOPT_SOCKETDATA (3)
9 - CURLMOPT_TIMERFUNCTION (3)
10 - CURLOPT_CLOSESOCKETFUNCTION (3)
11 - curl_multi_socket_action (3)
12Protocol:
13 - All
14Added-in: 7.15.4
15---
17# NAME
19CURLMOPT_SOCKETFUNCTION - callback informed about what to wait for
21# SYNOPSIS
23~~~c
24#include <curl/curl.h>
26int socket_callback(CURL *easy,
27 curl_socket_t socket,
28 int what,
29 void *clientp,
30 void *socketp);
32CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETFUNCTION,
33 socket_callback);
34~~~
36# DESCRIPTION
38Pass a pointer to your callback function, which should match the prototype
39shown above.
41When the curl_multi_socket_action(3) function is called, it uses this callback
42to inform the application about updates in the socket (file descriptor) status
43by doing none, one, or multiple calls to the **socket_callback**. The callback
44function gets status updates with changes since the previous time the callback
45was called. If the given callback pointer is set to NULL, no callback is
46called.
48libcurl then expects the application to monitor the sockets for the specific
49activities and tell libcurl again when something happens on one of them. Tell
50libcurl by calling curl_multi_socket_action(3).
52This callback may get invoked at any time when interacting with libcurl.
53This may even happen after all transfers are done and is *likely* to
54happen *during* a call to curl_multi_cleanup(3) when cached connections
55are shut down.
57libcurl may use a number of internal file descriptors for name resolving,
58Happy Eyeballs racing, internal communication and more, in addition to the
59main sockets used for network transfers. All of those file descriptors might
60get passed to this callback as "sockets".
62# CALLBACK ARGUMENTS
64**easy** identifies the specific transfer for which this update is related.
65Since this callback manages a whole multi handle, an application should not
66make assumptions about which particular handle that is passed here. It might
67even be an internal easy handle that the application did not add itself.
69**socket** is the specific socket this function invocation concerns. If the
70**what** argument is not CURL_POLL_REMOVE then it holds information about what
71activity on this socket the application is supposed to monitor. Subsequent
72calls to this callback might update the **what** bits for a socket that is
73already monitored.
75The socket callback should return 0 on success, and -1 on error. If this
76callback returns error, **all** transfers currently in progress in this
77multi handle are aborted and made to fail.
79**clientp** is set with CURLMOPT_SOCKETDATA(3).
81**socketp** is set with curl_multi_assign(3) or NULL.
83The **what** parameter informs the callback on the status of the given socket.
84It can hold one of these values:
86## CURL_POLL_IN
88Wait for incoming data. For the socket to become readable.
90## CURL_POLL_OUT
92Wait for outgoing data. For the socket to become writable.
94## CURL_POLL_INOUT
96Wait for incoming and outgoing data. For the socket to become readable or
97writable.
99## CURL_POLL_REMOVE
101The specified socket or file descriptor is no longer used by libcurl for any
102active transfer. It might soon be added again.
104When a socket is given a CURL_POLL_REMOVE value, it might be because libcurl
105is going to close it, but it might also mean that it does not need any more
106monitoring for the moment. An application cannot assume either. The same
107socket might appear soon in a call asking for monitoring again.
109A socket that is removed like this loses its assigned pointer as set with
110curl_multi_assign(3).
112# DEFAULT
114NULL (no callback)
116# %PROTOCOLS%
118# EXAMPLE
120~~~c
121struct priv {
122 void *ours;
123};
125static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
127 struct priv *p = cbp;
128 printf("our ptr: %p\n", p->ours);
130 if(what == CURL_POLL_REMOVE) {
131 /* remove the socket from our collection */
132 }
133 if(what & CURL_POLL_IN) {
134 /* wait for read on this socket */
135 }
136 if(what & CURL_POLL_OUT) {
137 /* wait for write on this socket */
138 }
140 return 0;
143int main(void)
145 struct priv setup;
146 CURLM *multi = curl_multi_init();
147 /* ... use socket callback and custom pointer */
148 curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
149 curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
151~~~
153# %AVAILABILITY%
155# RETURN VALUE
157Returns CURLM_OK.
Diagnostics4 git calls · 341 ms
CallStatusSizeTime0341 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
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 · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=335
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=4
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
fetch2002.0 KiB335 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2049
git.response.cache=MISS
git.response.duration_ms=335
git.fetch.wants=fb67c01a60a9203c9e2e2fff39002b62d480461c
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=2049
git.pkt.payload.max=2028
git.sideband.band1.bytes=2027
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
a5e3613cadcfb86e
Request
4f9fc472…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format