mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 08:46:58 +08:00
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:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user