master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24/* <DESC>
25 * Pass in a custom socket for libcurl to use.
26 * </DESC>
27 */
28#ifdef _MSC_VER
29#ifndef _CRT_SECURE_NO_WARNINGS
30#define _CRT_SECURE_NO_WARNINGS /* for strerror() */
31#endif
32#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
33#define _WINSOCK_DEPRECATED_NO_WARNINGS /* for inet_addr() */
34#endif
35#endif
37#include <stdio.h>
38#include <string.h>
39#include <stdlib.h>
41#include <curl/curl.h>
43#ifdef _WIN32
44#define close closesocket
45#else
46#include <sys/types.h> /* socket types */
47#include <sys/socket.h> /* socket definitions */
48#include <netinet/in.h>
49#include <arpa/inet.h> /* inet (3) functions */
50#include <unistd.h> /* misc. Unix functions */
51#endif
53#include <errno.h>
55/* The IP address and port number to connect to */
56#define IPADDR "127.0.0.1"
57#define PORTNUM 80
59#ifndef INADDR_NONE
60#define INADDR_NONE 0xffffffff
61#endif
63static size_t write_cb(char *ptr, size_t size, size_t nmemb, void *stream)
64{
65 size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
66 return written;
67}
69static int closecb(void *clientp, curl_socket_t item)
70{
71 (void)clientp;
72 printf("libcurl wants to close %d now\n", (int)item);
73 return 0;
74}
76static curl_socket_t opensocket(void *clientp,
77 curlsocktype purpose,
78 struct curl_sockaddr *address)
79{
80 curl_socket_t sockfd;
81 (void)purpose;
82 (void)address;
83 sockfd = *(curl_socket_t *)clientp;
84 /* the actual externally set socket is passed in via the OPENSOCKETDATA
85 option */
86 return sockfd;
87}
89static int sockopt_callback(void *clientp, curl_socket_t curlfd,
90 curlsocktype purpose)
91{
92 (void)clientp;
93 (void)curlfd;
94 (void)purpose;
95 /* This return code was added in libcurl 7.21.5 */
96 return CURL_SOCKOPT_ALREADY_CONNECTED;
97}
99int main(void)
100{
101 CURL *curl;
102 CURLcode result;
103 struct sockaddr_in servaddr; /* socket address structure */
104 curl_socket_t sockfd;
106 result = curl_global_init(CURL_GLOBAL_ALL);
107 if(result != CURLE_OK)
108 return (int)result;
110 curl = curl_easy_init();
111 if(curl) {
112 /*
113 * Note that libcurl internally thinks that you connect to the host and
114 * port that you specify in the URL option.
115 */
116 curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
118 /* Create the socket "manually" */
119 sockfd = socket(AF_INET, SOCK_STREAM, 0);
120 if(sockfd == CURL_SOCKET_BAD) {
121 printf("Error creating listening socket.\n");
122 return 3;
123 }
125 memset(&servaddr, 0, sizeof(servaddr));
126 servaddr.sin_family = AF_INET;
127 servaddr.sin_port = htons(PORTNUM);
129 servaddr.sin_addr.s_addr = inet_addr(IPADDR);
130 if(INADDR_NONE == servaddr.sin_addr.s_addr) {
131 close(sockfd);
132 return 2;
133 }
135 if(connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) {
136 close(sockfd);
137 printf("client error: connect: %s\n", strerror(errno));
138 return 1;
139 }
141 /* no progress meter please */
142 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
144 /* send all data to this function */
145 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
147 /* call this function to get a socket */
148 curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
149 curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
151 /* call this function to close sockets */
152 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closecb);
153 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &sockfd);
155 /* call this function to set options for the socket */
156 curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
158 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
160 result = curl_easy_perform(curl);
162 curl_easy_cleanup(curl);
164 close(sockfd);
166 if(result != CURLE_OK) {
167 printf("libcurl error: %d\n", (int)result);
168 return 4;
169 }
170 }
172 curl_global_cleanup();
174 return 0;
175}
Diagnostics4 git calls · 29 ms
CallStatusSizeTime029 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=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 · 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=86Open pack map
fetch2001.9 KiB · hit23 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1964 git.response.cache=HIT git.response.duration_ms=23 git.fetch.wants=b07f48b44724c84150b54c18ca792d3d79894880 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=1964 git.pkt.payload.max=1943 git.sideband.band1.bytes=1942 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
- a5e289e68feebd4a
- Request
- 3a024f6c…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format