Windows execmd: do check for cancellation

This commit is contained in:
Jean-Francois Dockes 2015-09-08 18:16:46 +02:00
parent 6590598765
commit fa13c25f6f
4 changed files with 29 additions and 11 deletions

View file

@ -152,6 +152,7 @@
<ClInclude Include="..\index\mimetype.h" />
<ClInclude Include="..\internfile\internfile.h" />
<ClInclude Include="..\internfile\mh_symlink.h" />
<ClInclude Include="..\utils\cancelcheck.h" />
<ClInclude Include="..\utils\cpuconf.h" />
<ClInclude Include="..\utils\debuglog.h" />
<ClInclude Include="..\utils\execmd.h" />

View file

@ -93,6 +93,9 @@
<ClInclude Include="..\utils\cpuconf.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\utils\cancelcheck.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\utils\smallut.cpp">

View file

@ -512,7 +512,7 @@ int ExecCmd::send(const string& data)
return -1;
}
WaitResult waitRes = Wait(m->oInputWrite.hEvent, 5000);
WaitResult waitRes = Wait(m->oInputWrite.hEvent, m->timeoutMs);
if (waitRes == Ok) {
if (!GetOverlappedResult(m->hInputWrite,
&m->oInputWrite, &dwWritten, TRUE)) {
@ -569,7 +569,9 @@ int ExecCmd::receive(string& data, int cnt)
}
totread += dwRead;
data.append(chBuf, dwRead);
LOGDEB1(("ExecCmd::receive: got %d bytes\n", int(dwRead)));
if (m->advise)
m->advise->newData(dwRead);
LOGDEB(("ExecCmd::receive: got %d bytes\n", int(dwRead)));
} else if (waitRes == Quit) {
if (!CancelIo(m->hOutputRead)) {
printError("CancelIo");
@ -577,11 +579,16 @@ int ExecCmd::receive(string& data, int cnt)
break;
} else if (waitRes == Timeout) {
// We only want to cancel if m_advise says so here. Is the io still
// valid at this point ?
if (!CancelIo(m->hOutputRead)) {
printError("CancelIo");
}
break;
// valid at this point ? Should we catch a possible exception to CancelIo?
if (m->advise)
m->advise->newData(0);
if (m->killRequest) {
LOGINFO(("ExecCmd::doexec: cancel request\n"));
if (!CancelIo(m->hOutputRead)) {
printError("CancelIo");
}
break;
}
}
}
return totread;

View file

@ -151,11 +151,12 @@ public:
void newData(int cnt) {
if (op_flags & OPT_c) {
static int callcnt;
if (callcnt++ == 10) {
if (callcnt++ == 5) {
// Just sets the cancellation flag
CancelCheck::instance().setCancel();
// Would be called from somewhere else and throws an
// exception. We call it here for simplicity
cerr << "newData: should throw !\n";
CancelCheck::instance().checkCancel();
}
}
@ -223,7 +224,13 @@ int main(int argc, char *argv[])
case 'm': op_flags |= OPT_m; break;
case 'i': op_flags |= OPT_i; break;
case 'o': op_flags |= OPT_o; break;
case'h': cout << "MESSAGE FROM TREXECMD\n"; return 0;
case'h':
for (int i = 0; i < 10; i++) {
cout << "MESSAGE " << i << " FROM TREXECMD\n";
cout.flush();
sleep(1);
}
return 0;
default: Usage(); break;
}
b1: argc--; argv++;
@ -265,10 +272,10 @@ int main(int argc, char *argv[])
// Set callback to be called whenever there is new data
// available and at a periodic interval, to check for
// cancellation
#ifdef LATER
MEAdv adv;
mexec.setAdvise(&adv);
mexec.setTimeout(5);
//mexec.setTimeout(5);
#ifdef LATER
// Stderr output goes there
mexec.setStderr("/tmp/trexecStderr");
#endif