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:
@@ -81,7 +81,7 @@ inline void wxStreamTempInputBuffer::Init(wxPipeInputStream *stream)
|
|||||||
|
|
||||||
void wxStreamTempInputBuffer::Update()
|
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
|
// realloc in blocks of 4Kb: this is the default (and minimal) buffer
|
||||||
// size of the Unix pipes so it should be the optimal step
|
// 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_
|
#endif // _WX_WXEXEC_CPP_
|
||||||
|
|
||||||
|
@@ -120,28 +120,22 @@ void wxProcess::SetPipeStreams(wxInputStream *inputSstream,
|
|||||||
m_outputStream = outputStream;
|
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
|
bool wxProcess::IsInputOpened() const
|
||||||
{
|
{
|
||||||
return m_inputStream != NULL;
|
return m_inputStream &&
|
||||||
|
m_inputStream->GetLastError() != wxSTREAM_PIPE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxProcess::IsInputAvailable() const
|
bool wxProcess::IsInputAvailable() const
|
||||||
{
|
{
|
||||||
return m_inputStream && !m_inputStream->Eof();
|
return m_inputStream && m_inputStream->CanRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxProcess::IsErrorAvailable() const
|
bool wxProcess::IsErrorAvailable() const
|
||||||
{
|
{
|
||||||
return m_errorStream && !m_errorStream->Eof();
|
return m_errorStream && m_errorStream->CanRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !Win32 && !Unix
|
|
||||||
|
|
||||||
#endif // wxUSE_STREAMS
|
#endif // wxUSE_STREAMS
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -139,7 +139,7 @@ public:
|
|||||||
bool IsOpened() const { return m_hInput != INVALID_HANDLE_VALUE; }
|
bool IsOpened() const { return m_hInput != INVALID_HANDLE_VALUE; }
|
||||||
|
|
||||||
// returns TRUE if there is any data to be read from the pipe
|
// returns TRUE if there is any data to be read from the pipe
|
||||||
bool IsAvailable() const;
|
virtual bool CanRead() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
size_t OnSysRead(void *buffer, size_t len);
|
size_t OnSysRead(void *buffer, size_t len);
|
||||||
@@ -341,12 +341,12 @@ wxPipeInputStream::~wxPipeInputStream()
|
|||||||
::CloseHandle(m_hInput);
|
::CloseHandle(m_hInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxPipeInputStream::IsAvailable() const
|
bool wxPipeInputStream::CanRead() const
|
||||||
{
|
{
|
||||||
// FIXME
|
// FIXME
|
||||||
#ifdef __WXWINE__
|
#ifdef __WXWINE__
|
||||||
return FALSE;
|
return FALSE;
|
||||||
#else
|
#else // !Wine
|
||||||
if ( !IsOpened() )
|
if ( !IsOpened() )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@@ -374,37 +374,29 @@ bool wxPipeInputStream::IsAvailable() const
|
|||||||
// it had been closed
|
// it had been closed
|
||||||
::CloseHandle(m_hInput);
|
::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;
|
return nAvailable != 0;
|
||||||
#endif
|
#endif // Wine/!Wine
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxPipeInputStream::OnSysRead(void *buffer, size_t len)
|
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;
|
DWORD bytesRead;
|
||||||
if ( !::ReadFile(m_hInput, buffer, len, &bytesRead, NULL) )
|
if ( !::ReadFile(m_hInput, buffer, len, &bytesRead, NULL) )
|
||||||
{
|
{
|
||||||
if ( ::GetLastError() == ERROR_BROKEN_PIPE )
|
m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
|
||||||
m_lasterror = wxSTREAM_EOF;
|
? wxSTREAM_EOF
|
||||||
else
|
: wxSTREAM_READ_ERROR;
|
||||||
m_lasterror = wxSTREAM_READ_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bytesRead is set to 0, as desired, if an error occured
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,18 +416,17 @@ wxPipeOutputStream::~wxPipeOutputStream()
|
|||||||
|
|
||||||
size_t wxPipeOutputStream::OnSysWrite(const void *buffer, size_t len)
|
size_t wxPipeOutputStream::OnSysWrite(const void *buffer, size_t len)
|
||||||
{
|
{
|
||||||
DWORD bytesRead;
|
DWORD bytesWritten;
|
||||||
|
|
||||||
m_lasterror = wxSTREAM_NOERROR;
|
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 = ::GetLastError() == ERROR_BROKEN_PIPE
|
||||||
m_lasterror = wxSTREAM_EOF;
|
? wxSTREAM_EOF
|
||||||
else
|
: wxSTREAM_WRITE_ERROR;
|
||||||
m_lasterror = wxSTREAM_READ_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesRead;
|
return bytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_STREAMS
|
#endif // wxUSE_STREAMS
|
||||||
|
@@ -362,10 +362,10 @@ public:
|
|||||||
bool IsOpened() const { return !Eof(); }
|
bool IsOpened() const { return !Eof(); }
|
||||||
|
|
||||||
// return TRUE if we have anything to read, don't block
|
// 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 )
|
if ( m_lasterror == wxSTREAM_EOF )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Reference in New Issue
Block a user