diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2016-03-21 00:49:37 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2016-03-21 00:49:37 +0000 |
commit | 480dc4adde06fe54aa2665b9b4089af30a42820d (patch) | |
tree | c2567b64123939d7200344008a7006c9dabfd254 /games | |
parent | d4c8db29044b848271e1a2a3de2d895b0df21c40 (diff) |
Instead of creating a socket with socket() or accept() and then
setting the O_NONBLOCK flag on it with fcntl(F_SETFL) afterwards,
just pass SOCK_NONBLOCK to socket() or accept4() and get it right
to begin with.
ok millert@ krw@ beck@ deraadt@ jca@
Diffstat (limited to 'games')
-rw-r--r-- | games/hunt/huntd/answer.c | 19 | ||||
-rw-r--r-- | games/hunt/huntd/driver.c | 10 |
2 files changed, 11 insertions, 18 deletions
diff --git a/games/hunt/huntd/answer.c b/games/hunt/huntd/answer.c index 58d77408e32..16c6b7600f5 100644 --- a/games/hunt/huntd/answer.c +++ b/games/hunt/huntd/answer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: answer.c,v 1.18 2016/01/10 13:35:09 mestre Exp $ */ +/* $OpenBSD: answer.c,v 1.19 2016/03/21 00:49:36 guenther Exp $ */ /* $NetBSD: answer.c,v 1.3 1997/10/10 16:32:50 lukem Exp $ */ /* * Copyright (c) 1983-2003, Regents of the University of California. @@ -66,9 +66,14 @@ answer_first(void) int flags; struct spawn *sp; - /* Answer the call to hunt: */ + /* + * Answer the call to hunt, turning off blocking I/O, so a slow + * or dead terminal won't stop the game. All subsequent reads + * check how many bytes they read. + */ socklen = sizeof sockstruct; - newsock = accept(Socket, (struct sockaddr *) &sockstruct, &socklen); + newsock = accept4(Socket, (struct sockaddr *) &sockstruct, &socklen, + SOCK_NONBLOCK); if (newsock < 0) { logit(LOG_ERR, "accept"); return; @@ -92,14 +97,6 @@ answer_first(void) "struct sockaddr is not big enough! (%d > %zu)", socklen, sizeof Spawn->source); - /* - * Turn off blocking I/O, so a slow or dead terminal won't stop - * the game. All subsequent reads check how many bytes they read. - */ - flags = fcntl(newsock, F_GETFL, 0); - flags |= O_NDELAY; - (void) fcntl(newsock, F_SETFL, flags); - /* Start listening to the spawning connection */ sp->fd = newsock; FD_SET(sp->fd, &Fds_mask); diff --git a/games/hunt/huntd/driver.c b/games/hunt/huntd/driver.c index 159a163594f..e3c867fee1a 100644 --- a/games/hunt/huntd/driver.c +++ b/games/hunt/huntd/driver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: driver.c,v 1.26 2016/01/07 21:37:53 mestre Exp $ */ +/* $OpenBSD: driver.c,v 1.27 2016/03/21 00:49:36 guenther Exp $ */ /* $NetBSD: driver.c,v 1.5 1997/10/20 00:37:16 lukem Exp $ */ /* * Copyright (c) 1983-2003, Regents of the University of California. @@ -995,7 +995,8 @@ send_stats(void) /* Accept a connection to the statistics socket: */ socklen = sizeof sockstruct; - s = accept(Status, (struct sockaddr *) &sockstruct, &socklen); + s = accept4(Status, (struct sockaddr *) &sockstruct, &socklen, + SOCK_NONBLOCK); if (s < 0) { if (errno == EINTR) return; @@ -1003,11 +1004,6 @@ send_stats(void) return; } - /* Don't allow the writes to block: */ - flags = fcntl(s, F_GETFL, 0); - flags |= O_NDELAY; - (void) fcntl(s, F_SETFL, flags); - fp = fdopen(s, "w"); if (fp == NULL) { logit(LOG_ERR, "fdopen"); |