Skip to content

Commit 1db3035

Browse files
authored
Merge pull request libgit2#3996 from pks-t/pks/curl-lastsocket-deprecation
curl_stream: use CURLINFO_ACTIVESOCKET if curl is recent enough
2 parents f5ea9d4 + 5cbd526 commit 1db3035

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/curl_stream.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
#include "vector.h"
1616
#include "proxy.h"
1717

18+
/* This is for backwards compatibility with curl<7.45.0. */
19+
#ifndef CURLINFO_ACTIVESOCKET
20+
# define CURLINFO_ACTIVESOCKET CURLINFO_LASTSOCKET
21+
# define GIT_CURL_BADSOCKET -1
22+
# define git_activesocket_t long
23+
#else
24+
# define GIT_CURL_BADSOCKET CURL_SOCKET_BAD
25+
# define git_activesocket_t curl_socket_t
26+
#endif
27+
1828
typedef struct {
1929
git_stream parent;
2030
CURL *handle;
@@ -87,7 +97,8 @@ static int ask_and_apply_proxy_creds(curl_stream *s)
8797
static int curls_connect(git_stream *stream)
8898
{
8999
curl_stream *s = (curl_stream *) stream;
90-
long sockextr, connect_last = 0;
100+
git_activesocket_t sockextr;
101+
long connect_last = 0;
91102
int failed_cert = 0, error;
92103
bool retry_connect;
93104
CURLcode res;
@@ -117,11 +128,11 @@ static int curls_connect(git_stream *stream)
117128
if (res == CURLE_PEER_FAILED_VERIFICATION)
118129
failed_cert = 1;
119130

120-
if ((res = curl_easy_getinfo(s->handle, CURLINFO_LASTSOCKET, &sockextr)) != CURLE_OK) {
131+
if ((res = curl_easy_getinfo(s->handle, CURLINFO_ACTIVESOCKET, &sockextr)) != CURLE_OK) {
121132
return seterr_curl(s);
122133
}
123134

124-
if (sockextr == -1) {
135+
if (sockextr == GIT_CURL_BADSOCKET) {
125136
giterr_set(GITERR_NET, "curl socket is no longer valid");
126137
return -1;
127138
}

0 commit comments

Comments
 (0)