Merge branch 'bugfix/fix_lwip_macros' into 'master'
lwip: Change socket API macros to static-inline See merge request !1614
This commit is contained in:
commit
cc600bd517
4 changed files with 160 additions and 112 deletions
|
@ -558,62 +558,110 @@ int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptse
|
||||||
int lwip_ioctl_r(int s, long cmd, void *argp);
|
int lwip_ioctl_r(int s, long cmd, void *argp);
|
||||||
int lwip_fcntl_r(int s, int cmd, int val);
|
int lwip_fcntl_r(int s, int cmd, int val);
|
||||||
|
|
||||||
#define accept(s,addr,addrlen) lwip_accept_r(s,addr,addrlen)
|
static inline int accept(int s,struct sockaddr *addr,socklen_t *addrlen)
|
||||||
#define bind(s,name,namelen) lwip_bind_r(s,name,namelen)
|
{ return lwip_accept_r(s,addr,addrlen); }
|
||||||
#define shutdown(s,how) lwip_shutdown_r(s,how)
|
static inline int bind(int s,const struct sockaddr *name, socklen_t namelen)
|
||||||
#define getpeername(s,name,namelen) lwip_getpeername_r(s,name,namelen)
|
{ return lwip_bind_r(s,name,namelen); }
|
||||||
#define getsockname(s,name,namelen) lwip_getsockname_r(s,name,namelen)
|
static inline int shutdown(int s,int how)
|
||||||
#define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt_r(s,level,optname,opval,optlen)
|
{ return lwip_shutdown_r(s,how); }
|
||||||
#define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt_r(s,level,optname,opval,optlen)
|
static inline int getpeername(int s,struct sockaddr *name,socklen_t *namelen)
|
||||||
#define closesocket(s) lwip_close_r(s)
|
{ return lwip_getpeername_r(s,name,namelen); }
|
||||||
#define connect(s,name,namelen) lwip_connect_r(s,name,namelen)
|
static inline int getsockname(int s,struct sockaddr *name,socklen_t *namelen)
|
||||||
#define listen(s,backlog) lwip_listen_r(s,backlog)
|
{ return lwip_getsockname_r(s,name,namelen); }
|
||||||
#define recv(s,mem,len,flags) lwip_recv_r(s,mem,len,flags)
|
static inline int setsockopt(int s,int level,int optname,const void *opval,socklen_t optlen)
|
||||||
#define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom_r(s,mem,len,flags,from,fromlen)
|
{ return lwip_setsockopt_r(s,level,optname,opval,optlen); }
|
||||||
#define send(s,dataptr,size,flags) lwip_send_r(s,dataptr,size,flags)
|
static inline int getsockopt(int s,int level,int optname,void *opval,socklen_t *optlen)
|
||||||
#define sendmsg(s,message,flags) lwip_sendmsg_r(s,message,flags)
|
{ return lwip_getsockopt_r(s,level,optname,opval,optlen); }
|
||||||
#define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto_r(s,dataptr,size,flags,to,tolen)
|
static inline int closesocket(int s)
|
||||||
#define socket(domain,type,protocol) lwip_socket(domain,type,protocol)
|
{ return lwip_close_r(s); }
|
||||||
#define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout)
|
static inline int connect(int s,const struct sockaddr *name,socklen_t namelen)
|
||||||
#define ioctlsocket(s,cmd,argp) lwip_ioctl_r(s,cmd,argp)
|
{ return lwip_connect_r(s,name,namelen); }
|
||||||
|
static inline int listen(int s,int backlog)
|
||||||
|
{ return lwip_listen_r(s,backlog); }
|
||||||
|
static inline int recv(int s,void *mem,size_t len,int flags)
|
||||||
|
{ return lwip_recv_r(s,mem,len,flags); }
|
||||||
|
static inline int recvfrom(int s,void *mem,size_t len,int flags,struct sockaddr *from,socklen_t *fromlen)
|
||||||
|
{ return lwip_recvfrom_r(s,mem,len,flags,from,fromlen); }
|
||||||
|
static inline int send(int s,const void *dataptr,size_t size,int flags)
|
||||||
|
{ return lwip_send_r(s,dataptr,size,flags); }
|
||||||
|
static inline int sendmsg(int s,const struct msghdr *message,int flags)
|
||||||
|
{ return lwip_sendmsg_r(s,message,flags); }
|
||||||
|
static inline int sendto(int s,const void *dataptr,size_t size,int flags,const struct sockaddr *to,socklen_t tolen)
|
||||||
|
{ return lwip_sendto_r(s,dataptr,size,flags,to,tolen); }
|
||||||
|
static inline int socket(int domain,int type,int protocol)
|
||||||
|
{ return lwip_socket(domain,type,protocol); }
|
||||||
|
static inline int select(int maxfdp1,fd_set *readset,fd_set *writeset,fd_set *exceptset,struct timeval *timeout)
|
||||||
|
{ return lwip_select(maxfdp1,readset,writeset,exceptset,timeout); }
|
||||||
|
static inline int ioctlsocket(int s,long cmd,void *argp)
|
||||||
|
{ return lwip_ioctl_r(s,cmd,argp); }
|
||||||
|
|
||||||
#if LWIP_POSIX_SOCKETS_IO_NAMES
|
#if LWIP_POSIX_SOCKETS_IO_NAMES
|
||||||
#define read(s,mem,len) lwip_read_r(s,mem,len)
|
static inline int read(int s,void *mem,size_t len)
|
||||||
#define write(s,dataptr,len) lwip_write_r(s,dataptr,len)
|
{ return lwip_read_r(s,mem,len); }
|
||||||
#define writev(s,iov,iovcnt) lwip_writev_r(s,iov,iovcnt)
|
static inline int write(int s,const void *dataptr,size_t len)
|
||||||
#define close(s) lwip_close_r(s)
|
{ return lwip_write_r(s,dataptr,len); }
|
||||||
#define fcntl(s,cmd,val) lwip_fcntl_r(s,cmd,val)
|
static inline int writev(int s,const struct iovec *iov,int iovcnt)
|
||||||
#define ioctl(s,cmd,argp) lwip_ioctl_r(s,cmd,argp)
|
{ return lwip_writev_r(s,iov,iovcnt); }
|
||||||
#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
|
static inline int close(int s)
|
||||||
|
{ return lwip_close_r(s); }
|
||||||
|
static inline int fcntl(int s,int cmd,int val)
|
||||||
|
{ return lwip_fcntl_r(s,cmd,val); }
|
||||||
|
static inline int ioctl(int s,long cmd,void *argp)
|
||||||
|
{ return lwip_ioctl_r(s,cmd,argp); }
|
||||||
|
#endif /* { RETURN LWIP_POSIX_SOCKETS_IO_NAMES */
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen)
|
static inline int accept(int s,struct sockaddr *addr,socklen_t *addrlen)
|
||||||
#define bind(s,name,namelen) lwip_bind(s,name,namelen)
|
{ return lwip_accept(s,addr,addrlen); }
|
||||||
#define shutdown(s,how) lwip_shutdown(s,how)
|
static inline int bind(int s,const struct sockaddr *name,socklen_t namelen)
|
||||||
#define getpeername(s,name,namelen) lwip_getpeername(s,name,namelen)
|
{ return lwip_bind(s,name,namelen); }
|
||||||
#define getsockname(s,name,namelen) lwip_getsockname(s,name,namelen)
|
static inline int shutdown(int s,int how)
|
||||||
#define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt(s,level,optname,opval,optlen)
|
{ return lwip_shutdown(s,how); }
|
||||||
#define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt(s,level,optname,opval,optlen)
|
static inline int getpeername(int s,struct sockaddr *name,socklen_t *namelen)
|
||||||
#define closesocket(s) lwip_close(s)
|
{ return lwip_getpeername(s,name,namelen); }
|
||||||
#define connect(s,name,namelen) lwip_connect(s,name,namelen)
|
static inline int getsockname(int s,struct sockaddr *name,socklen_t *namelen)
|
||||||
#define listen(s,backlog) lwip_listen(s,backlog)
|
{ return lwip_getsockname(s,name,namelen); }
|
||||||
#define recv(s,mem,len,flags) lwip_recv(s,mem,len,flags)
|
static inline int setsockopt(int s,int level,int optname,const void *opval,socklen_t optlen)
|
||||||
#define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom(s,mem,len,flags,from,fromlen)
|
{ return lwip_setsockopt(s,level,optname,opval,optlen); }
|
||||||
#define send(s,dataptr,size,flags) lwip_send(s,dataptr,size,flags)
|
static inline int getsockopt(int s,int level,int optname,void *opval,socklen_t *optlen)
|
||||||
#define sendmsg(s,message,flags) lwip_sendmsg(s,message,flags)
|
{ return lwip_getsockopt(s,level,optname,opval,optlen); }
|
||||||
#define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto(s,dataptr,size,flags,to,tolen)
|
static inline int closesocket(int s)
|
||||||
#define socket(domain,type,protocol) lwip_socket(domain,type,protocol)
|
{ return lwip_close(s); }
|
||||||
#define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout)
|
static inline int connect(int s,const struct sockaddr *name,socklen_t namelen)
|
||||||
#define ioctlsocket(s,cmd,argp) lwip_ioctl(s,cmd,argp)
|
{ return lwip_connect(s,name,namelen); }
|
||||||
|
static inline int listen(int s,int backlog)
|
||||||
|
{ return lwip_listen(s,backlog); }
|
||||||
|
static inline int recv(int s,void *mem,size_t len,int flags)
|
||||||
|
{ return lwip_recv(s,mem,len,flags); }
|
||||||
|
static inline int recvfrom(int s,void *mem,size_t len,int flags,struct sockaddr *from,socklen_t *fromlen)
|
||||||
|
{ return lwip_recvfrom(s,mem,len,flags,from,fromlen); }
|
||||||
|
static inline int send(int s,const void *dataptr,size_t size,int flags)
|
||||||
|
{ return lwip_send(s,dataptr,size,flags); }
|
||||||
|
static inline int sendmsg(int s,const struct msghdr *message,int flags)
|
||||||
|
{ return lwip_sendmsg(s,message,flags); }
|
||||||
|
static inline int sendto(int s,const void *dataptr,size_t size,int flags,const struct sockaddr *to,socklen_t tolen)
|
||||||
|
{ return lwip_sendto(s,dataptr,size,flags,to,tolen); }
|
||||||
|
static inline int socket(int domain,int type,int protocol)
|
||||||
|
{ return lwip_socket(domain,type,protocol); }
|
||||||
|
static inline int select(int maxfdp1,fd_set t*readset,fd_set *writeset,fd_set *exceptset,struct timeval *timeout)
|
||||||
|
{ return lwip_select(maxfdp1,readset,writeset,exceptset,timeout); }
|
||||||
|
static inline int ioctlsocket(int s,long cmd,void *argp)
|
||||||
|
{ return lwip_ioctl(s,cmd,argp); }
|
||||||
|
|
||||||
#if LWIP_POSIX_SOCKETS_IO_NAMES
|
#if LWIP_POSIX_SOCKETS_IO_NAMES
|
||||||
#define read(s,mem,len) lwip_read(s,mem,len)
|
static inline int read(int s,void *mem,size_t len)
|
||||||
#define write(s,dataptr,len) lwip_write(s,dataptr,len)
|
{ return lwip_read(s,mem,len); }
|
||||||
#define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt)
|
static inline int write(int s,const void *dataptr,size_t len)
|
||||||
#define close(s) lwip_close(s)
|
{ return lwip_write(s,dataptr,len); }
|
||||||
#define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val)
|
static inline int writev(int s,const struct iovec *iov,int iovcnt)
|
||||||
#define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp)
|
{ return lwip_writev(s,iov,iovcnt); }
|
||||||
|
static inline int close(int s)
|
||||||
|
{ return lwip_close(s); }
|
||||||
|
static inline int fcntl(int s,long cmd,void *val)
|
||||||
|
{ return lwip_fcntl(s,cmd,val); }
|
||||||
|
static inline int ioctl(int s,int cmd,int argp)
|
||||||
|
{ return lwip_ioctl(s,cmd,argp); }
|
||||||
#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
|
#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
|
||||||
#endif /* ESP_THREAD_SAFE */
|
#endif /* ESP_THREAD_SAFE */
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ static void openssl_example_task(void *p)
|
||||||
int ret;
|
int ret;
|
||||||
SSL_CTX *ctx;
|
SSL_CTX *ctx;
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
int socket;
|
int sockfd;
|
||||||
struct sockaddr_in sock_addr;
|
struct sockaddr_in sock_addr;
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
struct ip4_addr *ip4_addr;
|
struct ip4_addr *ip4_addr;
|
||||||
|
@ -73,8 +73,8 @@ static void openssl_example_task(void *p)
|
||||||
ESP_LOGI(TAG, "OK");
|
ESP_LOGI(TAG, "OK");
|
||||||
|
|
||||||
ESP_LOGI(TAG, "create socket ......");
|
ESP_LOGI(TAG, "create socket ......");
|
||||||
socket = socket(AF_INET, SOCK_STREAM, 0);
|
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (socket < 0) {
|
if (sockfd < 0) {
|
||||||
ESP_LOGI(TAG, "failed");
|
ESP_LOGI(TAG, "failed");
|
||||||
goto failed2;
|
goto failed2;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ static void openssl_example_task(void *p)
|
||||||
sock_addr.sin_family = AF_INET;
|
sock_addr.sin_family = AF_INET;
|
||||||
sock_addr.sin_addr.s_addr = 0;
|
sock_addr.sin_addr.s_addr = 0;
|
||||||
sock_addr.sin_port = htons(OPENSSL_EXAMPLE_LOCAL_TCP_PORT);
|
sock_addr.sin_port = htons(OPENSSL_EXAMPLE_LOCAL_TCP_PORT);
|
||||||
ret = bind(socket, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
|
ret = bind(sockfd, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ESP_LOGI(TAG, "failed");
|
ESP_LOGI(TAG, "failed");
|
||||||
goto failed3;
|
goto failed3;
|
||||||
|
@ -97,7 +97,7 @@ static void openssl_example_task(void *p)
|
||||||
sock_addr.sin_family = AF_INET;
|
sock_addr.sin_family = AF_INET;
|
||||||
sock_addr.sin_addr.s_addr = ip4_addr->addr;
|
sock_addr.sin_addr.s_addr = ip4_addr->addr;
|
||||||
sock_addr.sin_port = htons(OPENSSL_EXAMPLE_TARGET_TCP_PORT);
|
sock_addr.sin_port = htons(OPENSSL_EXAMPLE_TARGET_TCP_PORT);
|
||||||
ret = connect(socket, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
|
ret = connect(sockfd, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ESP_LOGI(TAG, "failed");
|
ESP_LOGI(TAG, "failed");
|
||||||
goto failed3;
|
goto failed3;
|
||||||
|
@ -112,7 +112,7 @@ static void openssl_example_task(void *p)
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "OK");
|
ESP_LOGI(TAG, "OK");
|
||||||
|
|
||||||
SSL_set_fd(ssl, socket);
|
SSL_set_fd(ssl, sockfd);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "SSL connected to %s port %d ......",
|
ESP_LOGI(TAG, "SSL connected to %s port %d ......",
|
||||||
OPENSSL_EXAMPLE_TARGET_NAME, OPENSSL_EXAMPLE_TARGET_TCP_PORT);
|
OPENSSL_EXAMPLE_TARGET_NAME, OPENSSL_EXAMPLE_TARGET_TCP_PORT);
|
||||||
|
@ -150,8 +150,8 @@ failed4:
|
||||||
SSL_free(ssl);
|
SSL_free(ssl);
|
||||||
ssl = NULL;
|
ssl = NULL;
|
||||||
failed3:
|
failed3:
|
||||||
close(socket);
|
close(sockfd);
|
||||||
socket = -1;
|
sockfd = -1;
|
||||||
failed2:
|
failed2:
|
||||||
SSL_CTX_free(ctx);
|
SSL_CTX_free(ctx);
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
|
|
|
@ -53,7 +53,7 @@ static void openssl_example_task(void *p)
|
||||||
SSL_CTX *ctx;
|
SSL_CTX *ctx;
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
|
|
||||||
int socket, new_socket;
|
int sockfd, new_sockfd;
|
||||||
socklen_t addr_len;
|
socklen_t addr_len;
|
||||||
struct sockaddr_in sock_addr;
|
struct sockaddr_in sock_addr;
|
||||||
|
|
||||||
|
@ -99,8 +99,8 @@ static void openssl_example_task(void *p)
|
||||||
ESP_LOGI(TAG, "OK");
|
ESP_LOGI(TAG, "OK");
|
||||||
|
|
||||||
ESP_LOGI(TAG, "SSL server create socket ......");
|
ESP_LOGI(TAG, "SSL server create socket ......");
|
||||||
socket = socket(AF_INET, SOCK_STREAM, 0);
|
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (socket < 0) {
|
if (sockfd < 0) {
|
||||||
ESP_LOGI(TAG, "failed");
|
ESP_LOGI(TAG, "failed");
|
||||||
goto failed2;
|
goto failed2;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ static void openssl_example_task(void *p)
|
||||||
sock_addr.sin_family = AF_INET;
|
sock_addr.sin_family = AF_INET;
|
||||||
sock_addr.sin_addr.s_addr = 0;
|
sock_addr.sin_addr.s_addr = 0;
|
||||||
sock_addr.sin_port = htons(OPENSSL_EXAMPLE_LOCAL_TCP_PORT);
|
sock_addr.sin_port = htons(OPENSSL_EXAMPLE_LOCAL_TCP_PORT);
|
||||||
ret = bind(socket, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
|
ret = bind(sockfd, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ESP_LOGI(TAG, "failed");
|
ESP_LOGI(TAG, "failed");
|
||||||
goto failed3;
|
goto failed3;
|
||||||
|
@ -119,7 +119,7 @@ static void openssl_example_task(void *p)
|
||||||
ESP_LOGI(TAG, "OK");
|
ESP_LOGI(TAG, "OK");
|
||||||
|
|
||||||
ESP_LOGI(TAG, "SSL server socket listen ......");
|
ESP_LOGI(TAG, "SSL server socket listen ......");
|
||||||
ret = listen(socket, 32);
|
ret = listen(sockfd, 32);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ESP_LOGI(TAG, "failed");
|
ESP_LOGI(TAG, "failed");
|
||||||
goto failed3;
|
goto failed3;
|
||||||
|
@ -136,14 +136,14 @@ reconnect:
|
||||||
ESP_LOGI(TAG, "OK");
|
ESP_LOGI(TAG, "OK");
|
||||||
|
|
||||||
ESP_LOGI(TAG, "SSL server socket accept client ......");
|
ESP_LOGI(TAG, "SSL server socket accept client ......");
|
||||||
new_socket = accept(socket, (struct sockaddr *)&sock_addr, &addr_len);
|
new_sockfd = accept(sockfd, (struct sockaddr *)&sock_addr, &addr_len);
|
||||||
if (new_socket < 0) {
|
if (new_sockfd < 0) {
|
||||||
ESP_LOGI(TAG, "failed" );
|
ESP_LOGI(TAG, "failed" );
|
||||||
goto failed4;
|
goto failed4;
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "OK");
|
ESP_LOGI(TAG, "OK");
|
||||||
|
|
||||||
SSL_set_fd(ssl, new_socket);
|
SSL_set_fd(ssl, new_sockfd);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "SSL server accept client ......");
|
ESP_LOGI(TAG, "SSL server accept client ......");
|
||||||
ret = SSL_accept(ssl);
|
ret = SSL_accept(ssl);
|
||||||
|
@ -177,15 +177,15 @@ reconnect:
|
||||||
|
|
||||||
SSL_shutdown(ssl);
|
SSL_shutdown(ssl);
|
||||||
failed5:
|
failed5:
|
||||||
close(new_socket);
|
close(new_sockfd);
|
||||||
new_socket = -1;
|
new_sockfd = -1;
|
||||||
failed4:
|
failed4:
|
||||||
SSL_free(ssl);
|
SSL_free(ssl);
|
||||||
ssl = NULL;
|
ssl = NULL;
|
||||||
goto reconnect;
|
goto reconnect;
|
||||||
failed3:
|
failed3:
|
||||||
close(socket);
|
close(sockfd);
|
||||||
socket = -1;
|
sockfd = -1;
|
||||||
failed2:
|
failed2:
|
||||||
SSL_CTX_free(ctx);
|
SSL_CTX_free(ctx);
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
|
|
|
@ -20,7 +20,7 @@ typedef struct {
|
||||||
uint32_t total_len;
|
uint32_t total_len;
|
||||||
uint32_t buffer_len;
|
uint32_t buffer_len;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
uint32_t socket;
|
uint32_t sockfd;
|
||||||
} iperf_ctrl_t;
|
} iperf_ctrl_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -53,13 +53,13 @@ inline static bool iperf_is_tcp_server(void)
|
||||||
return ((s_iperf_ctrl.cfg.flag & IPERF_FLAG_SERVER) && (s_iperf_ctrl.cfg.flag & IPERF_FLAG_TCP));
|
return ((s_iperf_ctrl.cfg.flag & IPERF_FLAG_SERVER) && (s_iperf_ctrl.cfg.flag & IPERF_FLAG_TCP));
|
||||||
}
|
}
|
||||||
|
|
||||||
int iperf_get_socket_error_code(int socket)
|
int iperf_get_socket_error_code(int sockfd)
|
||||||
{
|
{
|
||||||
uint32_t optlen = sizeof(int);
|
uint32_t optlen = sizeof(int);
|
||||||
int result;
|
int result;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = getsockopt(socket, SOL_SOCKET, SO_ERROR, &result, &optlen);
|
err = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &result, &optlen);
|
||||||
if (err == -1) {
|
if (err == -1) {
|
||||||
ESP_LOGE(TAG, "getsockopt failed: ret=%d", err);
|
ESP_LOGE(TAG, "getsockopt failed: ret=%d", err);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -68,9 +68,9 @@ int iperf_get_socket_error_code(int socket)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int iperf_show_socket_error_reason(const char *str, int socket)
|
int iperf_show_socket_error_reason(const char *str, int sockfd)
|
||||||
{
|
{
|
||||||
int err = iperf_get_socket_error_code(socket);
|
int err = iperf_get_socket_error_code(sockfd);
|
||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
ESP_LOGW(TAG, "%s error, error code: %d, reason: %s", str, err, strerror(err));
|
ESP_LOGW(TAG, "%s error, error code: %d, reason: %s", str, err, strerror(err));
|
||||||
|
@ -129,7 +129,7 @@ esp_err_t iperf_run_tcp_server(void)
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
int listen_socket;
|
int listen_socket;
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
int socket;
|
int sockfd;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
listen_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
listen_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
|
@ -161,8 +161,8 @@ esp_err_t iperf_run_tcp_server(void)
|
||||||
while (!s_iperf_ctrl.finish) {
|
while (!s_iperf_ctrl.finish) {
|
||||||
|
|
||||||
/*TODO need to change to non-block mode */
|
/*TODO need to change to non-block mode */
|
||||||
socket = accept(listen_socket, (struct sockaddr*)&remote_addr, &addr_len);
|
sockfd = accept(listen_socket, (struct sockaddr*)&remote_addr, &addr_len);
|
||||||
if (socket < 0) {
|
if (sockfd < 0) {
|
||||||
iperf_show_socket_error_reason("tcp server listen", listen_socket);
|
iperf_show_socket_error_reason("tcp server listen", listen_socket);
|
||||||
close(listen_socket);
|
close(listen_socket);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
|
@ -170,11 +170,11 @@ esp_err_t iperf_run_tcp_server(void)
|
||||||
printf("accept: %s,%d\n", inet_ntoa(remote_addr.sin_addr), htons(remote_addr.sin_port));
|
printf("accept: %s,%d\n", inet_ntoa(remote_addr.sin_addr), htons(remote_addr.sin_port));
|
||||||
|
|
||||||
t.tv_sec = IPERF_SOCKET_RX_TIMEOUT;
|
t.tv_sec = IPERF_SOCKET_RX_TIMEOUT;
|
||||||
setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t));
|
setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!s_iperf_ctrl.finish) {
|
while (!s_iperf_ctrl.finish) {
|
||||||
actual_recv = recv(socket, buffer, want_recv, 0);
|
actual_recv = recv(sockfd, buffer, want_recv, 0);
|
||||||
if (actual_recv < 0) {
|
if (actual_recv < 0) {
|
||||||
iperf_show_socket_error_reason("tcp server recv", listen_socket);
|
iperf_show_socket_error_reason("tcp server recv", listen_socket);
|
||||||
break;
|
break;
|
||||||
|
@ -183,7 +183,7 @@ esp_err_t iperf_run_tcp_server(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(socket);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
s_iperf_ctrl.finish = true;
|
s_iperf_ctrl.finish = true;
|
||||||
|
@ -199,22 +199,22 @@ esp_err_t iperf_run_udp_server(void)
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
int want_recv = 0;
|
int want_recv = 0;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
int socket;
|
int sockfd;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if (socket < 0) {
|
if (sockfd < 0) {
|
||||||
iperf_show_socket_error_reason("udp server create", socket);
|
iperf_show_socket_error_reason("udp server create", sockfd);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||||
|
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(s_iperf_ctrl.cfg.sport);
|
addr.sin_port = htons(s_iperf_ctrl.cfg.sport);
|
||||||
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip;
|
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip;
|
||||||
if (bind(socket, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
if (bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
||||||
iperf_show_socket_error_reason("udp server bind", socket);
|
iperf_show_socket_error_reason("udp server bind", sockfd);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,19 +229,19 @@ esp_err_t iperf_run_udp_server(void)
|
||||||
ESP_LOGI(TAG, "want recv=%d", want_recv);
|
ESP_LOGI(TAG, "want recv=%d", want_recv);
|
||||||
|
|
||||||
t.tv_sec = IPERF_SOCKET_RX_TIMEOUT;
|
t.tv_sec = IPERF_SOCKET_RX_TIMEOUT;
|
||||||
setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t));
|
setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t));
|
||||||
|
|
||||||
while (!s_iperf_ctrl.finish) {
|
while (!s_iperf_ctrl.finish) {
|
||||||
actual_recv = recvfrom(socket, buffer, want_recv, 0, (struct sockaddr *)&addr, &addr_len);
|
actual_recv = recvfrom(sockfd, buffer, want_recv, 0, (struct sockaddr *)&addr, &addr_len);
|
||||||
if (actual_recv < 0) {
|
if (actual_recv < 0) {
|
||||||
iperf_show_socket_error_reason("udp server recv", socket);
|
iperf_show_socket_error_reason("udp server recv", sockfd);
|
||||||
} else {
|
} else {
|
||||||
s_iperf_ctrl.total_len += actual_recv;
|
s_iperf_ctrl.total_len += actual_recv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s_iperf_ctrl.finish = true;
|
s_iperf_ctrl.finish = true;
|
||||||
close(socket);
|
close(sockfd);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,24 +254,24 @@ esp_err_t iperf_run_udp_client(void)
|
||||||
uint32_t delay = 1;
|
uint32_t delay = 1;
|
||||||
int want_send = 0;
|
int want_send = 0;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
int socket;
|
int sockfd;
|
||||||
int opt;
|
int opt;
|
||||||
int err;
|
int err;
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if (socket < 0) {
|
if (sockfd < 0) {
|
||||||
iperf_show_socket_error_reason("udp server create", socket);
|
iperf_show_socket_error_reason("udp server create", sockfd);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||||
|
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = 0;
|
addr.sin_port = 0;
|
||||||
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip;
|
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip;
|
||||||
if (bind(socket, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
if (bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
||||||
iperf_show_socket_error_reason("udp server bind", socket);
|
iperf_show_socket_error_reason("udp server bind", sockfd);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,10 +293,10 @@ esp_err_t iperf_run_udp_client(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
retry = false;
|
retry = false;
|
||||||
actual_send = sendto(socket, buffer, want_send, 0, (struct sockaddr *)&addr, sizeof(addr));
|
actual_send = sendto(sockfd, buffer, want_send, 0, (struct sockaddr *)&addr, sizeof(addr));
|
||||||
|
|
||||||
if (actual_send != want_send) {
|
if (actual_send != want_send) {
|
||||||
err = iperf_get_socket_error_code(socket);
|
err = iperf_get_socket_error_code(sockfd);
|
||||||
if (err == ENOMEM) {
|
if (err == ENOMEM) {
|
||||||
vTaskDelay(delay);
|
vTaskDelay(delay);
|
||||||
if (delay < IPERF_MAX_DELAY) {
|
if (delay < IPERF_MAX_DELAY) {
|
||||||
|
@ -314,7 +314,7 @@ esp_err_t iperf_run_udp_client(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
s_iperf_ctrl.finish = true;
|
s_iperf_ctrl.finish = true;
|
||||||
close(socket);
|
close(sockfd);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,22 +325,22 @@ esp_err_t iperf_run_tcp_client(void)
|
||||||
int actual_send = 0;
|
int actual_send = 0;
|
||||||
int want_send = 0;
|
int want_send = 0;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
int socket;
|
int sockfd;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (socket < 0) {
|
if (sockfd < 0) {
|
||||||
iperf_show_socket_error_reason("tcp client create", socket);
|
iperf_show_socket_error_reason("tcp client create", sockfd);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||||
|
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = 0;
|
addr.sin_port = 0;
|
||||||
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip;
|
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip;
|
||||||
if (bind(socket, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
if (bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
||||||
iperf_show_socket_error_reason("tcp client bind", socket);
|
iperf_show_socket_error_reason("tcp client bind", sockfd);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,8 +348,8 @@ esp_err_t iperf_run_tcp_client(void)
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(s_iperf_ctrl.cfg.dport);
|
addr.sin_port = htons(s_iperf_ctrl.cfg.dport);
|
||||||
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.dip;
|
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.dip;
|
||||||
if (connect(socket, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
iperf_show_socket_error_reason("tcp client connect", socket);
|
iperf_show_socket_error_reason("tcp client connect", sockfd);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ esp_err_t iperf_run_tcp_client(void)
|
||||||
buffer = s_iperf_ctrl.buffer;
|
buffer = s_iperf_ctrl.buffer;
|
||||||
want_send = s_iperf_ctrl.buffer_len;
|
want_send = s_iperf_ctrl.buffer_len;
|
||||||
while (!s_iperf_ctrl.finish) {
|
while (!s_iperf_ctrl.finish) {
|
||||||
actual_send = send(socket, buffer, want_send, 0);
|
actual_send = send(sockfd, buffer, want_send, 0);
|
||||||
if (actual_send <= 0) {
|
if (actual_send <= 0) {
|
||||||
vTaskDelay(1);
|
vTaskDelay(1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -365,7 +365,7 @@ esp_err_t iperf_run_tcp_client(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(socket);
|
close(sockfd);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue