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:
parent
55c53b9add
commit
2e4f63c270
5 changed files with 21 additions and 29 deletions
|
@ -42,9 +42,6 @@
|
||||||
|
|
||||||
#define IO_BUFSIZE 4096
|
#define IO_BUFSIZE 4096
|
||||||
|
|
||||||
#define IO_NOWAIT 0
|
|
||||||
#define IO_WAIT 1
|
|
||||||
|
|
||||||
extern struct iop *io_open(int, int, int, struct timeval);
|
extern struct iop *io_open(int, int, int, struct timeval);
|
||||||
extern void io_init(void);
|
extern void io_init(void);
|
||||||
extern void io_close(struct iop *);
|
extern void io_close(struct iop *);
|
||||||
|
|
|
@ -183,15 +183,14 @@ io_outputwaiting(struct iop *iop)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write output queued in 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.
|
* Return number of bytes written on success, -1 on error.
|
||||||
* In particular, return zero when nothing was written because the
|
* In particular, return zero when nothing was written because the
|
||||||
* queue was empty, or because the write slept and got woken up (only
|
* queue was empty, or because the write slept and got woken up (only
|
||||||
* if WAITFOROUTPUT != IO_NOWAIT), or because the write refused to
|
* if WAIT), or because the write refused to sleep (only if !WAIT).
|
||||||
* sleep (only if WAITFOROUTPUT == IO_NOWAIT).
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
io_output(struct iop *iop, int waitforoutput)
|
io_output(struct iop *iop, int wait)
|
||||||
{
|
{
|
||||||
struct iovec iov[16];
|
struct iovec iov[16];
|
||||||
int n, res, cc;
|
int n, res, cc;
|
||||||
|
@ -207,7 +206,7 @@ io_output(struct iop *iop, int waitforoutput)
|
||||||
|
|
||||||
n = ioq_makeiov(iop->output, iov, IO_BUFSIZE);
|
n = ioq_makeiov(iop->output, iov, IO_BUFSIZE);
|
||||||
|
|
||||||
if (waitforoutput != IO_NOWAIT) {
|
if (wait) {
|
||||||
res = empth_select(iop->fd, EMPTH_FD_WRITE, NULL);
|
res = empth_select(iop->fd, EMPTH_FD_WRITE, NULL);
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -251,7 +250,7 @@ io_read(struct iop *iop, char *buf, int nbytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
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;
|
int len;
|
||||||
|
|
||||||
|
@ -260,12 +259,12 @@ io_write(struct iop *iop, char *buf, int nbytes, int doWait)
|
||||||
ioq_append(iop->output, buf, nbytes);
|
ioq_append(iop->output, buf, nbytes);
|
||||||
len = ioq_qsize(iop->output);
|
len = ioq_qsize(iop->output);
|
||||||
if (len > iop->bufsize) {
|
if (len > iop->bufsize) {
|
||||||
if (doWait) {
|
if (wait) {
|
||||||
io_output_all(iop);
|
io_output_all(iop);
|
||||||
} else {
|
} else {
|
||||||
/* only try a write every BUFSIZE characters */
|
/* only try a write every BUFSIZE characters */
|
||||||
if (((len - nbytes) % iop->bufsize) < (len % iop->bufsize))
|
if (((len - nbytes) % iop->bufsize) < (len % iop->bufsize))
|
||||||
io_output(iop, IO_NOWAIT);
|
io_output(iop, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nbytes;
|
return nbytes;
|
||||||
|
@ -280,7 +279,7 @@ io_output_all(struct iop *iop)
|
||||||
* Mustn't block a player thread while update is pending, or else
|
* Mustn't block a player thread while update is pending, or else
|
||||||
* a malicous player could delay the update indefinitely
|
* 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);
|
empth_select(iop->fd, EMPTH_FD_WRITE, NULL);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
|
|
|
@ -87,9 +87,9 @@ player_login(void *ud)
|
||||||
pr_id(player, C_INIT, "Empire server ready\n");
|
pr_id(player, C_INIT, "Empire server ready\n");
|
||||||
|
|
||||||
while (player->state != PS_SHUTDOWN) {
|
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) {
|
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) {
|
||||||
if (res == 0 && !io_eof(player->iop))
|
if (res == 0 && !io_eof(player->iop))
|
||||||
pr_id(player, C_DATA, "idle connection terminated\n");
|
pr_id(player, C_DATA, "idle connection terminated\n");
|
||||||
|
@ -118,7 +118,7 @@ player_login(void *ud)
|
||||||
player->state = PS_SHUTDOWN;
|
player->state = PS_SHUTDOWN;
|
||||||
if (!io_eof(player->iop)) {
|
if (!io_eof(player->iop)) {
|
||||||
pr_id(player, C_EXIT, "so long...\n");
|
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);
|
player_delete(player);
|
||||||
empth_exit();
|
empth_exit();
|
||||||
|
|
|
@ -85,7 +85,7 @@ recvclient(char *cmd, int size)
|
||||||
if (player->aborted)
|
if (player->aborted)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
res = io_input(player->iop, IO_WAIT);
|
res = io_input(player->iop, 1);
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
;
|
;
|
||||||
else if (res < 0)
|
else if (res < 0)
|
||||||
|
|
|
@ -152,7 +152,7 @@ pr_flash(struct player *pl, char *format, ...)
|
||||||
if (!(pl->flags & PF_UTF8))
|
if (!(pl->flags & PF_UTF8))
|
||||||
copy_utf8_to_ascii_no_funny(buf, buf);
|
copy_utf8_to_ascii_no_funny(buf, buf);
|
||||||
pr_player(pl, C_FLASH, 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);
|
(void)vsprintf(buf, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
pr_player(pl, C_INFORM, buf);
|
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)
|
if (p->state != PS_PLAYING)
|
||||||
continue;
|
continue;
|
||||||
pr_player(p, C_FLASH, buf);
|
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');
|
p = strchr(bp, '\n');
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
len = (p - bp) + 1;
|
len = (p - bp) + 1;
|
||||||
if ((pl->command && (pl->command->c_flags & C_MOD)) ||
|
io_write(pl->iop, bp, len,
|
||||||
(player != pl))
|
player == pl
|
||||||
io_write(pl->iop, bp, len, IO_NOWAIT);
|
&& !(pl->command && (pl->command->c_flags & C_MOD)));
|
||||||
else
|
|
||||||
io_write(pl->iop, bp, len, IO_WAIT);
|
|
||||||
bp += len;
|
bp += len;
|
||||||
pl->curid = -1;
|
pl->curid = -1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -288,11 +286,9 @@ upr_player(struct player *pl, int id, char *buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
if ((pl->command && (pl->command->c_flags & C_MOD)) ||
|
io_write(pl->iop, &ch, 1,
|
||||||
(player != pl))
|
player == pl
|
||||||
io_write(pl->iop, &ch, 1, IO_NOWAIT);
|
&& !(pl->command && (pl->command->c_flags & C_MOD)));
|
||||||
else
|
|
||||||
io_write(pl->iop, &ch, 1, IO_WAIT);
|
|
||||||
pl->curid = -1;
|
pl->curid = -1;
|
||||||
} else {
|
} else {
|
||||||
printbuf[0] = ch;
|
printbuf[0] = ch;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue