Artifactspublic-v0

curl

master
ply4 git calls28 ms288 KiB3 cachedprotocol v2
111 lines2.7 KiBRaw

NAME

curl_global_init_mem - global libcurl initialization with memory callbacks

SYNOPSIS

c
#include <curl/curl.h>

CURLcode curl_global_init_mem(long flags,
                              curl_malloc_callback m,
                              curl_free_callback f,
                              curl_realloc_callback r,
                              curl_strdup_callback s,
                              curl_calloc_callback c);

DESCRIPTION

This function works exactly as curl_global_init(3) with one addition: it allows the application to set callbacks to replace the otherwise used internal memory functions.

If you are using libcurl from multiple threads or libcurl was built with the threaded resolver option then the callback functions must be thread-safe. The threaded resolver is a common build option to enable (and in some cases the default) so we strongly urge you to make your callback functions thread-safe.

All callback arguments must be set to valid function pointers. The prototypes for the given callbacks must match these:

void *malloc_callback(size_t size);

To replace malloc()

void free_callback(void *ptr);

To replace free()

void *realloc_callback(void *ptr, size_t size);

To replace realloc()

char *strdup_callback(const char *str);

To replace strdup()

void *calloc_callback(size_t nmemb, size_t size);

To replace calloc()

This function is otherwise the same as curl_global_init(3), please refer to that man page for documentation.

CAUTION

Manipulating these gives considerable powers to the application to severely screw things up for libcurl. Take care.

%PROTOCOLS%

EXAMPLE

c
extern void *malloc_cb(size_t);
extern void free_cb(void *);
extern void *realloc_cb(void *, size_t);
extern char *strdup_cb(const char *);
extern void *calloc_cb(size_t, size_t);

int main(void)
{
  CURLcode result;

  result = curl_global_init_mem(CURL_GLOBAL_DEFAULT, malloc_cb,
                                free_cb, realloc_cb,
                                strdup_cb, calloc_cb);

  if(result == CURLE_OK) {

    /* use libcurl, then before exiting... */

    curl_global_cleanup();
  }
}

%AVAILABILITY%

RETURN VALUE

This function returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3). If CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3) there can be an error message stored in the error buffer when non-zero is returned.

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_global_init_mem
5Section: 3
6Source: libcurl
7See-also:
8 - curl_global_cleanup (3)
9 - curl_global_init (3)
10Protocol:
11 - All
12Added-in: 7.12.0
13---
15# NAME
17curl_global_init_mem - global libcurl initialization with memory callbacks
19# SYNOPSIS
21~~~c
22#include <curl/curl.h>
24CURLcode curl_global_init_mem(long flags,
25 curl_malloc_callback m,
26 curl_free_callback f,
27 curl_realloc_callback r,
28 curl_strdup_callback s,
29 curl_calloc_callback c);
30~~~
32# DESCRIPTION
34This function works exactly as curl_global_init(3) with one addition: it
35allows the application to set callbacks to replace the otherwise used internal
36memory functions.
38If you are using libcurl from multiple threads or libcurl was built with the
39threaded resolver option then the callback functions must be thread-safe. The
40threaded resolver is a common build option to enable (and in some cases the
41default) so we strongly urge you to make your callback functions thread-safe.
43All callback arguments must be set to valid function pointers. The
44prototypes for the given callbacks must match these:
46## `void *malloc_callback(size_t size);`
48To replace malloc()
50## `void free_callback(void *ptr);`
52To replace free()
54## `void *realloc_callback(void *ptr, size_t size);`
56To replace realloc()
58## `char *strdup_callback(const char *str);`
60To replace strdup()
62## `void *calloc_callback(size_t nmemb, size_t size);`
64To replace calloc()
66This function is otherwise the same as curl_global_init(3), please refer
67to that man page for documentation.
69# CAUTION
71Manipulating these gives considerable powers to the application to severely
72screw things up for libcurl. Take care.
74# %PROTOCOLS%
76# EXAMPLE
78~~~c
79extern void *malloc_cb(size_t);
80extern void free_cb(void *);
81extern void *realloc_cb(void *, size_t);
82extern char *strdup_cb(const char *);
83extern void *calloc_cb(size_t, size_t);
85int main(void)
87 CURLcode result;
89 result = curl_global_init_mem(CURL_GLOBAL_DEFAULT, malloc_cb,
90 free_cb, realloc_cb,
91 strdup_cb, calloc_cb);
93 if(result == CURLE_OK) {
95 /* use libcurl, then before exiting... */
97 curl_global_cleanup();
98 }
100~~~
102# %AVAILABILITY%
104# RETURN VALUE
106This function returns a CURLcode indicating success or error.
108CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
109libcurl-errors(3). If CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3)
110there can be an error message stored in the error buffer when non-zero is
111returned.
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 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=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 · 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 · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=23
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
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.2 KiB · hit23 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1261
git.response.cache=HIT
git.response.duration_ms=23
git.fetch.wants=a39471c729cce720680ced1e97f53d609944bcac
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=1261
git.pkt.payload.max=1240
git.sideband.band1.bytes=1239
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
a5e3470cef86f4d4
Request
8603d148…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format