From f90e0be4fdb079517910f0ec30c0c5ae35e594db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Mon, 31 Aug 2015 13:26:26 +0200 Subject: [PATCH] 2015-08-31 13:26 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/rtl/hbsockhb.c + added new PRG function: hb_socketAutoShutdown( hSocket, [ lNewSetting ] ) --> lPrevSetting it allows to enable/disable automatic shutdown when connected socket is closed. * contrib/hbpipeio/pipeio.c * removed trailing space * contrib/hbpipeio/tests/test.prg * cleaned the code and messages --- ChangeLog.txt | 13 +++++++++++++ contrib/hbpipeio/pipeio.c | 2 +- contrib/hbpipeio/tests/test.prg | 18 +++++++++--------- src/rtl/hbsockhb.c | 13 +++++++++++++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 6cd5b45518..fe11b40969 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,19 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2015-08-31 13:26 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/rtl/hbsockhb.c + + added new PRG function: + hb_socketAutoShutdown( hSocket, [ lNewSetting ] ) --> lPrevSetting + it allows to enable/disable automatic shutdown when connected socket + is closed. + + * contrib/hbpipeio/pipeio.c + * removed trailing space + + * contrib/hbpipeio/tests/test.prg + * cleaned the code and messages + 2015-08-31 12:45 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/hbtcpio/tcpio.c * contrib/hbpipeio/pipeio.c diff --git a/contrib/hbpipeio/pipeio.c b/contrib/hbpipeio/pipeio.c index 5eba5db867..00407ac282 100644 --- a/contrib/hbpipeio/pipeio.c +++ b/contrib/hbpipeio/pipeio.c @@ -167,7 +167,7 @@ static HB_SIZE s_fileWrite( PHB_FILE pFile, const void * data, if( pFile->hPipeWR == FS_ERROR ) hb_fsSetError( 6 ); - else + else { if( timeout == -1 ) timeout = pFile->timeout; diff --git a/contrib/hbpipeio/tests/test.prg b/contrib/hbpipeio/tests/test.prg index 544c0364ac..abf9bb2bad 100644 --- a/contrib/hbpipeio/tests/test.prg +++ b/contrib/hbpipeio/tests/test.prg @@ -22,7 +22,7 @@ PROCEDURE Main() cData := hb_tsToStr( hb_dateTime() ) + hb_eol() + ; Version() + hb_eol() + ; OS() + hb_eol() + ; - replicate( "0123456789" + hb_eol(), 1000 ) + ; + Replicate( "0123456789" + hb_eol(), 1000 ) + ; "END" + hb_eol() nDone := 0 WHILE nDone < hb_BLen( cData ) .AND. ; @@ -32,7 +32,7 @@ PROCEDURE Main() ENDDO ? "total bytes written: " + hb_ntos( nDone ) + ; ", error: " + hb_ntos( FError() ) - /* close input stream fro GZIP process to indicate end of data */ + /* close input stream for GZIP process to indicate end of data */ hb_vfConfig( pFile, HB_VF_SHUTDOWN, FO_WRITE ) ? @@ -40,10 +40,10 @@ PROCEDURE Main() ? "reading..." cBuffer := Space( 1000 ) WHILE ( nLen := hb_vfRead( pFile, @cBuffer ) ) > 0 - cResult += left( cBuffer, nLen ) + cResult += hb_BLeft( cBuffer, nLen ) ? "read: " + hb_ntos( nLen ) ENDDO - ? "total bytes read: " + hb_ntos( Len( cResult ) ) + ; + ? "total bytes read: " + hb_ntos( hb_BLen( cResult ) ) + ; ", error: " + hb_ntos( FError() ) /* close the pipe file and wait for child process termination */ @@ -53,14 +53,14 @@ PROCEDURE Main() ? hb_vfErase( "data.gz" ) - ? "write data.gz " + hb_ntos( len( cResult ) ) + " " - ?? iif( len( cResult ) == 0, ( hb_vfErase( "data.gz" ), .f. ), ; - hb_memoWrit( "data.gz", cResult ) ) + ? "write data.gz " + hb_ntos( hb_BLen( cResult ) ) + " -> " + ; + iif( hb_BLen( cResult ) > 0 .AND. hb_memoWrit( "data.gz", cResult ), ; + "OK", "ERROR" ) /* check if we can decode data compressed by GZIP */ IF hb_ZUncompress( cResult ) == cData - ? "OK, GZIP output decompressed correctly and much the source" + ? "OK, GZIP output decompressed correctly and muches the source" ELSE - ? "ERROR, decompressed GZIP output not much the source" + ? "ERROR, decompressed GZIP output does not much the source" ENDIF ENDIF ? diff --git a/src/rtl/hbsockhb.c b/src/rtl/hbsockhb.c index e71b9f300e..054640fa68 100644 --- a/src/rtl/hbsockhb.c +++ b/src/rtl/hbsockhb.c @@ -90,6 +90,7 @@ * hb_socketWrite( hSocket, cBuffer, [ nLen = Len( cBuffer ) ], [ nTimeout = FOREVER ] ) --> nBytesWritten * hb_socketFlush( hSocket, [ nTimeout = FOREVER ], [ lSync ] ) --> nBytesLeft * hb_socketAutoFlush( hSocket, [ nNewSetting ] ) --> nPrevSetting + * hb_socketAutoShutdown( hSocket, [ lNewSetting ] ) --> lPrevSetting */ /* this has to be declared before hbsocket.h is included */ @@ -1483,3 +1484,15 @@ HB_FUNC( HB_SOCKETAUTOFLUSH ) hb_sockexSetAutoFlush( pSock, hb_parni( 2 ) ); } } + +HB_FUNC( HB_SOCKETAUTOSHUTDOWN ) +{ + PHB_SOCKEX pSock = hb_sockexParam( 1 ); + + if( pSock ) + { + hb_retl( hb_sockexGetShutDown( pSock ) ); + if( HB_ISLOG( 2 ) ) + hb_sockexSetShutDown( pSock, hb_parl( 2 ) ); + } +}