ENH: Removed pipe selection argument from WaitForData method in kwsysProcess. This greatly simplifies its use.

This commit is contained in:
Brad King 2003-12-05 11:53:17 -05:00
parent 97b469537b
commit ed853b5d70
7 changed files with 18 additions and 37 deletions

View File

@ -2363,9 +2363,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string* output,
std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl; std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl;
std::cout << " " << std::flush; std::cout << " " << std::flush;
} }
while(cmsysProcess_WaitForData(cp, (cmsysProcess_Pipe_STDOUT | while(cmsysProcess_WaitForData(cp, &data, &length, 0))
cmsysProcess_Pipe_STDERR),
&data, &length, 0))
{ {
if ( output ) if ( output )
{ {
@ -2454,9 +2452,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *re
char* data; char* data;
int length; int length;
while(cmsysProcess_WaitForData(cp, (cmsysProcess_Pipe_STDOUT | while(cmsysProcess_WaitForData(cp, &data, &length, 0))
cmsysProcess_Pipe_STDERR),
&data, &length, 0))
{ {
if ( output ) if ( output )
{ {

View File

@ -403,9 +403,7 @@ bool cmSystemTools::RunSingleCommand(
std::vector<char> tempOutput; std::vector<char> tempOutput;
char* data; char* data;
int length; int length;
while(cmsysProcess_WaitForData(cp, (cmsysProcess_Pipe_STDOUT | while(cmsysProcess_WaitForData(cp, &data, &length, 0))
cmsysProcess_Pipe_STDERR),
&data, &length, 0))
{ {
if ( output ) if ( output )
{ {

View File

@ -213,13 +213,9 @@ kwsysEXPORT const char* kwsysProcess_GetErrorString(kwsysProcess* cp);
kwsysEXPORT void kwsysProcess_Execute(kwsysProcess* cp); kwsysEXPORT void kwsysProcess_Execute(kwsysProcess* cp);
/** /**
* Block until data are available on a requested pipe, a timeout * Block until data are available on a pipe, a timeout expires, or the
* expires, or the child process terminates. Arguments are as * child process terminates. Arguments are as follows:
* follows:
* *
* pipes = Flags for the child output pipes of interest to the caller.
* Possible values are Pipe_STDOUT and Pipe_STDERR. Multiple
* pipes may be specified by using the bitwise OR operator '|'.
* data = If data are read, the pointer to which this points is * data = If data are read, the pointer to which this points is
* set to point to the data. * set to point to the data.
* length = If data are read, the integer to which this points is * length = If data are read, the integer to which this points is
@ -241,9 +237,8 @@ kwsysEXPORT void kwsysProcess_Execute(kwsysProcess* cp);
* call. Time elapsed has been subtracted from timeout * call. Time elapsed has been subtracted from timeout
* argument. * argument.
*/ */
kwsysEXPORT int kwsysProcess_WaitForData(kwsysProcess* cp, int pipes, kwsysEXPORT int kwsysProcess_WaitForData(kwsysProcess* cp, char** data,
char** data, int* length, int* length, double* timeout);
double* timeout);
enum kwsysProcess_Pipes_e enum kwsysProcess_Pipes_e
{ {
kwsysProcess_Pipe_STDOUT=1, kwsysProcess_Pipe_STDOUT=1,

View File

@ -486,8 +486,8 @@ void kwsysProcess_Execute(kwsysProcess* cp)
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int kwsysProcess_WaitForData(kwsysProcess* cp, int pipes, char** data, int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
int* length, double* userTimeout) double* userTimeout)
{ {
int i; int i;
int max = -1; int max = -1;
@ -537,9 +537,9 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, int pipes, char** data,
{ {
/* This is data on the special termination pipe. Ignore it. */ /* This is data on the special termination pipe. Ignore it. */
} }
else if(pipes & (1 << i)) else if(data && length)
{ {
/* Caller wants this data. Report it. */ /* Report this data. */
*data = cp->PipeBuffer; *data = cp->PipeBuffer;
*length = n; *length = n;
pipeId = (1 << i); pipeId = (1 << i);
@ -687,7 +687,7 @@ int kwsysProcess_WaitForExit(kwsysProcess* cp, double* userTimeout)
} }
/* Wait for all the pipes to close. Ignore all data. */ /* Wait for all the pipes to close. Ignore all data. */
while((pipe = kwsysProcess_WaitForData(cp, 0, 0, 0, userTimeout)) > 0) while((pipe = kwsysProcess_WaitForData(cp, 0, 0, userTimeout)) > 0)
{ {
if(pipe == kwsysProcess_Pipe_Timeout) if(pipe == kwsysProcess_Pipe_Timeout)
{ {

View File

@ -921,7 +921,7 @@ void kwsysProcess_Execute(kwsysProcess* cp)
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int kwsysProcess_WaitForData(kwsysProcess* cp, int pipes, char** data, int* length, int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
double* userTimeout) double* userTimeout)
{ {
kwsysProcessTime userStartTime; kwsysProcessTime userStartTime;
@ -997,18 +997,14 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, int pipes, char** data, int* leng
/* The pipe closed. */ /* The pipe closed. */
--cp->PipesLeft; --cp->PipesLeft;
} }
else if(pipes & (1 << cp->CurrentIndex)) else if(data && length)
{ {
/* Caller wants this data. Report it. */ /* Report this data. */
*data = cp->Pipe[cp->CurrentIndex].DataBuffer; *data = cp->Pipe[cp->CurrentIndex].DataBuffer;
*length = cp->Pipe[cp->CurrentIndex].DataLength; *length = cp->Pipe[cp->CurrentIndex].DataLength;
pipeId = (1 << cp->CurrentIndex); pipeId = (1 << cp->CurrentIndex);
done = 1; done = 1;
} }
else
{
/* Caller does not care about this pipe. Ignore the data. */
}
} }
else else
{ {
@ -1074,7 +1070,7 @@ int kwsysProcess_WaitForExit(kwsysProcess* cp, double* userTimeout)
} }
/* Wait for the process to terminate. Ignore all data. */ /* Wait for the process to terminate. Ignore all data. */
while((pipe = kwsysProcess_WaitForData(cp, 0, 0, 0, userTimeout)) > 0) while((pipe = kwsysProcess_WaitForData(cp, 0, 0, userTimeout)) > 0)
{ {
if(pipe == kwsysProcess_Pipe_Timeout) if(pipe == kwsysProcess_Pipe_Timeout)
{ {

View File

@ -11,9 +11,7 @@ int main()
kwsysProcess_Execute(kp); kwsysProcess_Execute(kp);
char* data = 0; char* data = 0;
int length = 0; int length = 0;
while(kwsysProcess_WaitForData(kp, (kwsysProcess_Pipe_STDOUT | while(kwsysProcess_WaitForData(kp, &data, &length, 0))
kwsysProcess_Pipe_STDERR),
&data, &length, 0))
{ {
kwsys_std::cout.write(data, length); kwsys_std::cout.write(data, length);
} }

View File

@ -66,9 +66,7 @@ int runChild(const char* cmd[], int state, int exception, int value)
kwsysProcess_SetTimeout(kp, 3); kwsysProcess_SetTimeout(kp, 3);
kwsysProcess_Execute(kp); kwsysProcess_Execute(kp);
while(kwsysProcess_WaitForData(kp, (kwsysProcess_Pipe_STDOUT | while(kwsysProcess_WaitForData(kp, &data, &length, 0))
kwsysProcess_Pipe_STDERR),
&data, &length, 0))
{ {
fwrite(data, 1, length, stdout); fwrite(data, 1, length, stdout);
fflush(stdout); fflush(stdout);