Shut down session on receipt of "ctld\n" even when reading arguments:

(player): New member eof.
(recvclient): Return -1 without receiving input when it is set.  Set
it on receipt of "ctld\n".
(execute): Clear it after receiving the script.
This commit is contained in:
Markus Armbruster 2007-11-15 19:10:04 +00:00
parent bd0d5c10b6
commit 79407e68fd
3 changed files with 28 additions and 6 deletions

View file

@ -76,7 +76,8 @@ struct player {
double dolcost; double dolcost;
int broke; int broke;
time_t curup; /* when last input was received */ time_t curup; /* when last input was received */
int aborted; int aborted; /* interrupt cookie received? */
int eof; /* EOF (cookie or real) received? */
int curid; /* for pr, cur. line's id, -1 none */ int curid; /* for pr, cur. line's id, -1 none */
char *map; /* pointer to in-mem map */ char *map; /* pointer to in-mem map */
char *bmap; /* pointer to in-mem bmap */ char *bmap; /* pointer to in-mem bmap */

View file

@ -302,6 +302,7 @@ execute(void)
} }
if (redir == NULL) if (redir == NULL)
pr("Execute : %s\n", failed ? "aborted" : "terminated"); pr("Execute : %s\n", failed ? "aborted" : "terminated");
player->eof = 0;
return RET_OK; return RET_OK;
} }

View file

@ -40,6 +40,7 @@
/* /*
* Receive a line of input from the current player. * Receive a line of input from the current player.
* If the player's eof flag is set, return -1 without receiving input.
* If the player's aborted flag is set, return -2 without receiving * If the player's aborted flag is set, return -2 without receiving
* input. * input.
* Else receive one line and store it in CMD[SIZE]. * Else receive one line and store it in CMD[SIZE].
@ -48,38 +49,57 @@
* If the player's connection has the I/O error indicator set, or the * If the player's connection has the I/O error indicator set, or the
* line is "aborted", set the player's aborted flag and return -2. * line is "aborted", set the player's aborted flag and return -2.
* If the player's connection has the EOF indicator set, or the line * If the player's connection has the EOF indicator set, or the line
* is "ctld", return -1. * is "ctld", set the player's eof flag and return -1.
* Else return the length of the line. * Else return the length of the line.
* Design bug: there is no way to indicate truncation of a long line. * Design bug: there is no way to indicate truncation of a long line.
* FIXME caller needs to know whether a line was consumed, to prompt correctly
*/ */
int int
recvclient(char *cmd, int size) recvclient(char *cmd, int size)
{ {
int count; int count;
if (player->eof)
return -1;
if (player->aborted) if (player->aborted)
return -2; return -2;
count = io_gets(player->iop, cmd, size); count = io_gets(player->iop, cmd, size);
while (!player->aborted && count < 0) {
while (!player->aborted && !player->eof && count < 0) {
/* Sleep for input */
/* Make sure player sees prompt */
io_output_all(player->iop); io_output_all(player->iop);
/*
* If io_output_all() blocked and got unblocked by command
* abortion, we must return without blocking in io_input().
*/
if (player->aborted) if (player->aborted)
return -2; return -2;
io_input(player->iop, IO_WAIT); io_input(player->iop, IO_WAIT);
if (io_error(player->iop)) if (io_error(player->iop))
player->aborted++; player->aborted = 1;
else if (io_eof(player->iop)) else if (io_eof(player->iop))
return -1; player->eof = 1;
else else
count = io_gets(player->iop, cmd, size); count = io_gets(player->iop, cmd, size);
} }
if (count > 0) { if (count > 0) {
if (strcmp(cmd, "ctld") == 0) if (strcmp(cmd, "ctld") == 0)
return -1; player->eof = 1;
if (strcmp(cmd, "aborted") == 0) if (strcmp(cmd, "aborted") == 0)
player->aborted = 1; player->aborted = 1;
} }
if (player->eof)
return -1;
if (player->aborted) if (player->aborted)
return -2; return -2;
journal_input(cmd); journal_input(cmd);
return count; return count;
} }