tiny-curl: base and FreeRTOS support

This commit is contained in:
Daniel Stenberg 2020-05-27 10:27:38 +02:00
parent 9d954e49bc
commit ceda8d10ea
17 changed files with 1430 additions and 67 deletions

View file

@ -30,7 +30,8 @@ EXTRA_DIST = Makefile.m32 config-win32.h config-win32ce.h \
config-os400.h setup-os400.h config-symbian.h Makefile.Watcom \
config-tpf.h mk-ca-bundle.pl mk-ca-bundle.vbs $(CMAKE_DIST) \
firefox-db2pem.sh config-vxworks.h Makefile.vxworks checksrc.pl \
setup-win32.h
setup-win32.h \
config-freertos.h
lib_LTLIBRARIES = libcurl.la

398
lib/config-freertos.h Normal file
View file

@ -0,0 +1,398 @@
#ifndef CURL_CONFIG_FREERTOS_H
#define CURL_CONFIG_FREERTOS_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
***************************************************************************/
/* to disable cookies support */
#define CURL_DISABLE_COOKIES 1
/* disable HTTP authentication */
#define CURL_DISABLE_HTTP_AUTH 1
/* disable DoH */
#define CURL_DISABLE_DOH 1
/* disable mime API */
#define CURL_DISABLE_MIME 1
/* disable date parsing */
#define CURL_DISABLE_PARSEDATE 1
/* disable netrc parsing */
#define CURL_DISABLE_NETRC 1
/* disable DNS shuffling */
#define CURL_DISABLE_SHUFFLE_DNS 1
/* disable progress-meter */
#define CURL_DISABLE_PROGRESS_METER 1
/* to disable cryptographic authentication */
#define CURL_DISABLE_CRYPTO_AUTH 1
/* to disable DICT */
#define CURL_DISABLE_DICT 1
/* to disable FILE */
#define CURL_DISABLE_FILE 1
/* to disable FTP */
#define CURL_DISABLE_FTP 1
/* to disable Gopher */
#define CURL_DISABLE_GOPHER 1
/* to disable IMAP */
#define CURL_DISABLE_IMAP 1
/* to disable LDAP */
#define CURL_DISABLE_LDAP 1
/* to disable LDAPS */
#define CURL_DISABLE_LDAPS 1
/* to disable POP3 */
#define CURL_DISABLE_POP3 1
/* to disable proxies */
#define CURL_DISABLE_PROXY 1
/* to disable RTSP */
#define CURL_DISABLE_RTSP 1
/* to disable SMB/CIFS */
#define CURL_DISABLE_SMB 1
/* to disable SMTP */
#define CURL_DISABLE_SMTP 1
/* to disable TELNET */
#define CURL_DISABLE_TELNET 1
/* to disable TFTP */
#define CURL_DISABLE_TFTP 1
/* to disable verbose strings */
#define CURL_DISABLE_VERBOSE_STRINGS 1
/* Definition to make a library symbol externally visible. */
#define CURL_EXTERN_SYMBOL __attribute__ ((__visibility__ ("default")))
/* IP address type in sockaddr */
#define CURL_SA_FAMILY_T uint8_t
/* lack of non-blocking support */
#define USE_BLOCKING_SOCKETS 1
/* Define to the type of arg 2 for gethostname. */
#define GETHOSTNAME_TYPE_ARG2 size_t
/* Specifies the number of arguments to getservbyport_r */
#define GETSERVBYPORT_R_ARGS 6
/* Specifies the size of the buffer to pass to getservbyport_r */
#define GETSERVBYPORT_R_BUFSIZE 4096
/* Define to 1 if you have the <alloca.h> header file. */
#define HAVE_ALLOCA_H 1
/* Define to 1 if you have the <arpa/inet.h> header file. */
/* Define to 1 if you have the <arpa/tftp.h> header file. */
/* Define to 1 if you have the <assert.h> header file. */
#define HAVE_ASSERT_H 1
/* Define to 1 if you have the basename function. */
#define HAVE_BASENAME 1
/* Define to 1 if bool is an available type. */
#define HAVE_BOOL_T 1
/* Define to 1 if you have the connect function. */
#define HAVE_CONNECT 1
/* Define to 1 if you have the <cyassl/error-ssl.h> header file. */
#define HAVE_CYASSL_ERROR_SSL_H 1
/* Define to 1 if you have the <cyassl/options.h> header file. */
#define HAVE_CYASSL_OPTIONS_H 1
/* Define to 1 if you have the declaration of `getpwuid_r', and to 0 if you
don't. */
#define HAVE_DECL_GETPWUID_R 1
/* Define to 1 if you have the <errno.h> header file. */
#define HAVE_ERRNO_H 1
/* Define to 1 if you have the gethostbyname function. */
#define HAVE_GETHOSTBYNAME 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the <linux/tcp.h> header file. */
/* if your compiler supports LL */
#define HAVE_LL 1
/* Define to 1 if the compiler supports the 'long long' data type. */
#define HAVE_LONGLONG 1
/* Define to 1 if you have the malloc.h header file. */
#define HAVE_MALLOC_H 1
/* Define to 1 if you have the memory.h header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the <netdb.h> header file. */
/* Define to 1 if you have the <netinet/in.h> header file. */
/* Define to 1 if you have the <netinet/tcp.h> header file. */
/* Define to 1 if you have the <net/if.h> header file. */
/* Define to 1 if you have the recv function. */
#define HAVE_RECV 1
/* Define to 1 if you have the select function. */
#define HAVE_SELECT 1
/* Define to 1 if you have the send function. */
#define HAVE_SEND 1
/* Define to 1 if you have the <setjmp.h> header file. */
#define HAVE_SETJMP_H 1
/* Define to 1 if you have the setsockopt function. */
#define HAVE_SETSOCKOPT 1
/* Define to 1 if you have the socket function. */
#define HAVE_SOCKET 1
/* Define to 1 if you have the <stdbool.h> header file. */
#define HAVE_STDBOOL_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdio.h> header file. */
#define HAVE_STDIO_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the strcasecmp function. */
#define HAVE_STRCASECMP 1
/* Define to 1 if you have the strdup function. */
#define HAVE_STRDUP 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the strncasecmp function. */
#define HAVE_STRNCASECMP 1
/* Define to 1 if you have the <stropts.h> header file. */
/* Define to 1 if you have the strstr function. */
#define HAVE_STRSTR 1
/* Define to 1 if you have the strtok_r function. */
#define HAVE_STRTOK_R 1
/* Define to 1 if you have the strtoll function. */
#define HAVE_STRTOLL 1
/* if struct sockaddr_storage is defined */
#define HAVE_STRUCT_SOCKADDR_STORAGE 1
/* Define to 1 if you have the timeval struct. */
#define HAVE_STRUCT_TIMEVAL 1
/* Define to 1 if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <sys/uio.h> header file. */
#define HAVE_SYS_UIO_H 1
/* Define to 1 if you have the <sys/un.h> header file. */
/* Define to 1 if you have the <sys/wait.h> header file. */
#define HAVE_SYS_WAIT_H 1
/* Define to 1 if you have the <sys/xattr.h> header file. */
#define HAVE_SYS_XATTR_H 1
/* Define to 1 if you have the <termios.h> header file. */
#define HAVE_TERMIOS_H 1
/* Define to 1 if you have the <termio.h> header file. */
#define HAVE_TERMIO_H 1
/* Define to 1 if you have the <time.h> header file. */
#define HAVE_TIME_H 1
/* Define to 1 if you have the `utime' function. */
#define HAVE_UTIME 1
/* Define to 1 if you have the `utimes' function. */
#define HAVE_UTIMES 1
/* Define to 1 if you have the <utime.h> header file. */
#define HAVE_UTIME_H 1
/* Define to 1 if compiler supports C99 variadic macro style. */
#define HAVE_VARIADIC_MACROS_C99 1
/* Define to 1 if compiler supports old gcc variadic macro style. */
#define HAVE_VARIADIC_MACROS_GCC 1
/* Define to 1 if you have the `wolfSSL_CTX_UseSupportedCurve' function. */
#define HAVE_WOLFSSL_CTX_USESUPPORTEDCURVE 1
/* Define to 1 if you have the `wolfSSL_get_peer_certificate' function. */
#define HAVE_WOLFSSL_GET_PEER_CERTIFICATE 1
/* Define to 1 if you have the writev function. */
#define HAVE_WRITEV 1
/* cpu-machine-OS */
#define OS "x86_64-freertos"
/* Define to the type of arg 1 for recv. */
#define RECV_TYPE_ARG1 Socket_t
/* Define to the type of arg 2 for recv. */
#define RECV_TYPE_ARG2 void *
/* Define to the type of arg 3 for recv. */
#define RECV_TYPE_ARG3 size_t
/* Define to the type of arg 4 for recv. */
#define RECV_TYPE_ARG4 long
/* Define to the function return type for recv. */
#define RECV_TYPE_RETV long
/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
/* Define to the type qualifier of arg 5 for select. */
#define SELECT_QUAL_ARG5
/* Define to the type of arg 1 for select. */
#define SELECT_TYPE_ARG1 int
/* Define to the type of args 2, 3 and 4 for select. */
#define SELECT_TYPE_ARG234 fd_set *
/* Define to the type of arg 5 for select. */
#define SELECT_TYPE_ARG5 struct timeval *
/* Define to the function return type for select. */
#define SELECT_TYPE_RETV int
/* Define to the type qualifier of arg 2 for send. */
#define SEND_QUAL_ARG2 const
/* Define to the type of arg 1 for send. */
#define SEND_TYPE_ARG1 int
/* Define to the type of arg 2 for send. */
#define SEND_TYPE_ARG2 void *
/* Define to the type of arg 3 for send. */
#define SEND_TYPE_ARG3 size_t
/* Define to the type of arg 4 for send. */
#define SEND_TYPE_ARG4 int
/* Define to the function return type for send. */
#define SEND_TYPE_RETV ssize_t
#define ssize_t int
/* The number of bytes in type curl_off_t */
#define SIZEOF_CURL_OFF_T 8
/* The number of bytes in type int */
#define SIZEOF_INT 4
/* The number of bytes in type long */
#define SIZEOF_LONG 4
/* The number of bytes in type long long */
#define SIZEOF_LONG_LONG 8
/* The number of bytes in type off_t */
#define SIZEOF_OFF_T 8
/* The number of bytes in type short */
#define SIZEOF_SHORT 2
/* The number of bytes in type size_t */
#define SIZEOF_SIZE_T 8
/* The number of bytes in type time_t */
#define SIZEOF_TIME_T 8
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* if CyaSSL/WolfSSL is enabled */
#define USE_CYASSL 1
/* Version number of package */
#define VERSION "-"
/* Define to 1 if OS is AIX. */
#ifndef _ALL_SOURCE
/* # undef _ALL_SOURCE */
#endif
/* Work-around to allow building the Windows FreeRTOS simulator */
#define ALLOW_MSVC6_WITHOUT_PSDK 1
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
#endif /* CURL_CONFIG_FREERTOS_H */

