Set blocking mode to fd returned by accept

That addresses issues in OpenBSD where the fd is
set to non blocking when the accept's fd is non blocking.
This commit is contained in:
Nikos Mavrogiannopoulos
2015-02-14 11:49:22 +01:00
parent ff5c721d30
commit 1b9fe50628
3 changed files with 13 additions and 0 deletions

View File

@@ -177,6 +177,14 @@ int val;
fcntl(fd, F_SETFL, val | O_NONBLOCK);
}
void set_block(int fd)
{
int val;
val = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, val & (~O_NONBLOCK));
}
ssize_t recv_timeout(int sockfd, void *buf, size_t len, unsigned sec)
{
int ret;

View File

@@ -36,6 +36,7 @@ void *_talloc_size2(void *ctx, size_t size);
#define DEFAULT_SOCKET_TIMEOUT 10
void set_non_block(int fd);
void set_block(int fd);
ssize_t force_write(int sockfd, const void *buf, size_t len);
ssize_t force_read(int sockfd, void *buf, size_t len);

View File

@@ -1111,6 +1111,10 @@ int main(int argc, char** argv)
continue;
}
set_cloexec_flag (fd, 1);
#ifndef __linux__
/* OpenBSD sets the non-blocking flag if accept's fd is non-blocking */
set_block(fd);
#endif
if (s->config->max_clients > 0 && s->active_clients >= s->config->max_clients) {
close(fd);