replaced IsAvailable() with CanRead() in wxPipeStream

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17694 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-11-04 00:40:59 +00:00
parent 5a86eeac8c
commit 405fff1bad
4 changed files with 26 additions and 60 deletions

View File

@@ -81,7 +81,7 @@ inline void wxStreamTempInputBuffer::Init(wxPipeInputStream *stream)
void wxStreamTempInputBuffer::Update()
{
if ( m_stream && m_stream->IsAvailable() )
if ( m_stream && m_stream->CanRead() )
{
// realloc in blocks of 4Kb: this is the default (and minimal) buffer
// size of the Unix pipes so it should be the optimal step
@@ -111,24 +111,5 @@ wxStreamTempInputBuffer::~wxStreamTempInputBuffer()
}
}
// ----------------------------------------------------------------------------
// platform-dependent parts of wxProcess implementation included
// ----------------------------------------------------------------------------
bool wxProcess::IsInputOpened() const
{
return m_inputStream && ((wxPipeInputStream *)m_inputStream)->IsOpened();
}
bool wxProcess::IsInputAvailable() const
{
return m_inputStream && ((wxPipeInputStream *)m_inputStream)->IsAvailable();
}
bool wxProcess::IsErrorAvailable() const
{
return m_errorStream && ((wxPipeInputStream *)m_errorStream)->IsAvailable();
}
#endif // _WX_WXEXEC_CPP_

View File

@@ -120,28 +120,22 @@ void wxProcess::SetPipeStreams(wxInputStream *inputSstream,
m_outputStream = outputStream;
}
// these are implemented in platform-dependent (and correct!) way under MSW and
// Unix but we still have to provide these dummy versions for the other
// platforms here
#if !defined(__WIN32__) && !defined(__UNIX_LIKE__)
bool wxProcess::IsInputOpened() const
{
return m_inputStream != NULL;
return m_inputStream &&
m_inputStream->GetLastError() != wxSTREAM_PIPE_ERROR;
}
bool wxProcess::IsInputAvailable() const
{
return m_inputStream && !m_inputStream->Eof();
return m_inputStream && m_inputStream->CanRead();
}
bool wxProcess::IsErrorAvailable() const
{
return m_errorStream && !m_errorStream->Eof();
return m_errorStream && m_errorStream->CanRead();
}
#endif // !Win32 && !Unix
#endif // wxUSE_STREAMS
// ----------------------------------------------------------------------------

View File

@@ -139,7 +139,7 @@ public:
bool IsOpened() const { return m_hInput != INVALID_HANDLE_VALUE; }
// returns TRUE if there is any data to be read from the pipe
bool IsAvailable() const;
virtual bool CanRead() const;
protected:
size_t OnSysRead(void *buffer, size_t len);
@@ -341,12 +341,12 @@ wxPipeInputStream::~wxPipeInputStream()
::CloseHandle(m_hInput);
}
bool wxPipeInputStream::IsAvailable() const
bool wxPipeInputStream::CanRead() const
{
// FIXME
#ifdef __WXWINE__
return FALSE;
#else
#else // !Wine
if ( !IsOpened() )
return FALSE;
@@ -374,37 +374,29 @@ bool wxPipeInputStream::IsAvailable() const
// it had been closed
::CloseHandle(m_hInput);
wxConstCast(this, wxPipeInputStream)->m_hInput = INVALID_HANDLE_VALUE;
wxPipeInputStream *self = wxConstCast(this, wxPipeInputStream);
return FALSE;
self->m_hInput = INVALID_HANDLE_VALUE;
self->m_lasterror = wxSTREAM_PIPE_ERROR;
nAvailable = 0;
}
return nAvailable != 0;
#endif
#endif // Wine/!Wine
}
size_t wxPipeInputStream::OnSysRead(void *buffer, size_t len)
{
// reading from a pipe may block if there is no more data, always check for
// EOF first
if ( !IsAvailable() )
{
m_lasterror = wxSTREAM_EOF;
return 0;
}
m_lasterror = wxSTREAM_NOERROR;
DWORD bytesRead;
if ( !::ReadFile(m_hInput, buffer, len, &bytesRead, NULL) )
{
if ( ::GetLastError() == ERROR_BROKEN_PIPE )
m_lasterror = wxSTREAM_EOF;
else
m_lasterror = wxSTREAM_READ_ERROR;
m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
? wxSTREAM_EOF
: wxSTREAM_READ_ERROR;
}
// bytesRead is set to 0, as desired, if an error occured
return bytesRead;
}
@@ -424,18 +416,17 @@ wxPipeOutputStream::~wxPipeOutputStream()
size_t wxPipeOutputStream::OnSysWrite(const void *buffer, size_t len)
{
DWORD bytesRead;
DWORD bytesWritten;
m_lasterror = wxSTREAM_NOERROR;
if ( !::WriteFile(m_hOutput, buffer, len, &bytesRead, NULL) )
if ( !::WriteFile(m_hOutput, buffer, len, &bytesWritten, NULL) )
{
if ( ::GetLastError() == ERROR_BROKEN_PIPE )
m_lasterror = wxSTREAM_EOF;
else
m_lasterror = wxSTREAM_READ_ERROR;
m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
? wxSTREAM_EOF
: wxSTREAM_WRITE_ERROR;
}
return bytesRead;
return bytesWritten;
}
#endif // wxUSE_STREAMS

View File

@@ -362,10 +362,10 @@ public:
bool IsOpened() const { return !Eof(); }
// return TRUE if we have anything to read, don't block
bool IsAvailable() const;
virtual bool CanRead() const;
};
bool wxPipeInputStream::IsAvailable() const
bool wxPipeInputStream::CanRead() const
{
if ( m_lasterror == wxSTREAM_EOF )
return FALSE;