Try to set non-blocking mode when accepting new clients.
This commit is contained in:
parent
43f172d0ed
commit
05a6e1678e
24
master.c
24
master.c
|
|
@ -144,6 +144,28 @@ create_socket(char *name)
|
||||||
return s;
|
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
|
/* Process activity on the pty - Input and terminal changes are sent out to
|
||||||
** the attached clients. If the pty goes away, we die. */
|
** the attached clients. If the pty goes away, we die. */
|
||||||
static void
|
static void
|
||||||
|
|
@ -187,7 +209,7 @@ control_activity(int s)
|
||||||
|
|
||||||
/* Accept the new client and link it in. */
|
/* Accept the new client and link it in. */
|
||||||
fd = accept(s, NULL, NULL);
|
fd = accept(s, NULL, NULL);
|
||||||
if (fd < 0)
|
if (fd < 0 || setnonblocking(fd) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Link it in. */
|
/* Link it in. */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue