lwip: Change socket API macros to static-inline

This commit is contained in:
Kedar Sovani 2017-11-28 15:53:39 +05:30
parent e43ac33b7c
commit 1c0543fb17
4 changed files with 160 additions and 112 deletions

View File

@ -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_fcntl_r(int s, int cmd, int val);
#define accept(s,addr,addrlen) lwip_accept_r(s,addr,addrlen)
#define bind(s,name,namelen) lwip_bind_r(s,name,namelen)
#define shutdown(s,how) lwip_shutdown_r(s,how)
#define getpeername(s,name,namelen) lwip_getpeername_r(s,name,namelen)
#define getsockname(s,name,namelen) lwip_getsockname_r(s,name,namelen)
#define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt_r(s,level,optname,opval,optlen)
#define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt_r(s,level,optname,opval,optlen)
#define closesocket(s) lwip_close_r(s)
#define connect(s,name,namelen) lwip_connect_r(s,name,namelen)
#define listen(s,backlog) lwip_listen_r(s,backlog)
#define recv(s,mem,len,flags) lwip_recv_r(s,mem,len,flags)
#define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom_r(s,mem,len,flags,from,fromlen)
#define send(s,dataptr,size,flags) lwip_send_r(s,dataptr,size,flags)
#define sendmsg(s,message,flags) lwip_sendmsg_r(s,message,flags)
#define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto_r(s,dataptr,size,flags,to,tolen)
#define socket(domain,type,protocol) lwip_socket(domain,type,protocol)
#define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout)
#define ioctlsocket(s,cmd,argp) lwip_ioctl_r(s,cmd,argp)
static inline int accept(int s,struct sockaddr *addr,socklen_t *addrlen)
{ return lwip_accept_r(s,addr,addrlen); }
static inline int bind(int s,const struct sockaddr *name, socklen_t namelen)
{ return lwip_bind_r(s,name,namelen); }
static inline int shutdown(int s,int how)
{ return lwip_shutdown_r(s,how); }
static inline int getpeername(int s,struct sockaddr *name,socklen_t *namelen)
{ return lwip_getpeername_r(s,name,namelen); }
static inline int getsockname(int s,struct sockaddr *name,socklen_t *namelen)
{ return lwip_getsockname_r(s,name,namelen); }
static inline int setsockopt(int s,int level,int optname,const void *opval,socklen_t optlen)
{ return lwip_setsockopt_r(s,level,optname,opval,optlen); }
static inline int getsockopt(int s,int level,int optname,void *opval,socklen_t *optlen)
{ return lwip_getsockopt_r(s,level,optname,opval,optlen); }
static inline int closesocket(int s)
{ return lwip_close_r(s); }
static inline int connect(int s,const struct sockaddr *name,socklen_t namelen)
{ 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
#define read(s,mem,len) lwip_read_r(s,mem,len)
#define write(s,dataptr,len) lwip_write_r(s,dataptr,len)
#define writev(s,iov,iovcnt) lwip_writev_r(s,iov,iovcnt)
#define close(s) lwip_close_r(s)
#define fcntl(s,cmd,val) lwip_fcntl_r(s,cmd,val)
#define ioctl(s,cmd,argp) lwip_ioctl_r(s,cmd,argp)
#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
static inline int read(int s,void *mem,size_t len)
{ return lwip_read_r(s,mem,len); }
static inline int write(int s,const void *dataptr,size_t len)
{ return lwip_write_r(s,dataptr,len); }
static inline int writev(int s,const struct iovec *iov,int iovcnt)
{ return lwip_writev_r(s,iov,iovcnt); }
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
#define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen)
#define bind(s,name,namelen) lwip_bind(s,name,namelen)
#define shutdown(s,how) lwip_shutdown(s,how)
#define getpeername(s,name,namelen) lwip_getpeername(s,name,namelen)
#define getsockname(s,name,namelen) lwip_getsockname(s,name,namelen)
#define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt(s,level,optname,opval,optlen)
#define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt(s,level,optname,opval,optlen)
#define closesocket(s) lwip_close(s)
#define connect(s,name,namelen) lwip_connect(s,name,namelen)
#define listen(s,backlog) lwip_listen(s,backlog)
#define recv(s,mem,len,flags) lwip_recv(s,mem,len,flags)
#define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom(s,mem,len,flags,from,fromlen)
#define send(s,dataptr,size,flags) lwip_send(s,dataptr,size,flags)
#define sendmsg(s,message,flags) lwip_sendmsg(s,message,flags)
#define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto(s,dataptr,size,flags,to,tolen)
#define socket(domain,type,protocol) lwip_socket(domain,type,protocol)
#define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout)
#define ioctlsocket(s,cmd,argp) lwip_ioctl(s,cmd,argp)
static inline int accept(int s,struct sockaddr *addr,socklen_t *addrlen)
{ return lwip_accept(s,addr,addrlen); }
static inline int bind(int s,const struct sockaddr *name,socklen_t namelen)
{ return lwip_bind(s,name,namelen); }
static inline int shutdown(int s,int how)
{ return lwip_shutdown(s,how); }
static inline int getpeername(int s,struct sockaddr *name,socklen_t *namelen)
{ return lwip_getpeername(s,name,namelen); }
static inline int getsockname(int s,struct sockaddr *name,socklen_t *namelen)
{ return lwip_getsockname(s,name,namelen); }
static inline int setsockopt(int s,int level,int optname,const void *opval,socklen_t optlen)
{ return lwip_setsockopt(s,level,optname,opval,optlen); }
static inline int getsockopt(int s,int level,int optname,void *opval,socklen_t *optlen)
{ return lwip_getsockopt(s,level,optname,opval,optlen); }
static inline int closesocket(int s)
{ return lwip_close(s); }
static inline int connect(int s,const struct sockaddr *name,socklen_t namelen)
{ 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
#define read(s,mem,len) lwip_read(s,mem,len)
#define write(s,dataptr,len) lwip_write(s,dataptr,len)
#define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt)
#define close(s) lwip_close(s)
#define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val)
#define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp)
static inline int read(int s,void *mem,size_t len)
{ return lwip_read(s,mem,len); }
static inline int write(int s,const void *dataptr,size_t len)
{ return lwip_write(s,dataptr,len); }
static inline int writev(int s,const struct iovec *iov,int iovcnt)
{ 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 /* ESP_THREAD_SAFE */

View File

@ -40,7 +40,7 @@ static void openssl_example_task(void *p)
int ret;
SSL_CTX *ctx;
SSL *ssl;
int socket;
int sockfd;
struct sockaddr_in sock_addr;
struct hostent *hp;
struct ip4_addr *ip4_addr;
@ -73,8 +73,8 @@ static void openssl_example_task(void *p)
ESP_LOGI(TAG, "OK");
ESP_LOGI(TAG, "create socket ......");
socket = socket(AF_INET, SOCK_STREAM, 0);
if (socket < 0) {
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
ESP_LOGI(TAG, "failed");
goto failed2;
}
@ -85,7 +85,7 @@ static void openssl_example_task(void *p)
sock_addr.sin_family = AF_INET;
sock_addr.sin_addr.s_addr = 0;
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) {
ESP_LOGI(TAG, "failed");
goto failed3;
@ -97,7 +97,7 @@ static void openssl_example_task(void *p)
sock_addr.sin_family = AF_INET;
sock_addr.sin_addr.s_addr = ip4_addr->addr;
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) {
ESP_LOGI(TAG, "failed");
goto failed3;
@ -112,7 +112,7 @@ static void openssl_example_task(void *p)
}
ESP_LOGI(TAG, "OK");
SSL_set_fd(ssl, socket);
SSL_set_fd(ssl, sockfd);
ESP_LOGI(TAG, "SSL connected to %s port %d ......",
OPENSSL_EXAMPLE_TARGET_NAME, OPENSSL_EXAMPLE_TARGET_TCP_PORT);
@ -150,8 +150,8 @@ failed4:
SSL_free(ssl);
ssl = NULL;
failed3:
close(socket);
socket = -1;
close(sockfd);
sockfd = -1;
failed2:
SSL_CTX_free(ctx);
ctx = NULL;

View File

@ -53,7 +53,7 @@ static void openssl_example_task(void *p)
SSL_CTX *ctx;
SSL *ssl;
int socket, new_socket;
int sockfd, new_sockfd;
socklen_t addr_len;
struct sockaddr_in sock_addr;
@ -99,8 +99,8 @@ static void openssl_example_task(void *p)
ESP_LOGI(TAG, "OK");
ESP_LOGI(TAG, "SSL server create socket ......");
socket = socket(AF_INET, SOCK_STREAM, 0);
if (socket < 0) {
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
ESP_LOGI(TAG, "failed");
goto failed2;
}
@ -111,7 +111,7 @@ static void openssl_example_task(void *p)
sock_addr.sin_family = AF_INET;
sock_addr.sin_addr.s_addr = 0;
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) {
ESP_LOGI(TAG, "failed");
goto failed3;
@ -119,7 +119,7 @@ static void openssl_example_task(void *p)
ESP_LOGI(TAG, "OK");
ESP_LOGI(TAG, "SSL server socket listen ......");
ret = listen(socket, 32);
ret = listen(sockfd, 32);
if (ret) {
ESP_LOGI(TAG, "failed");
goto failed3;
@ -136,14 +136,14 @@ reconnect:
ESP_LOGI(TAG, "OK");
ESP_LOGI(TAG, "SSL server socket accept client ......");
new_socket = accept(socket, (struct sockaddr *)&sock_addr, &addr_len);
if (new_socket < 0) {
new_sockfd = accept(sockfd, (struct sockaddr *)&sock_addr, &addr_len);
if (new_sockfd < 0) {
ESP_LOGI(TAG, "failed" );
goto failed4;
}
ESP_LOGI(TAG, "OK");
SSL_set_fd(ssl, new_socket);
SSL_set_fd(ssl, new_sockfd);
ESP_LOGI(TAG, "SSL server accept client ......");
ret = SSL_accept(ssl);
@ -177,15 +177,15 @@ reconnect:
SSL_shutdown(ssl);
failed5:
close(new_socket);
new_socket = -1;
close(new_sockfd);
new_sockfd = -1;
failed4:
SSL_free(ssl);
ssl = NULL;
goto reconnect;
failed3:
close(socket);
socket = -1;
close(sockfd);
sockfd = -1;
failed2:
SSL_CTX_free(ctx);
ctx = NULL;

View File

@ -20,7 +20,7 @@ typedef struct {
uint32_t total_len;
uint32_t buffer_len;
uint8_t *buffer;
uint32_t socket;
uint32_t sockfd;
} iperf_ctrl_t;
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));
}
int iperf_get_socket_error_code(int socket)
int iperf_get_socket_error_code(int sockfd)
{
uint32_t optlen = sizeof(int);
int result;
int err;
err = getsockopt(socket, SOL_SOCKET, SO_ERROR, &result, &optlen);
err = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &result, &optlen);
if (err == -1) {
ESP_LOGE(TAG, "getsockopt failed: ret=%d", err);
return -1;
@ -68,9 +68,9 @@ int iperf_get_socket_error_code(int socket)
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) {
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;
int listen_socket;
struct timeval t;
int socket;
int sockfd;
int opt;
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) {
/*TODO need to change to non-block mode */
socket = accept(listen_socket, (struct sockaddr*)&remote_addr, &addr_len);
if (socket < 0) {
sockfd = accept(listen_socket, (struct sockaddr*)&remote_addr, &addr_len);
if (sockfd < 0) {
iperf_show_socket_error_reason("tcp server listen", listen_socket);
close(listen_socket);
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));
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) {
actual_recv = recv(socket, buffer, want_recv, 0);
actual_recv = recv(sockfd, buffer, want_recv, 0);
if (actual_recv < 0) {
iperf_show_socket_error_reason("tcp server recv", listen_socket);
break;
@ -183,7 +183,7 @@ esp_err_t iperf_run_tcp_server(void)
}
}
close(socket);
close(sockfd);
}
s_iperf_ctrl.finish = true;
@ -199,22 +199,22 @@ esp_err_t iperf_run_udp_server(void)
struct timeval t;
int want_recv = 0;
uint8_t *buffer;
int socket;
int sockfd;
int opt;
socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (socket < 0) {
iperf_show_socket_error_reason("udp server create", socket);
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sockfd < 0) {
iperf_show_socket_error_reason("udp server create", sockfd);
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_port = htons(s_iperf_ctrl.cfg.sport);
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip;
if (bind(socket, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
iperf_show_socket_error_reason("udp server bind", socket);
if (bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
iperf_show_socket_error_reason("udp server bind", sockfd);
return ESP_FAIL;
}
@ -229,19 +229,19 @@ esp_err_t iperf_run_udp_server(void)
ESP_LOGI(TAG, "want recv=%d", want_recv);
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) {
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) {
iperf_show_socket_error_reason("udp server recv", socket);
iperf_show_socket_error_reason("udp server recv", sockfd);
} else {
s_iperf_ctrl.total_len += actual_recv;
}
}
s_iperf_ctrl.finish = true;
close(socket);
close(sockfd);
return ESP_OK;
}
@ -254,24 +254,24 @@ esp_err_t iperf_run_udp_client(void)
uint32_t delay = 1;
int want_send = 0;
uint8_t *buffer;
int socket;
int sockfd;
int opt;
int err;
int id;
socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (socket < 0) {
iperf_show_socket_error_reason("udp server create", socket);
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sockfd < 0) {
iperf_show_socket_error_reason("udp server create", sockfd);
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_port = 0;
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip;
if (bind(socket, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
iperf_show_socket_error_reason("udp server bind", socket);
if (bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
iperf_show_socket_error_reason("udp server bind", sockfd);
return ESP_FAIL;
}
@ -293,10 +293,10 @@ esp_err_t iperf_run_udp_client(void)
}
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) {
err = iperf_get_socket_error_code(socket);
err = iperf_get_socket_error_code(sockfd);
if (err == ENOMEM) {
vTaskDelay(delay);
if (delay < IPERF_MAX_DELAY) {
@ -314,7 +314,7 @@ esp_err_t iperf_run_udp_client(void)
}
s_iperf_ctrl.finish = true;
close(socket);
close(sockfd);
return ESP_OK;
}
@ -325,22 +325,22 @@ esp_err_t iperf_run_tcp_client(void)
int actual_send = 0;
int want_send = 0;
uint8_t *buffer;
int socket;
int sockfd;
int opt;
socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (socket < 0) {
iperf_show_socket_error_reason("tcp client create", socket);
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockfd < 0) {
iperf_show_socket_error_reason("tcp client create", sockfd);
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_port = 0;
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip;
if (bind(socket, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
iperf_show_socket_error_reason("tcp client bind", socket);
if (bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
iperf_show_socket_error_reason("tcp client bind", sockfd);
return ESP_FAIL;
}
@ -348,8 +348,8 @@ esp_err_t iperf_run_tcp_client(void)
addr.sin_family = AF_INET;
addr.sin_port = htons(s_iperf_ctrl.cfg.dport);
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.dip;
if (connect(socket, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
iperf_show_socket_error_reason("tcp client connect", socket);
if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
iperf_show_socket_error_reason("tcp client connect", sockfd);
return ESP_FAIL;
}
@ -357,7 +357,7 @@ esp_err_t iperf_run_tcp_client(void)
buffer = s_iperf_ctrl.buffer;
want_send = s_iperf_ctrl.buffer_len;
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) {
vTaskDelay(1);
} else {
@ -365,7 +365,7 @@ esp_err_t iperf_run_tcp_client(void)
}
}
close(socket);
close(sockfd);
return ESP_OK;
}