diff options
author | zfl9 <zfl9.com@gmail.com> | 2020-03-04 21:49:42 +0800 |
---|---|---|
committer | zfl9 <zfl9.com@gmail.com> | 2020-03-04 21:49:42 +0800 |
commit | 7edb0065ca986803dbf3d12b79d86bfba446b10a (patch) | |
tree | ba0768f6d6f076abc88468c10e58257dedece30b | |
parent | use libev instead of libuv (diff) | |
download | dns2tcp-7edb0065ca986803dbf3d12b79d86bfba446b10a.tar.gz dns2tcp-7edb0065ca986803dbf3d12b79d86bfba446b10a.tar.bz2 dns2tcp-7edb0065ca986803dbf3d12b79d86bfba446b10a.zip |
use libev instead of libuv
-rw-r--r-- | dnsudp2tcp.c | 54 | ||||
-rwxr-xr-x | test | bin | 0 -> 75832 bytes |
2 files changed, 54 insertions, 0 deletions
diff --git a/dnsudp2tcp.c b/dnsudp2tcp.c index f76b9f9..b96ed30 100644 --- a/dnsudp2tcp.c +++ b/dnsudp2tcp.c @@ -94,6 +94,60 @@ static void udp_recv_cb(evloop_t *evloop, evio_t *watcher, int events); static void tcp_send_cb(evloop_t *evloop, evio_t *watcher, int events); static void tcp_recv_cb(evloop_t *evloop, evio_t *watcher, int events); +static void set_nonblock(int sockfd) { + int flags = fcntl(sockfd, F_GETFL, 0); + if (flags < 0) { + LOGERR("[set_nonblock] fcntl(%d, F_GETFL) failed: (%d) %s", sockfd, errno, strerror(errno)); + exit(errno); + } + if (fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) < 0) { + LOGERR("[set_nonblock] fcntl(%d, F_SETFL) failed: (%d) %s", sockfd, errno, strerror(errno)); + exit(errno); + } +} + +static void set_ipv6only(int sockfd) { + if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){1}, sizeof(int)) < 0) { + LOGERR("[set_ipv6only] setsockopt(%d, IPV6_V6ONLY) failed: (%d) %s", sockfd, errno, strerror(errno)); + exit(errno); + } +} + +static void set_reuseaddr(int sockfd) { + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) < 0) { + LOGERR("[set_reuseaddr] setsockopt(%d, SO_REUSEADDR) failed: (%d) %s", sockfd, errno, strerror(errno)); + exit(errno); + } +} + +static void set_reuseport(int sockfd) { + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &(int){1}, sizeof(int)) < 0) { + LOGERR("[set_reuseport] setsockopt(%d, SO_REUSEPORT) failed: (%d) %s", sockfd, errno, strerror(errno)); + exit(errno); + } +} + +static void set_nodelay(int sockfd) { + if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &(int){1}, sizeof(int)) < 0) { + LOGERR("[set_nodelay] setsockopt(%d, TCP_NODELAY) failed: (%d) %s", sockfd, errno, strerror(errno)); + exit(errno); + } +} + +static void set_quickack(int sockfd) { + if (setsockopt(sockfd, IPPROTO_TCP, TCP_QUICKACK, &(int){1}, sizeof(int)) < 0) { + LOGERR("[set_quickack] setsockopt(%d, TCP_QUICKACK) failed: (%d) %s", sockfd, errno, strerror(errno)); + exit(errno); + } +} + +static void set_syncnt(int sockfd, int syncnt) { + if (setsockopt(sockfd, IPPROTO_TCP, TCP_SYNCNT, &syncnt, sizeof(syncnt)) < 0) { + LOGERR("[set_syncnt] setsockopt(%d, TCP_SYNCNT) failed: (%d) %s", sockfd, errno, strerror(errno)); + exit(errno); + } +} + static int get_ipstr_family(const char *ipstr) { if (!ipstr) return -1; /* invalid */ uint8_t ipaddr[16]; /* 16-bytes */ Binary files differ |