View file

@ -114,8 +114,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\n", sockfd);
}
else {
@ -138,16 +138,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\n", 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\n", sockfd);
}
#endif
@ -247,7 +247,8 @@ static CURLcode bindlocal(struct connectdata *conn,
struct Curl_easy *data = conn->data;
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
@ -306,8 +307,8 @@ static CURLcode bindlocal(struct connectdata *conn,
* 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.
@ -448,8 +449,9 @@ static CURLcode bindlocal(struct connectdata *conn,
}
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));
@ -460,6 +462,7 @@ static CURLcode bindlocal(struct connectdata *conn,
error, Curl_strerror(error, buffer, sizeof(buffer)));
return CURLE_INTERFACE_FAILED;
}
#endif
infof(data, "Local port: %hu\n", port);
conn->bits.bound = TRUE;
return CURLE_OK;
@ -489,6 +492,7 @@ static CURLcode bindlocal(struct connectdata *conn,
return CURLE_INTERFACE_FAILED;
}
#ifdef HAVE_GETSOCKOPT
/*
* verifyconnect() returns TRUE if the connect really has happened.
*/
@ -555,6 +559,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 */
@ -1028,8 +1036,8 @@ static void tcpnodelay(struct connectdata *conn, curl_socket_t sockfd)
(void) conn;
#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\n",
Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
#else
@ -1229,18 +1237,18 @@ static CURLcode singleipconnect(struct connectdata *conn,
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\n", 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
@ -1248,7 +1256,7 @@ static CURLcode singleipconnect(struct connectdata *conn,
#endif
}
else {
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
rc = curl_connect(sockfd, &addr.sa_addr, addr.addrlen);
}
if(-1 == rc)
@ -1438,8 +1446,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 */
}
}
@ -1537,7 +1545,7 @@ CURLcode Curl_socket(struct connectdata *conn,
}
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 */

