summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed T. Crigler <crigler@users.sourceforge.net>2004-10-04 20:19:08 +0000
committerNed T. Crigler <crigler@users.sourceforge.net>2004-10-04 20:19:08 +0000
commit05a6e1678ee2a39a3a962f0f693d1d43cabef60c (patch)
treef796fc76e41997a230cd3a47333e078168660343
parent43f172d0ed73b9964d8b8645a460644ab07bbce7 (diff)
Try to set non-blocking mode when accepting new clients.
-rw-r--r--master.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/master.c b/master.c
index 612ce2f..776812b 100644
--- a/master.c
+++ b/master.c
@@ -144,6 +144,28 @@ create_socket(char *name)
return s;
}
+/* Sets a file descriptor to non-blocking mode. */
+static int
+setnonblocking(int fd)
+{
+ int flags;
+
+#if defined(O_NONBLOCK)
+ flags = fcntl(fd, F_GETFL);
+ if (flags < 0 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0)
+ return -1;
+ return 0;
+#elif defined(FIONBIO)
+ flags = 1;
+ if (ioctl(fd, FIONBIO, &flags) < 0)
+ return -1;
+ return 0;
+#else
+#warning Do not know how to set non-blocking mode.
+ return 0;
+#endif
+}
+
/* Process activity on the pty - Input and terminal changes are sent out to
** the attached clients. If the pty goes away, we die. */
static void
@@ -187,7 +209,7 @@ control_activity(int s)
/* Accept the new client and link it in. */
fd = accept(s, NULL, NULL);
- if (fd < 0)
+ if (fd < 0 || setnonblocking(fd) < 0)
return;
/* Link it in. */