@@ -899,7 +899,7 @@ int wolfIP_sock_recvmsg(struct wolfIP *ipstack, int sockfd, struct msghdr *msg,
899899 socklen_t addrlen = 0 ;
900900 size_t total_len = 0 ;
901901 int ret ;
902- uint8_t stack_buf [WOLFIP_IOV_STACK_BUF ];
902+ uint8_t stack_buf [WOLFIP_IOV_STACK_BUF ] = { 0 } ;
903903 uint8_t * heap_buf = NULL ;
904904 uint8_t * buf = NULL ;
905905 struct pollfd pfd ;
@@ -1274,6 +1274,7 @@ static int wolfip_accept_common(int sockfd, struct sockaddr *addr, socklen_t *ad
12741274 return -1 ;
12751275 }
12761276 wolfip_drain_pipe_locked (entry );
1277+ want_nonblock = wolfip_fd_is_nonblock (sockfd );
12771278 }
12781279 } while (internal_ret == - EAGAIN );
12791280 if (internal_ret < 0 ) {
@@ -1450,12 +1451,9 @@ ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct
14501451 }
14511452 if (ret == - EAGAIN ) {
14521453 if (nonblock ) {
1453- if (sent == 0 ) {
1454- errno = EAGAIN ;
1455- pthread_mutex_unlock (& wolfIP_mutex );
1456- return -1 ;
1457- }
1458- break ;
1454+ errno = EAGAIN ;
1455+ pthread_mutex_unlock (& wolfIP_mutex );
1456+ return -1 ;
14591457 }
14601458 if (entry ) {
14611459 wait_ret = wolfip_wait_for_event_locked (entry , POLLOUT , entry -> snd_timeout_ms );
@@ -1472,7 +1470,7 @@ ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct
14721470 if (internal_fd < 0 ) {
14731471 pthread_mutex_unlock (& wolfIP_mutex );
14741472 errno = EBADF ;
1475- return ( sent == 0 ) ? -1 : ( ssize_t ) sent ;
1473+ return -1 ;
14761474 }
14771475 }
14781476 continue ;
@@ -1521,12 +1519,9 @@ ssize_t send(int sockfd, const void *buf, size_t len, int flags) {
15211519 }
15221520 if (ret == - EAGAIN ) {
15231521 if (nonblock ) {
1524- if (sent == 0 ) {
1525- errno = EAGAIN ;
1526- pthread_mutex_unlock (& wolfIP_mutex );
1527- return -1 ;
1528- }
1529- break ;
1522+ errno = EAGAIN ;
1523+ pthread_mutex_unlock (& wolfIP_mutex );
1524+ return -1 ;
15301525 }
15311526 if (entry ) {
15321527 wait_ret = wolfip_wait_for_event_locked (entry , POLLOUT , entry -> snd_timeout_ms );
@@ -1580,12 +1575,9 @@ ssize_t write(int sockfd, const void *buf, size_t len) {
15801575 }
15811576 if (ret == - EAGAIN ) {
15821577 if (nonblock ) {
1583- if (sent == 0 ) {
1584- errno = EAGAIN ;
1585- pthread_mutex_unlock (& wolfIP_mutex );
1586- return -1 ;
1587- }
1588- break ;
1578+ errno = EAGAIN ;
1579+ pthread_mutex_unlock (& wolfIP_mutex );
1580+ return -1 ;
15891581 }
15901582 if (entry ) {
15911583 wait_ret = wolfip_wait_for_event_locked (entry , POLLOUT , entry -> snd_timeout_ms );
@@ -1687,8 +1679,18 @@ void __attribute__((constructor)) init_wolfip_posix() {
16871679#if WOLFIP_POSIX_TCPDUMP
16881680 static int tcpdump_atexit_registered ;
16891681#endif
1690- if (IPSTACK )
1682+ {
1683+ static int mutex_initialized = 0 ;
1684+ if (!mutex_initialized ) {
1685+ pthread_mutex_init (& wolfIP_mutex , NULL );
1686+ mutex_initialized = 1 ;
1687+ }
1688+ }
1689+ pthread_mutex_lock (& wolfIP_mutex );
1690+ if (IPSTACK ) {
1691+ pthread_mutex_unlock (& wolfIP_mutex );
16911692 return ;
1693+ }
16921694 host_stack_ip_str = getenv ("WOLFIP_HOST_IP" );
16931695 if (!host_stack_ip_str || host_stack_ip_str [0 ] == '\0' ) {
16941696 host_stack_ip_str = HOST_STACK_IP ;
@@ -1734,8 +1736,6 @@ void __attribute__((constructor)) init_wolfip_posix() {
17341736 swap_socketcall (select , "select" );
17351737 swap_socketcall (fcntl , "fcntl" );
17361738
1737- pthread_mutex_init (& wolfIP_mutex , NULL );
1738- pthread_mutex_lock (& wolfIP_mutex );
17391739 wolfIP_init_static (& IPSTACK );
17401740 tapdev = wolfIP_getdev (IPSTACK );
17411741 if (!tapdev ) {
0 commit comments