mirror of
https://github.com/curl/curl.git
synced 2026-08-25 13:53:37 +03:00
tiny-curl: base and FreeRTOS support
This commit is contained in:
parent
6f19f68e93
commit
462d10f44c
17 changed files with 1368 additions and 54 deletions
|
|
@ -109,8 +109,8 @@ tcpkeepalive(struct Curl_easy *data,
|
|||
int optval = data->set.tcp_keepalive?1:0;
|
||||
|
||||
/* only set IDLE and INTVL if setting KEEPALIVE is successful */
|
||||
if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(void *)&optval, sizeof(optval)) < 0) {
|
||||
if(curl_setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(void *)&optval, sizeof(optval)) < 0) {
|
||||
infof(data, "Failed to set SO_KEEPALIVE on fd %d", sockfd);
|
||||
}
|
||||
else {
|
||||
|
|
@ -133,16 +133,16 @@ tcpkeepalive(struct Curl_easy *data,
|
|||
#ifdef TCP_KEEPIDLE
|
||||
optval = curlx_sltosi(data->set.tcp_keepidle);
|
||||
KEEPALIVE_FACTOR(optval);
|
||||
if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
(void *)&optval, sizeof(optval)) < 0) {
|
||||
if(curl_setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
(void *)&optval, sizeof(optval)) < 0) {
|
||||
infof(data, "Failed to set TCP_KEEPIDLE on fd %d", sockfd);
|
||||
}
|
||||
#endif
|
||||
#ifdef TCP_KEEPINTVL
|
||||
optval = curlx_sltosi(data->set.tcp_keepintvl);
|
||||
KEEPALIVE_FACTOR(optval);
|
||||
if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPINTVL,
|
||||
(void *)&optval, sizeof(optval)) < 0) {
|
||||
if(curl_setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPINTVL,
|
||||
(void *)&optval, sizeof(optval)) < 0) {
|
||||
infof(data, "Failed to set TCP_KEEPINTVL on fd %d", sockfd);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -240,7 +240,8 @@ static CURLcode bindlocal(struct Curl_easy *data,
|
|||
{
|
||||
struct connectdata *conn = data->conn;
|
||||
struct Curl_sockaddr_storage sa;
|
||||
struct sockaddr *sock = (struct sockaddr *)&sa; /* bind to this address */
|
||||
struct curl_struct_sockaddr *sock =
|
||||
(struct curl_struct_sockaddr *)&sa; /* bind to this address */
|
||||
curl_socklen_t sizeof_sa = 0; /* size of the data sock points to */
|
||||
struct sockaddr_in *si4 = (struct sockaddr_in *)&sa;
|
||||
#ifdef ENABLE_IPV6
|
||||
|
|
@ -302,8 +303,8 @@ static CURLcode bindlocal(struct Curl_easy *data,
|
|||
* converted to an IP address and would fail Curl_if2ip. Simply try
|
||||
* to use it straight away.
|
||||
*/
|
||||
if(setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
|
||||
dev, (curl_socklen_t)strlen(dev) + 1) == 0) {
|
||||
if(curl_setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
|
||||
dev, (curl_socklen_t)strlen(dev) + 1) == 0) {
|
||||
/* This is typically "errno 1, error: Operation not permitted" if
|
||||
* you're not running as root or another suitable privileged
|
||||
* user.
|
||||
|
|
@ -446,8 +447,9 @@ static CURLcode bindlocal(struct Curl_easy *data,
|
|||
(void)setsockopt(sockfd, SOL_IP, IP_BIND_ADDRESS_NO_PORT, &on, sizeof(on));
|
||||
#endif
|
||||
for(;;) {
|
||||
if(bind(sockfd, sock, sizeof_sa) >= 0) {
|
||||
if(curl_bind(sockfd, sock, sizeof_sa) >= 0) {
|
||||
/* we succeeded to bind */
|
||||
#ifdef HAVE_GETSOCKNAME
|
||||
struct Curl_sockaddr_storage add;
|
||||
curl_socklen_t size = sizeof(add);
|
||||
memset(&add, 0, sizeof(struct Curl_sockaddr_storage));
|
||||
|
|
@ -462,7 +464,7 @@ static CURLcode bindlocal(struct Curl_easy *data,
|
|||
conn->bits.bound = TRUE;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
if(--portnum > 0) {
|
||||
infof(data, "Bind to local port %hu failed, trying next", port);
|
||||
port++; /* try next port */
|
||||
|
|
@ -487,6 +489,7 @@ static CURLcode bindlocal(struct Curl_easy *data,
|
|||
return CURLE_INTERFACE_FAILED;
|
||||
}
|
||||
|
||||
#ifdef HAVE_GETSOCKOPT
|
||||
/*
|
||||
* verifyconnect() returns TRUE if the connect really has happened.
|
||||
*/
|
||||
|
|
@ -553,6 +556,10 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
|
|||
#endif
|
||||
return rc;
|
||||
}
|
||||
#else
|
||||
#define verifyconnect(x,y) TRUE
|
||||
#endif
|
||||
|
||||
|
||||
/* update tempaddr[tempindex] (to the next entry), makes sure to stick
|
||||
to the correct family */
|
||||
|
|
@ -1069,8 +1076,8 @@ static void tcpnodelay(struct Curl_easy *data, curl_socket_t sockfd)
|
|||
(void) data;
|
||||
#endif
|
||||
|
||||
if(setsockopt(sockfd, level, TCP_NODELAY, (void *)&onoff,
|
||||
sizeof(onoff)) < 0)
|
||||
if(curl_setsockopt(sockfd, level, TCP_NODELAY, (void *)&onoff,
|
||||
sizeof(onoff)) < 0)
|
||||
infof(data, "Could not set TCP_NODELAY: %s",
|
||||
Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
|
||||
#else
|
||||
|
|
@ -1271,18 +1278,18 @@ static CURLcode singleipconnect(struct Curl_easy *data,
|
|||
NULL, 0, NULL, NULL);
|
||||
}
|
||||
else {
|
||||
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
|
||||
rc = curl_connect(sockfd, &addr.sa_addr, addr.addrlen);
|
||||
}
|
||||
# else
|
||||
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
|
||||
rc = curl_connect(sockfd, &addr.sa_addr, addr.addrlen);
|
||||
# endif /* HAVE_BUILTIN_AVAILABLE */
|
||||
#elif defined(TCP_FASTOPEN_CONNECT) /* Linux >= 4.11 */
|
||||
#elif defined(HAVE_TCP_FASTOPEN_CONNECT) /* Linux >= 4.11 */
|
||||
if(setsockopt(sockfd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
|
||||
(void *)&optval, sizeof(optval)) < 0)
|
||||
infof(data, "Failed to enable TCP Fast Open on fd %d", sockfd);
|
||||
|
||||
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
|
||||
#elif defined(MSG_FASTOPEN) /* old Linux */
|
||||
#elif defined(HAVE_MSG_FASTOPEN) /* old Linux */
|
||||
if(conn->given->flags & PROTOPT_SSL)
|
||||
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
|
||||
else
|
||||
|
|
@ -1290,7 +1297,7 @@ static CURLcode singleipconnect(struct Curl_easy *data,
|
|||
#endif
|
||||
}
|
||||
else {
|
||||
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
|
||||
rc = curl_connect(sockfd, &addr.sa_addr, addr.addrlen);
|
||||
}
|
||||
|
||||
if(-1 == rc)
|
||||
|
|
@ -1499,8 +1506,8 @@ bool Curl_connalive(struct connectdata *conn)
|
|||
else {
|
||||
/* use the socket */
|
||||
char buf;
|
||||
if(recv((RECV_TYPE_ARG1)conn->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf,
|
||||
(RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) {
|
||||
if(curl_recv((RECV_TYPE_ARG1)conn->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf,
|
||||
(RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) {
|
||||
return false; /* FIN received */
|
||||
}
|
||||
}
|
||||
|
|
@ -1598,7 +1605,7 @@ CURLcode Curl_socket(struct Curl_easy *data,
|
|||
}
|
||||
else
|
||||
/* opensocket callback not set, so simply create the socket now */
|
||||
*sockfd = socket(addr->family, addr->socktype, addr->protocol);
|
||||
*sockfd = curl_socket(addr->family, addr->socktype, addr->protocol);
|
||||
|
||||
if(*sockfd == CURL_SOCKET_BAD)
|
||||
/* no socket, no connection */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue