An image (*.jpg) is passed to ET via an input pipe, along with some selected command line options and it returns its output via a piped output stream back to my app. In some ways, ET looks like a memory resident application.
For some cases, the code as taken from the example drops the last partial buffer. But I cannot be sure whether it is related to output length or system load.
The code I am using looks like
Code: Select all
bool MyFrame::DoGetStream( wxArrayString &ar_wasIn, wxInputStream& in )
{
wxString wsBuffer;
char buffer[4096 + 1];
ar_wasIn.clear();
in.Reset();
while ( in.CanRead() )
{
memset( buffer, '\0', WXSIZEOF(buffer) - 1 );
buffer[in.Read(buffer, WXSIZEOF(buffer) - 1).LastRead()] = '\0';
wsBuffer += buffer;
#if defined( TEST_STREAM )
::wxMilliSleep( 5);
#endif
}
wxStringTokenizer tokenizer( wsBuffer, "\r\n");
while ( tokenizer.HasMoreTokens() )
{
wxString wsToken = tokenizer.GetNextToken();
ar_wasIn.Add( wsToken );
}
return true;
}
If I include the line ::wxMilliSleep( 5); in the loop, the code works as expected for the cases I have tested.
Without that line, there is at least one image for which the last 0x260 characters (2-bytes wide) out of a total of 0x2260 are lost and are not appended to wsBuffer. IOW, it looks like the CanRead() timeout somewhere during the last few bytes and drops out without appending them.
My problem: How can I ensure that this works as expected in general.
Using a hardwired sleep of 5 milliseconds may work on my current machine with the current normal work load, but it is not a good solution at all.
And, even if I could change the time out value for the input stream, how can I ensure it works for all cases, other than possibly a user controlled wxMilliSleep delay?