Remove IO_NOWAIT, IO_WAIT

They make the code slightly clearer in some places, and more
complicated in others.  Not worth it.
This commit is contained in:
Markus Armbruster 2009-04-26 10:36:57 +02:00
parent 55c53b9add
commit 2e4f63c270
5 changed files with 21 additions and 29 deletions

View file

@ -42,9 +42,6 @@
#define IO_BUFSIZE 4096
#define IO_NOWAIT 0
#define IO_WAIT 1
extern struct iop *io_open(int, int, int, struct timeval);
extern void io_init(void);
extern void io_close(struct iop *);

View file

@ -183,15 +183,14 @@ io_outputwaiting(struct iop *iop)
/*
* Write output queued in IOP.
* If WAITFOROUTPUT != IO_NOWAIT, writing may put the thread to sleep.
* If WAIT, writing may put the thread to sleep.
* Return number of bytes written on success, -1 on error.
* In particular, return zero when nothing was written because the
* queue was empty, or because the write slept and got woken up (only
* if WAITFOROUTPUT != IO_NOWAIT), or because the write refused to
* sleep (only if WAITFOROUTPUT == IO_NOWAIT).
* if WAIT), or because the write refused to sleep (only if !WAIT).
*/
int
io_output(struct iop *iop, int waitforoutput)
io_output(struct iop *iop, int wait)
{
struct iovec iov[16];
int n, res, cc;
@ -207,7 +206,7 @@ io_output(struct iop *iop, int waitforoutput)
n = ioq_makeiov(iop->output, iov, IO_BUFSIZE);
if (waitforoutput != IO_NOWAIT) {
if (wait) {
res = empth_select(iop->fd, EMPTH_FD_WRITE, NULL);
if (res == 0)
return 0;
@ -251,7 +250,7 @@ io_read(struct iop *iop, char *buf, int nbytes)
}
int
io_write(struct iop *iop, char *buf, int nbytes, int doWait)
io_write(struct iop *iop, char *buf, int nbytes, int wait)
{
int len;
@ -260,12 +259,12 @@ io_write(struct iop *iop, char *buf, int nbytes, int doWait)
ioq_append(iop->output, buf, nbytes);
len = ioq_qsize(iop->output);
if (len > iop->bufsize) {
if (doWait) {
if (wait) {
io_output_all(iop);
} else {
/* only try a write every BUFSIZE characters */
if (((len - nbytes) % iop->bufsize) < (len % iop->bufsize))
io_output(iop, IO_NOWAIT);
io_output(iop, 0);
}
}
return nbytes;
@ -280,7 +279,7 @@ io_output_all(struct iop *iop)
* Mustn't block a player thread while update is pending, or else
* a malicous player could delay the update indefinitely
*/
while ((n = io_output(iop, IO_NOWAIT)) > 0 && !play_wrlock_wanted)
while ((n = io_output(iop, 0)) > 0 && !play_wrlock_wanted)
empth_select(iop->fd, EMPTH_FD_WRITE, NULL);
return n;

View file

@ -87,9 +87,9 @@ player_login(void *ud)
pr_id(player, C_INIT, "Empire server ready\n");
while (player->state != PS_SHUTDOWN) {
io_output(player->iop, IO_WAIT);
io_output(player->iop, 1);
if (io_gets(player->iop, buf, sizeof(buf)) < 0) {
res = io_input(player->iop, IO_WAIT);
res = io_input(player->iop, 1);
if (res <= 0) {
if (res == 0 && !io_eof(player->iop))
pr_id(player, C_DATA, "idle connection terminated\n");
@ -118,7 +118,7 @@ player_login(void *ud)
player->state = PS_SHUTDOWN;
if (!io_eof(player->iop)) {
pr_id(player, C_EXIT, "so long...\n");
while (io_output(player->iop, IO_WAIT) > 0) ;
while (io_output(player->iop, 1) > 0) ;
}
player_delete(player);
empth_exit();

View file

@ -85,7 +85,7 @@ recvclient(char *cmd, int size)
if (player->aborted)
break;
res = io_input(player->iop, IO_WAIT);
res = io_input(player->iop, 1);
if (res > 0)
;
else if (res < 0)

View file

@ -152,7 +152,7 @@ pr_flash(struct player *pl, char *format, ...)
if (!(pl->flags & PF_UTF8))
copy_utf8_to_ascii_no_funny(buf, buf);
pr_player(pl, C_FLASH, buf);
io_output(pl->iop, IO_NOWAIT);
io_output(pl->iop, 0);
}
/*
@ -173,7 +173,7 @@ pr_inform(struct player *pl, char *format, ...)
(void)vsprintf(buf, format, ap);
va_end(ap);
pr_player(pl, C_INFORM, buf);
io_output(pl->iop, IO_NOWAIT);
io_output(pl->iop, 0);
}
/*
@ -205,7 +205,7 @@ pr_wall(char *format, ...)
if (p->state != PS_PLAYING)
continue;
pr_player(p, C_FLASH, buf);
io_output(p->iop, IO_NOWAIT);
io_output(p->iop, 0);
}
}
@ -233,11 +233,9 @@ pr_player(struct player *pl, int id, char *buf)
p = strchr(bp, '\n');
if (p != NULL) {
len = (p - bp) + 1;
if ((pl->command && (pl->command->c_flags & C_MOD)) ||
(player != pl))
io_write(pl->iop, bp, len, IO_NOWAIT);
else
io_write(pl->iop, bp, len, IO_WAIT);
io_write(pl->iop, bp, len,
player == pl
&& !(pl->command && (pl->command->c_flags & C_MOD)));
bp += len;
pl->curid = -1;
} else {
@ -288,11 +286,9 @@ upr_player(struct player *pl, int id, char *buf)
}
}
if (ch == '\n') {
if ((pl->command && (pl->command->c_flags & C_MOD)) ||
(player != pl))
io_write(pl->iop, &ch, 1, IO_NOWAIT);
else
io_write(pl->iop, &ch, 1, IO_WAIT);
io_write(pl->iop, &ch, 1,
player == pl
&& !(pl->command && (pl->command->c_flags & C_MOD)));
pl->curid = -1;
} else {
printbuf[0] = ch;