View file

@ -91,7 +91,7 @@ struct Curl_sockaddr_ex {
int protocol;
unsigned int addrlen;
union {
struct sockaddr addr;
struct curl_struct_sockaddr addr;
struct Curl_sockaddr_storage buff;
} _sa_ex_u;
};

View file

@ -68,10 +68,14 @@
#else /* HAVE_CONFIG_H */
#ifdef FreeRTOS
#include "config-freertos.h"
#endif
#ifdef _WIN32_WCE
# include "config-win32ce.h"
#else
# ifdef WIN32
# if defined(WIN32) && !defined(FreeRTOS)
# include "config-win32.h"
# endif
#endif
@ -596,6 +600,23 @@
# endif
#endif
/*
* Intentionally fail to build when using msvc 6.0 without PSDK installed.
* The brave of heart can circumvent this, defining ALLOW_MSVC6_WITHOUT_PSDK
* in lib/config-win32.h although absolutely discouraged and unsupported.
*/
#if 0
# if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_))
# if !defined(ALLOW_MSVC6_WITHOUT_PSDK)
# error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. \
"Windows Server 2003 PSDK"
# else
# define CURL_DISABLE_LDAP 1
# endif
# endif
#endif
#ifdef NETWARE
int netware_init(void);
#ifndef __NOVELL_LIBC__

