Reimplement max_idle without a separate thread

Remove the KillIdle thread.  Add timeout to struct iop, initialized in
io_open().  Obey it in io_input() by passing it to empth_select().  If
empth_select() times out, report that back through io_input() to
recvclient() and player_login().  If player_login() receives a timeout
indication, print a message and terminate the session.  If
recvclient() receives a timeout indication, flash a message to the
player and initiate a shut down the player's session.

Create WIN32 sys/time.h to define struct timeval.  This creates some
conflicts with WIN32 windows.h definitions.  Including windows.h in
show.c and info.c creates conflicts, so remove that.  Modify service.c
to include sys/socket.h instead of windows.h to remove the conflict
with sys/time.h.
This commit is contained in:
Ron Koenderink 2009-02-01 06:22:26 -06:00 committed by Markus Armbruster
parent a7ee69d112
commit 08b9455682
17 changed files with 181 additions and 133 deletions

View file

@ -289,65 +289,58 @@ empth_terminate(empth_t *a)
pthread_kill(a->id, SIGALRM);
}
void
empth_select(int fd, int flags)
int
empth_select(int fd, int flags, struct timeval *tv)
{
fd_set readmask;
fd_set writemask;
struct timeval tv;
int n;
int res = 0;
pthread_mutex_unlock(&mtx_ctxsw);
empth_status("%s select on %d",
flags == EMPTH_FD_READ ? "read" : "write", fd);
while (1) {
tv.tv_sec = 1000000;
tv.tv_usec = 0;
FD_ZERO(&readmask);
FD_ZERO(&writemask);
FD_ZERO(&readmask);
FD_ZERO(&writemask);
switch (flags) {
case EMPTH_FD_READ:
FD_SET(fd, &readmask);
break;
case EMPTH_FD_WRITE:
FD_SET(fd, &writemask);
break;
default:
logerror("bad flag %d passed to empth_select", flags);
empth_exit();
}
n = select(fd + 1, &readmask, &writemask, (fd_set *) 0, &tv);
if (n < 0) {
if (errno == EINTR) {
/* go handle the signal */
empth_status("select broken by signal");
goto done;
return;
}
/* strange but we dont get EINTR on select broken by signal */
empth_status("select failed (%s)", strerror(errno));
goto done;
return;
}
if (flags == EMPTH_FD_READ && FD_ISSET(fd, &readmask)) {
empth_status("input ready");
break;
}
if (flags == EMPTH_FD_WRITE && FD_ISSET(fd, &writemask)) {
empth_status("output ready");
break;
}
switch (flags) {
case EMPTH_FD_READ:
FD_SET(fd, &readmask);
break;
case EMPTH_FD_WRITE:
FD_SET(fd, &writemask);
break;
default:
CANT_REACH();
errno = EINVAL;
res = -1;
goto done;
}
done:
n = select(fd + 1, &readmask, &writemask, (fd_set *) 0, tv);
if (n < 0) {
if (errno == EINTR) /* go handle the signal */
empth_status("select broken by signal");
else
empth_status("select failed (%s)", strerror(errno));
res = -1;
} else if (n == 0) {
empth_status("select timed out");
res = 0;
} else if (flags == EMPTH_FD_READ && FD_ISSET(fd, &readmask)) {
empth_status("input ready");
res = 1;
} else if (flags == EMPTH_FD_WRITE && FD_ISSET(fd, &writemask)) {
empth_status("output ready");
res = 1;
}
done:
pthread_mutex_lock(&mtx_ctxsw);
empth_restorectx();
return res;
}
static void