Behavior differs for the following scenario: if, while the thread
sleeps in io_input() called from recvclient(), at least one line of
input arrives and the thread gets awakened by the update aborting
commands, then the old code throws away the first line of input, but
the new code doesn't.
* is "ctld", set the player's eof flag and return -1.
* Else return the length of the line.
* Design bug: there is no way to indicate truncation of a long line.
* is "ctld", set the player's eof flag and return -1.
* Else return the length of the 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
recvclient(char *cmd, int size)
{
int count;
*/
int
recvclient(char *cmd, int size)
{
int count;
- if (player->eof)
- return -1;
- if (player->aborted)
- return -2;
-
- count = io_gets(player->iop, cmd, size);
-
- while (!player->aborted && !player->eof && count < 0) {
- /* Sleep for input */
+ count = -1;
+ while (!player->aborted && !player->eof) {
+ /* Try to get a line of input */
+ count = io_gets(player->iop, cmd, size);
+ if (count >= 0) {
+ /* got it */
+ if (strcmp(cmd, "ctld") == 0)
+ player->eof = 1;
+ if (strcmp(cmd, "aborted") == 0)
+ player->aborted = 1;
+ break;
+ }
/* Make sure player sees prompt */
io_output_all(player->iop);
/* Make sure player sees prompt */
io_output_all(player->iop);
* abortion, we must return without blocking in io_input().
*/
if (player->aborted)
* abortion, we must return without blocking in io_input().
*/
if (player->aborted)
io_input(player->iop, IO_WAIT);
if (io_error(player->iop))
player->aborted = 1;
else if (io_eof(player->iop))
player->eof = 1;
io_input(player->iop, IO_WAIT);
if (io_error(player->iop))
player->aborted = 1;
else if (io_eof(player->iop))
player->eof = 1;
- else
- count = io_gets(player->iop, cmd, size);
- }
-
- if (count > 0) {
- if (strcmp(cmd, "ctld") == 0)
- player->eof = 1;
- if (strcmp(cmd, "aborted") == 0)
- player->aborted = 1;