mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 00:37:00 +08:00
added set_non_block()
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <vpn.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -160,6 +161,14 @@ fd_set set;
|
||||
return len;
|
||||
}
|
||||
|
||||
void set_non_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;
|
||||
|
||||
@@ -33,6 +33,8 @@ void *_talloc_size2(void *ctx, size_t size);
|
||||
|
||||
#define DEFAULT_SOCKET_TIMEOUT 10
|
||||
|
||||
void set_non_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);
|
||||
ssize_t force_read_timeout(int sockfd, void *buf, size_t len, unsigned sec);
|
||||
|
||||
11
src/main.c
11
src/main.c
@@ -122,16 +122,7 @@ int y;
|
||||
|
||||
static void set_common_socket_options(int fd)
|
||||
{
|
||||
int val;
|
||||
|
||||
val = fcntl(fd, F_GETFL, 0);
|
||||
if ((val == -1)
|
||||
|| (fcntl(fd, F_SETFL, val | O_NONBLOCK) < 0)) {
|
||||
int e = errno;
|
||||
fprintf(stderr, "fcntl() error: %s", strerror(e));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
set_non_block(fd);
|
||||
set_cloexec_flag (fd, 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user