From 7a35350efb36301726c28a6116cc53968972f613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Tue, 5 Aug 2014 16:29:37 +0200 Subject: [PATCH] 2014-08-05 16:29 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/hbnetio/hbnetio.hbx * contrib/hbnetio/netiocli.c * contrib/hbnetio/readme.txt + added new client side function: netio_TimeOut( [, ] ) -> [] Get/Set client side timeout for messages + inherit timeout used in socket connection and use it for farther message processing. Warning: incompatible, for slow connections or time consuming RPC functions people should set timeout using netio_TimeOut() function. In previous version timeout was set to -1 what means wait forever without any time limits or until connection is broken. --- ChangeLog.txt | 15 ++++++++++++ contrib/hbnetio/hbnetio.hbx | 1 + contrib/hbnetio/netiocli.c | 46 ++++++++++++++++++++++++++++--------- contrib/hbnetio/readme.txt | 4 ++++ 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c8aeae7fc7..074fe1d81d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,21 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2014-08-05 16:29 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * contrib/hbnetio/hbnetio.hbx + * contrib/hbnetio/netiocli.c + * contrib/hbnetio/readme.txt + + added new client side function: + netio_TimeOut( [, ] ) -> [] + Get/Set client side timeout for messages + + inherit timeout used in socket connection and use it for farther + message processing. + Warning: incompatible, for slow connections or time consuming RPC + functions people should set timeout using netio_TimeOut() + function. In previous version timeout was set to -1 what + means wait forever without any time limits or until + connection is broken. + 2014-08-01 02:04 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * extras/gtwvw/gtwvwd.c ! fixed typo in WVW_SETICON() - thanks to Ash diff --git a/contrib/hbnetio/hbnetio.hbx b/contrib/hbnetio/hbnetio.hbx index 4a00406d8f..72048250a4 100644 --- a/contrib/hbnetio/hbnetio.hbx +++ b/contrib/hbnetio/hbnetio.hbx @@ -45,6 +45,7 @@ DYNAMIC netio_ServerTimeOut DYNAMIC netio_SrvSendData DYNAMIC netio_SrvSendItem DYNAMIC netio_SrvStatus +DYNAMIC netio_TimeOut DYNAMIC netio_VerifyClient #if defined( __HBEXTREQ__ ) .OR. defined( __HBEXTERN__HBNETIO__REQUEST ) diff --git a/contrib/hbnetio/netiocli.c b/contrib/hbnetio/netiocli.c index 4c7af0121e..daf141efe3 100644 --- a/contrib/hbnetio/netiocli.c +++ b/contrib/hbnetio/netiocli.c @@ -170,8 +170,6 @@ static HB_BOOL s_fInit = HB_TRUE; static const HB_FILE_FUNCS * s_fileMethods( void ); -#define NETIO_TIMEOUT -1 - static void hb_errRT_NETIO( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, HB_ERRCODE errOsCode, const char * szDescription, const char * szOperation ) @@ -192,9 +190,9 @@ static long s_fileRecvAll( PHB_CONCLI conn, void * buffer, long len ) while( lRead < len ) { if( conn->zstream ) - l = hb_znetRead( conn->zstream, conn->sd, ptr + lRead, len - lRead, NETIO_TIMEOUT ); + l = hb_znetRead( conn->zstream, conn->sd, ptr + lRead, len - lRead, conn->timeout ); else - l = hb_socketRecv( conn->sd, ptr + lRead, len - lRead, 0, NETIO_TIMEOUT ); + l = hb_socketRecv( conn->sd, ptr + lRead, len - lRead, 0, conn->timeout ); if( l <= 0 ) break; lRead += l; @@ -217,7 +215,7 @@ static long s_fileRecvTest( PHB_CONCLI conn, void * buffer, long len ) if( l <= 0 ) break; lRead += l; - timeout = NETIO_TIMEOUT; + timeout = conn->timeout; } return lRead; } @@ -395,9 +393,9 @@ static HB_BOOL s_fileSendMsg( PHB_CONCLI conn, HB_BYTE * msgbuf, while( lSent < len ) { if( conn->zstream ) - l = hb_znetWrite( conn->zstream, conn->sd, msg + lSent, len - lSent, NETIO_TIMEOUT, &lLast ); + l = hb_znetWrite( conn->zstream, conn->sd, msg + lSent, len - lSent, conn->timeout, &lLast ); else - l = lLast = hb_socketSend( conn->sd, msg + lSent, len - lSent, 0, NETIO_TIMEOUT ); + l = lLast = hb_socketSend( conn->sd, msg + lSent, len - lSent, 0, conn->timeout ); if( l > 0 ) lSent += l; if( lLast <= 0 ) @@ -410,7 +408,7 @@ static HB_BOOL s_fileSendMsg( PHB_CONCLI conn, HB_BYTE * msgbuf, if( lSent == len ) { if( conn->zstream && - hb_znetFlush( conn->zstream, conn->sd, NETIO_TIMEOUT ) != 0 ) + hb_znetFlush( conn->zstream, conn->sd, conn->timeout ) != 0 ) { conn->errcode = hb_socketGetError(); if( ! fNoError ) @@ -1144,6 +1142,27 @@ HB_FUNC( NETIO_DISCONNECT ) hb_retl( fDisconnected ); } +/* netio_TimeOut( [, ] ) -> [] + */ +HB_FUNC( NETIO_TIMEOUT ) +{ + PHB_CONCLI conn = s_connParam( 1 ); + + if( conn ) + { + if( s_fileConLock( conn ) ) + { + hb_retni( conn->timeout ); + if( HB_ISNUM( 2 ) ) + conn->timeout = hb_parni( 2 ); + s_fileConUnlock( conn ); + } + s_fileConClose( conn ); + } + else + hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + static const char * s_netio_params( int iParam, int iMsg, const char * pszName, HB_U32 * pSize, char ** pFree ) { int iPCount = iMsg == NETIO_PROCIS ? 0 : hb_pcount(); @@ -1225,9 +1244,14 @@ static HB_BOOL s_netio_procexec( int iMsg, int iType ) } if( buffer == NULL ) buffer = ( char * ) hb_xgrab( nResult ); - nResult = s_fileRecvAll( conn, buffer, ( long ) nResult ); - data = buffer; - pItem = hb_itemDeserialize( &data, &nResult ); + if( nResult == ( HB_SIZE ) s_fileRecvAll( conn, buffer, ( long ) nResult ) ) + { + data = buffer; + pItem = hb_itemDeserialize( &data, &nResult ); + } + else + pItem = NULL; + if( pItem ) { if( iMsg == NETIO_FUNCCTRL ) diff --git a/contrib/hbnetio/readme.txt b/contrib/hbnetio/readme.txt index 28451f46eb..43f071a405 100644 --- a/contrib/hbnetio/readme.txt +++ b/contrib/hbnetio/readme.txt @@ -77,6 +77,10 @@ Client side functions: should not contain "net:" prefix. + netio_TimeOut( [, ] ) -> [] + Get/Set client side timeout for messages + + netio_ProcExists( [,] ) -> Check if function or procedure exists on the server side.