2015-08-31 12:45 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* contrib/hbtcpio/tcpio.c
* contrib/hbpipeio/pipeio.c
* modified hb_fileWrite() to return 0 in case of timeout or unblocking
write and -1 on other errors.
* contrib/hbcomio/comio.c
* modified hb_fileRead() to return 0 in case of timeout or unblocking
read and -1 on other errors.
* src/rtl/filesys.c
* return -1 instead of 0 from hb_fsPipeWrite() in MS-Windows and OS2
builds if PIPE state cannot be read
* ChangeLog.txt
! c&p typo in previous ChangeLog entry
This commit is contained in:
@@ -10,6 +10,23 @@
|
||||
* Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment
|
||||
*/
|
||||
|
||||
2015-08-31 12:45 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
|
||||
* contrib/hbtcpio/tcpio.c
|
||||
* contrib/hbpipeio/pipeio.c
|
||||
* modified hb_fileWrite() to return 0 in case of timeout or unblocking
|
||||
write and -1 on other errors.
|
||||
|
||||
* contrib/hbcomio/comio.c
|
||||
* modified hb_fileRead() to return 0 in case of timeout or unblocking
|
||||
read and -1 on other errors.
|
||||
|
||||
* src/rtl/filesys.c
|
||||
* return -1 instead of 0 from hb_fsPipeWrite() in MS-Windows and OS2
|
||||
builds if PIPE state cannot be read
|
||||
|
||||
* ChangeLog.txt
|
||||
! c&p typo in previous ChangeLog entry
|
||||
|
||||
2015-08-27 17:49 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
|
||||
+ contrib/hbpipeio/hbpipeio.hbc
|
||||
+ contrib/hbpipeio/hbpipeio.hbp
|
||||
@@ -37,7 +54,7 @@
|
||||
hProcess := hb_processOpen( cCommand, @hStdIn, @hStdOut )
|
||||
pFile := hb_vfFromPipes( hStdOut, hStdIn, hProcess, 5000 )
|
||||
The second one can be used directly:
|
||||
pFile := hb_vfFromPipes( cCommand, FO_READWRITE, 5000 )
|
||||
pFile := hb_vfOpenProcess( cCommand, FO_READWRITE, 5000 )
|
||||
Usually process which reads from its stdin works until its input
|
||||
stream is closed by other process. If user wants to close input
|
||||
stream for command redirected to Harbour PIPE FILE IO then he can
|
||||
|
||||
@@ -315,7 +315,7 @@ static HB_SIZE s_fileRead( PHB_FILE pFile, void * data,
|
||||
HB_SIZE nSize, HB_MAXINT timeout )
|
||||
{
|
||||
HB_ERRCODE errcode;
|
||||
long lRead = 0;
|
||||
long lRead = -1;
|
||||
|
||||
if( pFile->fRead )
|
||||
{
|
||||
@@ -324,20 +324,24 @@ static HB_SIZE s_fileRead( PHB_FILE pFile, void * data,
|
||||
timeout = pFile->timeout;
|
||||
lRead = hb_comRecv( pFile->port, data, lRead, timeout );
|
||||
errcode = hb_comGetError( pFile->port );
|
||||
if( lRead <= 0 && errcode == HB_COM_ERR_TIMEOUT )
|
||||
lRead = 0;
|
||||
else if( lRead == 0 )
|
||||
lRead = -1;
|
||||
}
|
||||
else
|
||||
errcode = HB_COM_ERR_ACCESS;
|
||||
|
||||
hb_fsSetError( errcode );
|
||||
|
||||
return HB_MAX( lRead, 0 );
|
||||
return lRead;
|
||||
}
|
||||
|
||||
static HB_SIZE s_fileWrite( PHB_FILE pFile, const void * data,
|
||||
HB_SIZE nSize, HB_MAXINT timeout )
|
||||
{
|
||||
HB_ERRCODE errcode;
|
||||
long lSent = 0;
|
||||
long lSent = -1;
|
||||
|
||||
if( pFile->fWrite )
|
||||
{
|
||||
@@ -346,13 +350,17 @@ static HB_SIZE s_fileWrite( PHB_FILE pFile, const void * data,
|
||||
timeout = pFile->timeout;
|
||||
lSent = hb_comSend( pFile->port, data, lSent, timeout );
|
||||
errcode = hb_comGetError( pFile->port );
|
||||
if( lSent <= 0 && errcode == HB_COM_ERR_TIMEOUT )
|
||||
lSent = 0;
|
||||
else if( lSent == 0 )
|
||||
lSent = -1;
|
||||
}
|
||||
else
|
||||
errcode = HB_COM_ERR_ACCESS;
|
||||
|
||||
hb_fsSetError( errcode );
|
||||
|
||||
return HB_MAX( 0, lSent );
|
||||
return lSent;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileConfigure( PHB_FILE pFile, int iIndex, PHB_ITEM pValue )
|
||||
|
||||
@@ -163,7 +163,7 @@ static HB_SIZE s_fileRead( PHB_FILE pFile, void * data,
|
||||
static HB_SIZE s_fileWrite( PHB_FILE pFile, const void * data,
|
||||
HB_SIZE nSize, HB_MAXINT timeout )
|
||||
{
|
||||
HB_SIZE nWritten = 0;
|
||||
HB_SIZE nWritten = ( HB_SIZE ) -1;
|
||||
|
||||
if( pFile->hPipeWR == FS_ERROR )
|
||||
hb_fsSetError( 6 );
|
||||
|
||||
@@ -230,17 +230,28 @@ static HB_SIZE s_fileRead( PHB_FILE pFile, void * data,
|
||||
static HB_SIZE s_fileWrite( PHB_FILE pFile, const void * data,
|
||||
HB_SIZE nSize, HB_MAXINT timeout )
|
||||
{
|
||||
long lSend = nSize > LONG_MAX ? LONG_MAX : ( long ) nSize;
|
||||
long lSent = nSize > LONG_MAX ? LONG_MAX : ( long ) nSize;
|
||||
HB_ERRCODE errcode;
|
||||
|
||||
if( timeout == -1 )
|
||||
timeout = pFile->timeout;
|
||||
lSend = hb_sockexWrite( pFile->sock, data, lSend, timeout );
|
||||
hb_fsSetError( hb_socketGetError() );
|
||||
lSent = hb_sockexWrite( pFile->sock, data, lSent, timeout );
|
||||
errcode = hb_socketGetError();
|
||||
hb_fsSetError( errcode );
|
||||
|
||||
if( lSend < 0 )
|
||||
lSend = 0;
|
||||
if( lSent < 0 )
|
||||
{
|
||||
switch( errcode )
|
||||
{
|
||||
case HB_SOCKET_ERR_TIMEOUT:
|
||||
case HB_SOCKET_ERR_AGAIN:
|
||||
case HB_SOCKET_ERR_TRYAGAIN:
|
||||
lSent = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lSend;
|
||||
return lSent;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileEof( PHB_FILE pFile )
|
||||
|
||||
@@ -1079,7 +1079,6 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi
|
||||
HANDLE hPipe = ( HANDLE ) hb_fsGetOsHandle( hPipeHandle );
|
||||
DWORD dwMode = 0;
|
||||
|
||||
nWritten = 0;
|
||||
if( GetNamedPipeHandleState( hPipe, &dwMode, NULL, NULL, NULL, NULL, 0 ) )
|
||||
{
|
||||
HB_MAXUINT end_timer = nTimeOut > 0 ? hb_dateMilliSeconds() + nTimeOut : 0;
|
||||
@@ -1111,13 +1110,15 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi
|
||||
SetNamedPipeHandleState( hPipe, &dwMode, NULL, NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_fsSetIOError( HB_FALSE, 0 );
|
||||
nWritten = ( HB_SIZE ) -1;
|
||||
}
|
||||
}
|
||||
#elif defined( HB_OS_OS2 )
|
||||
{
|
||||
ULONG state = 0;
|
||||
|
||||
nWritten = 0;
|
||||
if( DosQueryNPHState( ( HPIPE ) hPipeHandle, &state ) == NO_ERROR )
|
||||
{
|
||||
HB_MAXUINT end_timer = nTimeOut > 0 ? hb_dateMilliSeconds() + nTimeOut : 0;
|
||||
@@ -1147,7 +1148,10 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi
|
||||
DosSetNPHState( ( HPIPE ) hPipeHandle, state );
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_fsSetIOError( HB_FALSE, 0 );
|
||||
nWritten = ( HB_SIZE ) -1;
|
||||
}
|
||||
}
|
||||
#elif defined( HB_OS_UNIX ) && ! defined( HB_OS_SYMBIAN )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user