summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/misc.c b/misc.c
index 1f320353e..1c43bc007 100644
--- a/misc.c
+++ b/misc.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: misc.c,v 1.23 2003/10/28 09:08:06 markus Exp $"); 26RCSID("$OpenBSD: misc.c,v 1.24 2004/06/14 01:44:39 djm Exp $");
27 27
28#include "misc.h" 28#include "misc.h"
29#include "log.h" 29#include "log.h"
@@ -46,7 +46,7 @@ chop(char *s)
46} 46}
47 47
48/* set/unset filedescriptor to non-blocking */ 48/* set/unset filedescriptor to non-blocking */
49void 49int
50set_nonblock(int fd) 50set_nonblock(int fd)
51{ 51{
52 int val; 52 int val;
@@ -54,20 +54,23 @@ set_nonblock(int fd)
54 val = fcntl(fd, F_GETFL, 0); 54 val = fcntl(fd, F_GETFL, 0);
55 if (val < 0) { 55 if (val < 0) {
56 error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno)); 56 error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
57 return; 57 return (-1);
58 } 58 }
59 if (val & O_NONBLOCK) { 59 if (val & O_NONBLOCK) {
60 debug2("fd %d is O_NONBLOCK", fd); 60 debug3("fd %d is O_NONBLOCK", fd);
61 return; 61 return (0);
62 } 62 }
63 debug2("fd %d setting O_NONBLOCK", fd); 63 debug2("fd %d setting O_NONBLOCK", fd);
64 val |= O_NONBLOCK; 64 val |= O_NONBLOCK;
65 if (fcntl(fd, F_SETFL, val) == -1) 65 if (fcntl(fd, F_SETFL, val) == -1) {
66 debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s", 66 debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s", fd,
67 fd, strerror(errno)); 67 strerror(errno));
68 return (-1);
69 }
70 return (0);
68} 71}
69 72
70void 73int
71unset_nonblock(int fd) 74unset_nonblock(int fd)
72{ 75{
73 int val; 76 int val;
@@ -75,17 +78,20 @@ unset_nonblock(int fd)
75 val = fcntl(fd, F_GETFL, 0); 78 val = fcntl(fd, F_GETFL, 0);
76 if (val < 0) { 79 if (val < 0) {
77 error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno)); 80 error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
78 return; 81 return (-1);
79 } 82 }
80 if (!(val & O_NONBLOCK)) { 83 if (!(val & O_NONBLOCK)) {
81 debug2("fd %d is not O_NONBLOCK", fd); 84 debug3("fd %d is not O_NONBLOCK", fd);
82 return; 85 return (0);
83 } 86 }
84 debug("fd %d clearing O_NONBLOCK", fd); 87 debug("fd %d clearing O_NONBLOCK", fd);
85 val &= ~O_NONBLOCK; 88 val &= ~O_NONBLOCK;
86 if (fcntl(fd, F_SETFL, val) == -1) 89 if (fcntl(fd, F_SETFL, val) == -1) {
87 debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s", 90 debug("fcntl(%d, F_SETFL, ~O_NONBLOCK): %s",
88 fd, strerror(errno)); 91 fd, strerror(errno));
92 return (-1);
93 }
94 return (0);
89} 95}
90 96
91/* disable nagle on socket */ 97/* disable nagle on socket */