From d95f99ceb6ffaba9f931ac9626fab71f686ff3a7 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 28 Sep 2009 10:57:53 +0000 Subject: [PATCH] 2009-09-28 12:57 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbnetio/netio.h * harbour/contrib/hbnetio/netiocli.c * harbour/contrib/hbnetio/netiosrv.c * added dummy sync messages which can be used as non waiting confirmation % added separate messages for UNLOCK actions which are confirmed by dummy message * updated version number in login string to force client and server synchronization with new protocol (both have to be recompiled with current SVN code) --- harbour/ChangeLog | 11 ++++++++ harbour/contrib/hbnetio/netio.h | 16 ++++++----- harbour/contrib/hbnetio/netiocli.c | 25 ++++++++++------- harbour/contrib/hbnetio/netiosrv.c | 43 +++++++++++++++++++----------- 4 files changed, 64 insertions(+), 31 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3feb49a846..aab437820d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,17 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-09-28 12:57 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/hbnetio/netio.h + * harbour/contrib/hbnetio/netiocli.c + * harbour/contrib/hbnetio/netiosrv.c + * added dummy sync messages which can be used as non waiting confirmation + % added separate messages for UNLOCK actions which are confirmed by + dummy message + * updated version number in login string to force client and server + synchronization with new protocol (both have to be recompiled with + current SVN code) + 2009-09-27 12:58 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbqt/generator/hbqtgen.prg ! Modified TO implement destructors IN a different way. diff --git a/harbour/contrib/hbnetio/netio.h b/harbour/contrib/hbnetio/netio.h index 15398a5490..c3b0b99d6a 100644 --- a/harbour/contrib/hbnetio/netio.h +++ b/harbour/contrib/hbnetio/netio.h @@ -73,7 +73,7 @@ #define NETIO_SERVERNAME_MAX 256 /* login string */ -#define NETIO_LOGINSTRID "HarbourFileTcpIpServer\004" +#define NETIO_LOGINSTRID "HarbourFileTcpIpServer\005" /* messages */ #define NETIO_LOGIN 1 @@ -86,9 +86,11 @@ #define NETIO_READ 8 #define NETIO_WRITE 9 #define NETIO_LOCK 10 -#define NETIO_OPEN 11 -#define NETIO_CLOSE 12 -#define NETIO_ERROR 13 +#define NETIO_UNLOCK 11 +#define NETIO_OPEN 12 +#define NETIO_CLOSE 13 +#define NETIO_ERROR 14 +#define NETIO_SYNC 15 #define NETIO_CONNECTED 0x4321DEAD /* messages format */ @@ -102,9 +104,11 @@ /* { NETIO_LOCK, file_no[2], start[ 8 ], len[ 8 ], flags[ 2 ], ... } -> { NETIO_LOCK, ... } */ /* { NETIO_TRUNC, file_no[2], offset[ 8 ], ... } -> { NETIO_TRUNC, ... } */ /* { NETIO_SIZE, file_no[2], ... } -> { NETIO_SIZE, size[ 8 ], err[ 2 ], ... } */ -/* { NETIO_COMMIT, file_no[2], ... } -> NULL */ +/* { NETIO_COMMIT, file_no[2], ... } -> { NETIO_SYNC, ... } */ /* { NETIO_CLOSE, file_no[2], ... } -> { NETIO_CLOSE, ... } */ -/* alternative answer for all non NULL messages: -> { NETIO_ERROR, err[ 2 ], ... } */ +/* { NETIO_UNLOCK, file_no[2], start[ 8 ], len[ 8 ], flags[ 2 ], ... } -> { NETIO_SYNC, ... } */ +/* { NETIO_SYNC, ... } -> NULL */ +/* alternative answer for all messages: -> { NETIO_ERROR, err[ 2 ], ... } */ /* netio errors */ #define NETIO_ERR_UNKNOWN_COMMAND 0xff01 diff --git a/harbour/contrib/hbnetio/netiocli.c b/harbour/contrib/hbnetio/netiocli.c index b2a404025f..5583742e6f 100644 --- a/harbour/contrib/hbnetio/netiocli.c +++ b/harbour/contrib/hbnetio/netiocli.c @@ -121,6 +121,8 @@ static BOOL s_fInit = TRUE; static const HB_FILE_FUNCS * s_fileMethods( void ); +#define NETIO_TIMEOUT -1 + static long s_fileRecvAll( PHB_CONCLI conn, void * buffer, long len ) { BYTE * ptr = ( BYTE * ) buffer; @@ -128,7 +130,7 @@ static long s_fileRecvAll( PHB_CONCLI conn, void * buffer, long len ) while( lRead < len ) { - l = hb_socketRecv( conn->sd, ptr + lRead, len - lRead, 0, -1 ); + l = hb_socketRecv( conn->sd, ptr + lRead, len - lRead, 0, NETIO_TIMEOUT ); if( l <= 0 ) break; lRead += l; @@ -162,7 +164,7 @@ static BOOL s_fileSendMsg( PHB_CONCLI conn, BYTE * msgbuf, while( lSent < len ) { - l = hb_socketSend( conn->sd, msg + lSent, len - lSent, 0, -1 ); + l = hb_socketSend( conn->sd, msg + lSent, len - lSent, 0, NETIO_TIMEOUT ); if( l <= 0 ) break; lSent += l; @@ -177,14 +179,18 @@ static BOOL s_fileSendMsg( PHB_CONCLI conn, BYTE * msgbuf, { int iMsg = HB_GET_LE_INT32( msgbuf ); - if( s_fileRecvAll( conn, msgbuf, NETIO_MSGLEN ) == NETIO_MSGLEN ) + while( s_fileRecvAll( conn, msgbuf, NETIO_MSGLEN ) == NETIO_MSGLEN ) { int iResult = HB_GET_LE_INT32( msgbuf ); - if( iResult == NETIO_ERROR ) - hb_fsSetError( HB_GET_LE_UINT16( &msgbuf[ 4 ] ) ); - else if( iResult == iMsg ) - fResult = TRUE; + if( iResult != NETIO_SYNC ) + { + if( iResult == NETIO_ERROR ) + hb_fsSetError( HB_GET_LE_UINT16( &msgbuf[ 4 ] ) ); + else if( iResult == iMsg ) + fResult = TRUE; + break; + } } } else @@ -659,15 +665,16 @@ static BOOL s_fileLock( PHB_FILE pFile, HB_FOFFSET ulStart, HB_FOFFSET ulLen, if( s_fileConLock( pFile->conn ) ) { BYTE msgbuf[ NETIO_MSGLEN ]; + BOOL fUnLock = ( iType & FL_MASK ) == FL_UNLOCK; - HB_PUT_LE_UINT32( &msgbuf[ 0 ], NETIO_LOCK ); + HB_PUT_LE_UINT32( &msgbuf[ 0 ], fUnLock ? NETIO_UNLOCK : NETIO_LOCK ); HB_PUT_LE_UINT16( &msgbuf[ 4 ], pFile->fd ); HB_PUT_LE_UINT64( &msgbuf[ 6 ], ulStart ); HB_PUT_LE_UINT64( &msgbuf[ 14 ], ulLen ); HB_PUT_LE_UINT16( &msgbuf[ 22 ], ( USHORT ) iType ); memset( msgbuf + 24, '\0', sizeof( msgbuf ) - 24 ); - fResult = s_fileSendMsg( pFile->conn, msgbuf, NULL, 0, TRUE ); + fResult = s_fileSendMsg( pFile->conn, msgbuf, NULL, 0, !fUnLock ); s_fileConUnlock( pFile->conn ); } diff --git a/harbour/contrib/hbnetio/netiosrv.c b/harbour/contrib/hbnetio/netiosrv.c index 7a17ee2cb9..9e6629c329 100644 --- a/harbour/contrib/hbnetio/netiosrv.c +++ b/harbour/contrib/hbnetio/netiosrv.c @@ -299,7 +299,7 @@ static long s_srvSendAll( PHB_CONSRV conn, void * buffer, long len ) while( lSent < len && !conn->stop ) { - l = hb_socketSend( conn->sd, ptr + lSent, len - lSent, 0, 1000 ); + l = hb_socketSend( conn->sd, ptr + lSent, len - lSent, 0, -1 ); if( l <= 0 ) { if( hb_socketGetError() != HB_SOCKET_ERR_TIMEOUT || @@ -709,6 +709,8 @@ HB_FUNC( NETIO_SERVER ) } break; + case NETIO_UNLOCK: + fNoAnswer = TRUE; case NETIO_LOCK: iFileNo = HB_GET_LE_UINT16( &msgbuf[ 4 ] ); llOffset = HB_GET_LE_INT64( &msgbuf[ 6 ] ); @@ -719,9 +721,10 @@ HB_FUNC( NETIO_SERVER ) iError = NETIO_ERR_WRONG_FILE_HANDLE; else if( !hb_fileLock( pFile, llOffset, llSize, uiFalgs ) ) iError = s_srvFsError(); - else + else if( !fNoAnswer ) { - HB_PUT_LE_UINT32( &msg[ 0 ], NETIO_LOCK ); + UINT32 uiMsg = HB_GET_LE_UINT32( msgbuf ); + HB_PUT_LE_UINT32( &msg[ 0 ], uiMsg ); memset( msg + 4, '\0', NETIO_MSGLEN - 4 ); } break; @@ -778,29 +781,37 @@ HB_FUNC( NETIO_SERVER ) fNoAnswer = TRUE; break; + case NETIO_SYNC: + continue; + default: /* unkown message */ iError = NETIO_ERR_UNKNOWN_COMMAND; break; } - if( !fNoAnswer ) + if( fNoAnswer ) { - if( iError != 0 ) - { - HB_PUT_LE_UINT32( &msg[ 0 ], NETIO_ERROR ); - HB_PUT_LE_UINT16( &msg[ 4 ], iError ); - memset( msg + 6, '\0', NETIO_MSGLEN - 6 ); - len = NETIO_MSGLEN; - } - else - len += NETIO_MSGLEN; - - if( s_srvSendAll( conn, msg, len ) != len ) - break; + HB_PUT_LE_UINT32( &msg[ 0 ], NETIO_SYNC ); + memset( msg + 4, '\0', NETIO_MSGLEN - 4 ); + len = NETIO_MSGLEN; } + else if( iError != 0 ) + { + HB_PUT_LE_UINT32( &msg[ 0 ], NETIO_ERROR ); + HB_PUT_LE_UINT16( &msg[ 4 ], iError ); + memset( msg + 6, '\0', NETIO_MSGLEN - 6 ); + len = NETIO_MSGLEN; + } + else + len += NETIO_MSGLEN; + + iError = s_srvSendAll( conn, msg, len ) != len; if( ptr ) hb_xfree( ptr ); + + if( iError ) + break; } } }