MCPcopy Create free account
hub / github.com/Kitware/CMake / kwsysProcess_WaitForData

Function kwsysProcess_WaitForData

Source/kwsys/ProcessUNIX.c:1075–1134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1073 kwsysProcessWaitData* wd);
1074
1075int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
1076 double* userTimeout)
1077{
1078 kwsysProcessTime userStartTime = { 0, 0 };
1079 kwsysProcessWaitData wd = { 0, kwsysProcess_Pipe_None, 0, 0, { 0, 0 } };
1080 wd.UserTimeout = userTimeout;
1081 /* Make sure we are executing a process. */
1082 if (!cp || cp->State != kwsysProcess_State_Executing || cp->Killed ||
1083 cp->TimeoutExpired) {
1084 return kwsysProcess_Pipe_None;
1085 }
1086
1087 /* Record the time at which user timeout period starts. */
1088 if (userTimeout) {
1089 userStartTime = kwsysProcessTimeGetCurrent();
1090 }
1091
1092 /* Calculate the time at which a timeout will expire, and whether it
1093 is the user or process timeout. */
1094 wd.User = kwsysProcessGetTimeoutTime(cp, userTimeout, &wd.TimeoutTime);
1095
1096 /* Data can only be available when pipes are open. If the process
1097 is not running, cp->PipesLeft will be 0. */
1098 while (cp->PipesLeft > 0 &&
1099 !kwsysProcessWaitForPipe(cp, data, length, &wd)) {
1100 }
1101
1102 /* Update the user timeout. */
1103 if (userTimeout) {
1104 kwsysProcessTime userEndTime = kwsysProcessTimeGetCurrent();
1105 kwsysProcessTime difference =
1106 kwsysProcessTimeSubtract(userEndTime, userStartTime);
1107 double d = kwsysProcessTimeToDouble(difference);
1108 *userTimeout -= d;
1109 if (*userTimeout < 0) {
1110 *userTimeout = 0;
1111 }
1112 }
1113
1114 /* Check what happened. */
1115 if (wd.PipeId) {
1116 /* Data are ready on a pipe. */
1117 return wd.PipeId;
1118 }
1119 if (wd.Expired) {
1120 /* A timeout has expired. */
1121 if (wd.User) {
1122 /* The user timeout has expired. It has no time left. */
1123 return kwsysProcess_Pipe_Timeout;
1124 }
1125
1126 /* The process timeout has expired. Kill the children now. */
1127 kwsysProcess_Kill(cp);
1128 cp->Killed = 0;
1129 cp->TimeoutExpired = 1;
1130 return kwsysProcess_Pipe_None;
1131 }
1132 /* No pipes are left open. */

Callers 3

runChild2Function · 0.70
kwsysProcess_WaitForExitFunction · 0.70
RunProcessMethod · 0.70

Calls 6

kwsysProcessWaitForPipeFunction · 0.85
kwsysProcessTimeSubtractFunction · 0.70
kwsysProcessTimeToDoubleFunction · 0.70
kwsysProcess_KillFunction · 0.70

Tested by 1

runChild2Function · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…