From 2f1bf5ee72133bbf44fb7557bb94da53e1e956c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Thu, 7 Apr 2016 18:34:30 +0200 Subject: [PATCH] 2016-04-07 18:34 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/common/hbprintf.c * pacified warning * src/rtl/filesys.c ! return -1 instead of from hb_fsPipeIsData() when poll() detects error or end of stream - 0 should indicate timeout only. * src/rtl/hbcom.c ! fixed bad typo which blocked hb_comSend() in *nixes using select() instead of poll() * src/rtl/filesys.c * src/rtl/hbcom.c * src/rtl/hbproces.c * src/rtl/hbsocket.c ; updated #if/#else/#endif comments --- ChangeLog.txt | 18 ++++++++++++++++++ src/common/hbprintf.c | 4 ++-- src/rtl/filesys.c | 35 +++++++++++++++++++++++------------ src/rtl/hbcom.c | 10 +++++----- src/rtl/hbproces.c | 4 ++-- src/rtl/hbsocket.c | 16 ++++++++-------- 6 files changed, 58 insertions(+), 29 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 91f80157bd..63f47ff5b6 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,24 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2016-04-07 18:34 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/common/hbprintf.c + * pacified warning + + * src/rtl/filesys.c + ! return -1 instead of from hb_fsPipeIsData() when poll() detects + error or end of stream - 0 should indicate timeout only. + + * src/rtl/hbcom.c + ! fixed bad typo which blocked hb_comSend() in *nixes + using select() instead of poll() + + * src/rtl/filesys.c + * src/rtl/hbcom.c + * src/rtl/hbproces.c + * src/rtl/hbsocket.c + ; updated #if/#else/#endif comments + 2016-04-06 15:49 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/common/hbprintf.c * pacified warnings diff --git a/src/common/hbprintf.c b/src/common/hbprintf.c index 76f97b20c3..37d235641f 100644 --- a/src/common/hbprintf.c +++ b/src/common/hbprintf.c @@ -1227,8 +1227,8 @@ int hb_vsnprintf( char * buffer, size_t bufsize, const char * format, va_list ap { double d = va_arg_n( args, _x_double, param ); HB_NUMTYPE( value, d ); - argval.value.as_x_long_dbl = - ( value & ( _HB_NUM_NAN | _HB_NUM_PINF | _HB_NUM_NINF ) ) == 0 ? d : 0; + argval.value.as_x_long_dbl = ( _x_long_dbl ) + ( ( value & ( _HB_NUM_NAN | _HB_NUM_PINF | _HB_NUM_NINF ) ) == 0 ? d : 0 ); } if( value & _HB_NUM_NAN ) size = put_str( buffer, bufsize, size, diff --git a/src/rtl/filesys.c b/src/rtl/filesys.c index cc555a1714..11a3145e2d 100644 --- a/src/rtl/filesys.c +++ b/src/rtl/filesys.c @@ -1154,7 +1154,8 @@ HB_SIZE hb_fsPipeIsData( HB_FHANDLE hPipeHandle, HB_SIZE nBufferSize, for( ;; ) { - int tout = nTimeOut < 0 || nTimeOut > 1000 ? 1000 : ( int ) nTimeOut; + HB_BOOL fLast = nTimeOut >= 0 && nTimeOut <= 1000; + int tout = fLast ? ( int ) nTimeOut : 1000; iResult = poll( &fds, 1, tout ); hb_fsSetIOError( iResult >= 0, 0 ); if( iResult > 0 && ( fds.revents & POLLIN ) == 0 ) @@ -1166,9 +1167,12 @@ HB_SIZE hb_fsPipeIsData( HB_FHANDLE hPipeHandle, HB_SIZE nBufferSize, } iResult = 0; } - if( ( ( iResult == 0 && ( nTimeOut < 0 || nTimeOut > 1000 ) ) || - ( iResult == -1 && nTimeOut != 0 && hb_fsOsError() == ( HB_ERRCODE ) EINTR ) ) && - hb_vmRequestQuery() == 0 ) + else if( iResult == -1 && hb_fsOsError() == ( HB_ERRCODE ) EINTR ) + { + iResult = 0; + fLast = HB_FALSE; + } + if( iResult == 0 && ! fLast && hb_vmRequestQuery() == 0 ) { if( nTimeOut < 0 ) continue; @@ -1185,7 +1189,7 @@ HB_SIZE hb_fsPipeIsData( HB_FHANDLE hPipeHandle, HB_SIZE nBufferSize, } break; } -#else +#else /* ! HB_HAS_POLL */ struct timeval tv; fd_set rfds; # if ! defined( HB_HAS_SELECT_TIMER ) @@ -1233,10 +1237,12 @@ HB_SIZE hb_fsPipeIsData( HB_FHANDLE hPipeHandle, HB_SIZE nBufferSize, } # endif } -#endif /* HB_HAS_POLL */ +#endif /* ! HB_HAS_POLL */ if( iResult > 0 ) nToRead = nBufferSize; + else if( iResult < 0 ) + nToRead = ( HB_SIZE ) FS_ERROR; } #else { @@ -1397,7 +1403,9 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi for( ;; ) { - int tout = nTimeOut < 0 || nTimeOut > 1000 ? 1000 : ( int ) nTimeOut; + HB_BOOL fLast = nTimeOut >= 0 && nTimeOut <= 1000; + int tout = fLast ? ( int ) nTimeOut : 1000; + iResult = poll( &fds, 1, tout ); hb_fsSetIOError( iResult >= 0, 0 ); if( iResult > 0 && ( fds.revents & POLLOUT ) == 0 ) @@ -1409,9 +1417,12 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi } iResult = 0; } - if( ( ( iResult == 0 && ( nTimeOut < 0 || nTimeOut > 1000 ) ) || - ( iResult == -1 && nTimeOut != 0 && hb_fsOsError() == ( HB_ERRCODE ) EINTR ) ) && - hb_vmRequestQuery() == 0 ) + else if( iResult == -1 && hb_fsOsError() == ( HB_ERRCODE ) EINTR ) + { + iResult = 0; + fLast = HB_FALSE; + } + if( iResult == 0 && ! fLast && hb_vmRequestQuery() == 0 ) { if( nTimeOut < 0 ) continue; @@ -1428,7 +1439,7 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi } break; } -#else +#else /* ! HB_HAS_POLL */ struct timeval tv; fd_set wfds; # if ! defined( HB_HAS_SELECT_TIMER ) @@ -1476,7 +1487,7 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi } # endif } -#endif /* HB_HAS_POLL */ +#endif /* ! HB_HAS_POLL */ if( iResult > 0 ) { diff --git a/src/rtl/hbcom.c b/src/rtl/hbcom.c index a25b2317a7..959339cd63 100644 --- a/src/rtl/hbcom.c +++ b/src/rtl/hbcom.c @@ -579,7 +579,7 @@ static int hb_comCanRead( PHB_COM pCom, HB_MAXINT timeout ) } break; } -#else +#else /* ! HB_HAS_POLL */ struct timeval tv; fd_set rfds; @@ -630,7 +630,7 @@ static int hb_comCanRead( PHB_COM pCom, HB_MAXINT timeout ) } # endif } -#endif /* HB_HAS_POLL */ +#endif /* ! HB_HAS_POLL */ return iResult; } @@ -683,7 +683,7 @@ static int hb_comCanWrite( PHB_COM pCom, HB_MAXINT timeout ) } break; } -#else +#else /* ! HB_HAS_POLL */ struct timeval tv; fd_set wfds; @@ -713,7 +713,7 @@ static int hb_comCanWrite( PHB_COM pCom, HB_MAXINT timeout ) # endif iResult = select( ( int ) ( pCom->fd + 1 ), NULL, &wfds, NULL, &tv ); - if( iResult > 0 && FD_ISSET( pCom->fd, &wfds ) ) + if( iResult > 0 && ! FD_ISSET( pCom->fd, &wfds ) ) iResult = 0; hb_comSetOsError( pCom, iResult == -1 ); if( iResult == 0 && timeout < 0 && hb_vmRequestQuery() == 0 ) @@ -735,7 +735,7 @@ static int hb_comCanWrite( PHB_COM pCom, HB_MAXINT timeout ) # endif break; } -#endif /* HB_HAS_POLL */ +#endif /* ! HB_HAS_POLL */ return iResult; } diff --git a/src/rtl/hbproces.c b/src/rtl/hbproces.c index 74f1205e24..ed464bc3ba 100644 --- a/src/rtl/hbproces.c +++ b/src/rtl/hbproces.c @@ -1552,7 +1552,7 @@ int hb_fsProcessRun( const char * pszFileName, } } } -#else +#else /* ! HB_HAS_POLL */ { fd_set rfds, wfds, *prfds, *pwfds; HB_FHANDLE fdMax; @@ -1598,7 +1598,7 @@ int hb_fsProcessRun( const char * pszFileName, fStderr = hStderr != FS_ERROR && FD_ISSET( hStderr, &rfds ); fStdin = hStdin != FS_ERROR && FD_ISSET( hStdin, &wfds ); } -#endif /* HB_HAS_POLL */ +#endif /* ! HB_HAS_POLL */ if( fStdout ) { diff --git a/src/rtl/hbsocket.c b/src/rtl/hbsocket.c index 42c6edbd80..d8f9edb35a 100644 --- a/src/rtl/hbsocket.c +++ b/src/rtl/hbsocket.c @@ -1540,7 +1540,7 @@ static int hb_socketSelectRD( HB_SOCKET sd, HB_MAXINT timeout ) break; } return iResult; -#else +#else /* ! HB_HAS_POLL */ struct timeval tv, * ptv; fd_set rfds; int iResult, iError; @@ -1591,7 +1591,7 @@ static int hb_socketSelectRD( HB_SOCKET sd, HB_MAXINT timeout ) return iResult < 0 ? -1 : ( iResult > 0 && FD_ISSET( ( HB_SOCKET_T ) sd, &rfds ) ? 1 : 0 ); -#endif /* HB_HAS_POLL */ +#endif /* ! HB_HAS_POLL */ } static int hb_socketSelectWR( HB_SOCKET sd, HB_MAXINT timeout ) @@ -1649,7 +1649,7 @@ static int hb_socketSelectWR( HB_SOCKET sd, HB_MAXINT timeout ) break; } return iResult; -#else +#else /* ! HB_HAS_POLL */ struct timeval tv, * ptv; fd_set wfds; int iResult, iError; @@ -1700,7 +1700,7 @@ static int hb_socketSelectWR( HB_SOCKET sd, HB_MAXINT timeout ) return iResult < 0 ? -1 : ( iResult > 0 && FD_ISSET( ( HB_SOCKET_T ) sd, &wfds ) ? 1 : 0 ); -#endif /* HB_HAS_POLL */ +#endif /* ! HB_HAS_POLL */ } static int hb_socketSelectWRE( HB_SOCKET sd, HB_MAXINT timeout ) @@ -1770,7 +1770,7 @@ static int hb_socketSelectWRE( HB_SOCKET sd, HB_MAXINT timeout ) hb_socketSetOsError( iError ); } return iResult; -#else +#else /* ! HB_HAS_POLL */ struct timeval tv, * ptv; fd_set wfds, * pefds; @@ -1862,7 +1862,7 @@ static int hb_socketSelectWRE( HB_SOCKET sd, HB_MAXINT timeout ) return iResult < 0 ? -1 : ( iResult > 0 && FD_ISSET( ( HB_SOCKET_T ) sd, &wfds ) ? 1 : 0 ); -#endif /* HB_HAS_POLL */ +#endif /* ! HB_HAS_POLL */ } int hb_socketGetAddrFamily( const void * pSockAddr, unsigned len ) @@ -3107,7 +3107,7 @@ int hb_socketSelect( PHB_ITEM pArrayRD, HB_BOOL fSetRD, hb_xfree( pfds ); return iResult; -#else +#else /* ! HB_HAS_POLL */ HB_SOCKET maxsd, sd; int i, ret; HB_SIZE nLen, nPos, ul; @@ -3198,7 +3198,7 @@ int hb_socketSelect( PHB_ITEM pArrayRD, HB_BOOL fSetRD, } return ret; -#endif /* HB_HAS_POLL */ +#endif /* ! HB_HAS_POLL */ }