View file

@ -130,7 +130,8 @@ struct timeval {
#define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \
(RECV_TYPE_ARG2)(y), \
(RECV_TYPE_ARG3)(z))
#elif defined(FreeRTOS)
#define sread(a,b,c) FreeRTOS_recv(a,b,c,0)
#elif defined(HAVE_RECV)
/*
* The definitions for the return type and arguments types
@ -193,6 +194,9 @@ struct timeval {
/* */
Error Missing_definition_of_return_and_arguments_types_of_send
/* */
#elif defined(FreeRTOS)
/* The flags argument (4) marked as 'Not currently used' */
#define swrite(a,b,c) FreeRTOS_send(a,b,c,0)
#else
#define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \
(SEND_QUAL_ARG2 SEND_TYPE_ARG2)(y), \
@ -260,6 +264,8 @@ struct timeval {
# define sclose(x) close_s((x))
#elif defined(USE_LWIPSOCK)
# define sclose(x) lwip_close((x))
#elif defined(FreeRTOS)
# define sclose(x) FreeRTOS_closesocket((x))
#else
# define sclose(x) close((x))
#endif

View file

@ -304,7 +304,7 @@ static size_t hash_fd(void *key, size_t key_length, size_t slots_num)
curl_socket_t fd = *((curl_socket_t *) key);
(void) key_length;
return (fd % slots_num);
return ((long)fd % slots_num); /* weirdo FreeRTOS hack */
}
/*
@ -1017,8 +1017,8 @@ static int multi_getsock(struct Curl_easy *data,
}
CURLMcode curl_multi_fdset(struct Curl_multi *multi,
fd_set *read_fd_set, fd_set *write_fd_set,
fd_set *exc_fd_set, int *max_fd)
curl_fd_set *read_fd_set, curl_fd_set *write_fd_set,
curl_fd_set *exc_fd_set, int *max_fd)
{
/* Scan through all the easy handles to get the file descriptors set.
Some easy handles may not have connected to the remote host yet,
@ -1043,18 +1043,20 @@ CURLMcode curl_multi_fdset(struct Curl_multi *multi,
curl_socket_t s = CURL_SOCKET_BAD;
if((bitmap & GETSOCK_READSOCK(i)) && VALID_SOCK((sockbunch[i]))) {
FD_SET(sockbunch[i], read_fd_set);
CURL_FD_SET(sockbunch[i], read_fd_set, eSELECT_READ);
s = sockbunch[i];
}
if((bitmap & GETSOCK_WRITESOCK(i)) && VALID_SOCK((sockbunch[i]))) {
FD_SET(sockbunch[i], write_fd_set);
CURL_FD_SET(sockbunch[i], write_fd_set, eSELECT_WRITE);
s = sockbunch[i];
}
if(s == CURL_SOCKET_BAD)
/* this socket is unused, break out of loop */
break;
#ifndef FreeRTOS
if((int)s > this_max_fd)
this_max_fd = (int)s;
#endif
}
data = data->next; /* check next handle */
@ -1084,8 +1086,8 @@ static CURLMcode Curl_multi_wait(struct Curl_multi *multi,
bool ufds_malloc = FALSE;
long timeout_internal;
int retcode = 0;
struct pollfd a_few_on_stack[NUM_POLLS_ON_STACK];
struct pollfd *ufds = &a_few_on_stack[0];
struct curl_pollfd a_few_on_stack[NUM_POLLS_ON_STACK];
struct curl_pollfd *ufds = &a_few_on_stack[0];
if(!GOOD_MULTI_HANDLE(multi))
return CURLM_BAD_HANDLE;

View file

@ -142,9 +142,9 @@ int Curl_wait_ms(timediff_t timeout_ms)
* N = number of signalled file descriptors
*/
int Curl_select(curl_socket_t maxfd, /* highest socket number */
fd_set *fds_read, /* sockets ready for reading */
fd_set *fds_write, /* sockets ready for writing */
fd_set *fds_err, /* sockets with errors */
curl_fd_set *fds_read, /* sockets ready for reading */
curl_fd_set *fds_write, /* sockets ready for writing */
curl_fd_set *fds_err, /* sockets with errors */
timediff_t timeout_ms) /* milliseconds to wait */
{
struct timeval pending_tv;
@ -215,6 +215,13 @@ int Curl_select(curl_socket_t maxfd, /* highest socket number */
fds_read && fds_read->fd_count ? fds_read : NULL,
fds_write && fds_write->fd_count ? fds_write : NULL,
fds_err && fds_err->fd_count ? fds_err : NULL, ptimeout);
#elif defined(FreeRTOS)
{
/* convert the timeout to FreeRTOS ticks */
TickType_t ticks = ptimeout ? ptimeout->tv_sec * configTICK_RATE_HZ : +
(ptimeout->tv_usec * configTICK_RATE_HZ) / 1000000;
r = FreeRTOS_select(fds_read, ticks);
}
#else
r = select((int)maxfd + 1, fds_read, fds_write, fds_err, ptimeout);
#endif
@ -251,9 +258,11 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
struct pollfd pfd[3];
int num;
#else
fd_set fds_read;
fd_set fds_write;
fd_set fds_err;
struct timeval pending_tv;
struct timeval *ptimeout;
curl_fd_set fds_read;
curl_fd_set fds_write;
curl_fd_set fds_err;
curl_socket_t maxfd;
#endif
int r;
@ -322,6 +331,19 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
return ret;
#else /* HAVE_POLL_FINE */
#if defined(FreeRTOS)
/* using its weirdo select() */
fds_read = FreeRTOS_CreateSocketSet();
maxfd = (curl_socket_t)-1;
if(readfd0 != CURL_SOCKET_BAD)
CURL_FD_SET(readfd0, &fds_read, eSELECT_READ);
if(readfd1 != CURL_SOCKET_BAD)
CURL_FD_SET(readfd1, &fds_read, eSELECT_READ);
if(writefd != CURL_SOCKET_BAD)
CURL_FD_SET(writefd, &fds_read, eSELECT_WRITE);
#else /* HAVE_POLL_FINE */
FD_ZERO(&fds_err);
@ -350,6 +372,7 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
if(writefd > maxfd)
maxfd = writefd;
}
#endif
/* We know that we have at least one bit set in at least two fd_sets in
this case, but we may have no bits set in either fds_read or fd_write,
@ -369,6 +392,16 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
return 0;
ret = 0;
#ifdef FreeRTOS
if(r) {
if((readfd0 != CURL_SOCKET_BAD) && FreeRTOS_FD_ISSET(readfd0, fds_read))
ret |= CURL_CSELECT_IN;
if((readfd1 != CURL_SOCKET_BAD) && FreeRTOS_FD_ISSET(readfd1, fds_read))
ret |= CURL_CSELECT_IN2;
if((writefd != CURL_SOCKET_BAD) && FreeRTOS_FD_ISSET(writefd, fds_read))
ret |= CURL_CSELECT_OUT;
}
#else
if(readfd0 != CURL_SOCKET_BAD) {
if(FD_ISSET(readfd0, &fds_read))
ret |= CURL_CSELECT_IN;
@ -387,11 +420,11 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
if(FD_ISSET(writefd, &fds_err))
ret |= CURL_CSELECT_ERR;
}
#endif
return ret;
#endif /* HAVE_POLL_FINE */
}
/*
@ -412,11 +445,11 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms)
#ifdef HAVE_POLL_FINE
int pending_ms;
#else
fd_set fds_read;
fd_set fds_write;
fd_set fds_err;
curl_socket_t maxfd;
curl_fd_set fds_read;
curl_fd_set fds_write;
curl_fd_set fds_err;
#endif
curl_socket_t maxfd;
bool fds_none = TRUE;
unsigned int i;
int r;
@ -441,12 +474,6 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms)
value indicating a blocking call should be performed. */
#ifdef HAVE_POLL_FINE
/* prevent overflow, timeout_ms is typecast to int. */
#if TIMEDIFF_T_MAX > INT_MAX
if(timeout_ms > INT_MAX)
timeout_ms = INT_MAX;
#endif
if(timeout_ms > 0)
pending_ms = (int)timeout_ms;
else if(timeout_ms < 0)
@ -471,6 +498,26 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms)
#else /* HAVE_POLL_FINE */
#ifdef FreeRTOS
fds_read = FreeRTOS_CreateSocketSet();
maxfd = (curl_socket_t)-1;
for(i = 0; i < nfds; i++) {
ufds[i].revents = 0;
if(ufds[i].fd == CURL_SOCKET_BAD)
continue;
VERIFY_SOCK(ufds[i].fd);
if(ufds[i].events & (POLLIN|POLLOUT|POLLPRI|
POLLRDNORM|POLLWRNORM|POLLRDBAND)) {
if(ufds[i].fd > maxfd)
maxfd = ufds[i].fd;
if(ufds[i].events & (POLLRDNORM|POLLIN))
CURL_FD_SET(ufds[i].fd, &fds_read, eSELECT_READ);
if(ufds[i].events & (POLLWRNORM|POLLOUT))
CURL_FD_SET(ufds[i].fd, &fds_read, eSELECT_WRITE);
}
}
#else
FD_ZERO(&fds_read);
FD_ZERO(&fds_write);
FD_ZERO(&fds_err);
@ -493,6 +540,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms)
FD_SET(ufds[i].fd, &fds_err);
}
}
#endif
r = Curl_select(maxfd, &fds_read, &fds_write, &fds_err, timeout_ms);
@ -506,12 +554,19 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms)
ufds[i].revents = 0;
if(ufds[i].fd == CURL_SOCKET_BAD)
continue;
#ifdef FreeRTOS
if((ufds[i].events & POLLIN) && FreeRTOS_FD_ISSET(ufds[i].fd, fds_read))
ufds[i].revents |= POLLIN;
if((ufds[i].events & POLLOUT) && FreeRTOS_FD_ISSET(ufds[i].fd, fds_read))
ufds[i].revents |= POLLOUT;
#else
if(FD_ISSET(ufds[i].fd, &fds_read))
ufds[i].revents |= POLLIN;
if(FD_ISSET(ufds[i].fd, &fds_write))
ufds[i].revents |= POLLOUT;
if(FD_ISSET(ufds[i].fd, &fds_err))
ufds[i].revents |= POLLPRI;
#endif
if(ufds[i].revents != 0)
r++;
}

View file

@ -73,9 +73,9 @@ struct pollfd
#define CURL_CSELECT_IN2 (CURL_CSELECT_ERR << 1)
int Curl_select(curl_socket_t maxfd,
fd_set *fds_read,
fd_set *fds_write,
fd_set *fds_err,
curl_fd_set *fds_read,
curl_fd_set *fds_write,
curl_fd_set *fds_err,
timediff_t timeout_ms);
int Curl_socket_check(curl_socket_t readfd, curl_socket_t readfd2,
@ -97,7 +97,7 @@ int tpf_select_libcurl(int maxfds, fd_set* reads, fd_set* writes,
/* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1], which
unfortunately makes it impossible for us to easily check if they're valid
*/
#if defined(USE_WINSOCK) || defined(TPF)
#if defined(USE_WINSOCK) || defined(TPF) || defined(FreeRTOS)
#define VALID_SOCK(x) 1
#define VERIFY_SOCK(x) Curl_nop_stmt
#else

View file

@ -25,6 +25,7 @@
/* This file is for lib internal stuff */
#include "curl_setup.h"
#include <curl/curl.h>
#define PORT_FTP 21
#define PORT_FTPS 990