@@ -322,6 +322,32 @@ static inline int SetupSocketAndConnect(SockIoCbCtx* sockIoCtx, const char* host
322322 return 0 ;
323323}
324324
325+ static inline int SocketWaitData (SockIoCbCtx * sockIoCtx , int timeout_sec )
326+ {
327+ int res ;
328+ struct timeval timeout ;
329+ fd_set fds , errfds ;
330+ FD_ZERO (& fds );
331+ FD_ZERO (& errfds );
332+ FD_SET (sockIoCtx -> fd , & fds );
333+ FD_SET (sockIoCtx -> fd , & errfds );
334+ timeout .tv_sec = timeout_sec ;
335+ timeout .tv_usec = 0 ;
336+ res = select (sockIoCtx -> fd + 1 , & fds , NULL , & errfds , & timeout );
337+ if (res == 0 ) {
338+ return 0 ; /* timeout */
339+ }
340+ else if (res > 0 ) {
341+ if (FD_ISSET (sockIoCtx -> fd , & fds )) {
342+ return 1 ; /* ready to read */
343+ }
344+ else if (FD_ISSET (sockIoCtx -> fd , & errfds )) {
345+ return -1 ; /* error */
346+ }
347+ }
348+ return 0 ; /* select failed */
349+ }
350+
325351static inline void CloseAndCleanupSocket (SockIoCbCtx * sockIoCtx )
326352{
327353 if (sockIoCtx -> fd != -1 ) {
@@ -343,6 +369,7 @@ static inline void CloseAndCleanupSocket(SockIoCbCtx* sockIoCtx)
343369
344370 int SetupSocketAndListen (SockIoCbCtx * sockIoCtx , word32 port );
345371 int SocketWaitClient (SockIoCbCtx * sockIoCtx );
372+ int SocketWaitData (SockIoCbCtx * sockIoCtx , int timeout_sec );
346373#endif /* !WOLFSSL_USER_IO */
347374
348375/******************************************************************************/
0 commit comments