Slight re-org of C API naming convention
This commit is contained in:
548
src/Sockets.cpp
548
src/Sockets.cpp
@@ -32,7 +32,7 @@ namespace ZeroTier {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int zts_socket(const int socket_family, const int socket_type, const int protocol)
|
||||
int zts_bsd_socket(const int socket_family, const int socket_type, const int protocol)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -40,7 +40,7 @@ int zts_socket(const int socket_family, const int socket_type, const int protoco
|
||||
return lwip_socket(socket_family, socket_type, protocol);
|
||||
}
|
||||
|
||||
int zts_connect(int fd, const struct zts_sockaddr* addr, zts_socklen_t addrlen)
|
||||
int zts_bsd_connect(int fd, const struct zts_sockaddr* addr, zts_socklen_t addrlen)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -55,46 +55,7 @@ int zts_connect(int fd, const struct zts_sockaddr* addr, zts_socklen_t addrlen)
|
||||
return lwip_connect(fd, (sockaddr*)addr, addrlen);
|
||||
}
|
||||
|
||||
int zts_simple_connect(int fd, const char* ipstr, unsigned short port, int timeout_ms)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
if (timeout_ms < 0) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
if (timeout_ms == 0) {
|
||||
timeout_ms = 30000; // Default
|
||||
}
|
||||
int div = 4; // Must be > 0, Four connection attempts per second
|
||||
int n_tries = (timeout_ms / 1000) * div;
|
||||
int connect_delay = 1000 / div;
|
||||
int err = ZTS_ERR_SOCKET;
|
||||
|
||||
zts_socklen_t addrlen = 0;
|
||||
struct zts_sockaddr_storage ss;
|
||||
struct zts_sockaddr* sa = NULL;
|
||||
|
||||
// Convert to standard address structure
|
||||
|
||||
addrlen = sizeof(ss);
|
||||
zts_util_ipstr_to_saddr(ipstr, port, (struct zts_sockaddr*)&ss, &addrlen);
|
||||
sa = (struct zts_sockaddr*)&ss;
|
||||
|
||||
if (addrlen > 0 && sa != NULL) {
|
||||
if (zts_simple_get_blocking(fd)) {
|
||||
do {
|
||||
err = zts_connect(fd, sa, addrlen);
|
||||
zts_util_delay(connect_delay);
|
||||
n_tries--;
|
||||
} while ((err < 0) && (zts_errno != 0) && (n_tries > 0));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
|
||||
int zts_bind(int fd, const struct zts_sockaddr* addr, zts_socklen_t addrlen)
|
||||
int zts_bsd_bind(int fd, const struct zts_sockaddr* addr, zts_socklen_t addrlen)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -108,26 +69,7 @@ int zts_bind(int fd, const struct zts_sockaddr* addr, zts_socklen_t addrlen)
|
||||
return lwip_bind(fd, (sockaddr*)addr, addrlen);
|
||||
}
|
||||
|
||||
int zts_simple_bind(int fd, const char* ipstr, unsigned short port)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
zts_socklen_t addrlen = 0;
|
||||
struct zts_sockaddr_storage ss;
|
||||
struct zts_sockaddr* sa = NULL;
|
||||
|
||||
addrlen = sizeof(ss);
|
||||
int err = ZTS_ERR_OK;
|
||||
if ((err = zts_util_ipstr_to_saddr(ipstr, port, (struct zts_sockaddr*)&ss, &addrlen)) != ZTS_ERR_OK) {
|
||||
printf("ERRRRRRR=%d\n", err);
|
||||
return err;
|
||||
}
|
||||
sa = (struct zts_sockaddr*)&ss;
|
||||
return zts_bind(fd, sa, addrlen);
|
||||
}
|
||||
|
||||
int zts_listen(int fd, int backlog)
|
||||
int zts_bsd_listen(int fd, int backlog)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -135,7 +77,7 @@ int zts_listen(int fd, int backlog)
|
||||
return lwip_listen(fd, backlog);
|
||||
}
|
||||
|
||||
int zts_accept(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
int zts_bsd_accept(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -143,124 +85,7 @@ int zts_accept(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
return lwip_accept(fd, (sockaddr*)addr, (socklen_t*)addrlen);
|
||||
}
|
||||
|
||||
int zts_simple_accept(int fd, char* remote_addr, int len, unsigned short* port)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
if (len != ZTS_INET6_ADDRSTRLEN) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
zts_sockaddr_storage ss;
|
||||
zts_socklen_t addrlen = sizeof(ss);
|
||||
|
||||
int acc_fd = zts_accept(fd, (zts_sockaddr*)&ss, (zts_socklen_t*)&addrlen);
|
||||
int err = ZTS_ERR_OK;
|
||||
if ((err = zts_util_ntop((struct zts_sockaddr*)&ss, addrlen, remote_addr, len, port)) < ZTS_ERR_OK) {
|
||||
return err;
|
||||
}
|
||||
return acc_fd;
|
||||
}
|
||||
|
||||
int zts_simple_getpeername(int fd, char* remote_addr_str, int len, unsigned short* port)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
if (len != ZTS_INET6_ADDRSTRLEN) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
struct zts_sockaddr_storage ss;
|
||||
struct zts_sockaddr* sa = (struct zts_sockaddr*)&ss;
|
||||
int err = ZTS_ERR_OK;
|
||||
zts_socklen_t addrlen = sizeof(ss);
|
||||
if ((err = zts_getpeername(fd, sa, &addrlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return zts_util_ntop(sa, addrlen, remote_addr_str, len, port);
|
||||
}
|
||||
|
||||
int zts_simple_getsockname(int fd, char* local_addr_str, int len, unsigned short* port)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
if (len != ZTS_INET6_ADDRSTRLEN) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
struct zts_sockaddr_storage ss;
|
||||
struct zts_sockaddr* sa = (struct zts_sockaddr*)&ss;
|
||||
int err = ZTS_ERR_OK;
|
||||
zts_socklen_t addrlen = sizeof(ss);
|
||||
if ((err = zts_getsockname(fd, sa, &addrlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return zts_util_ntop(sa, addrlen, local_addr_str, len, port);
|
||||
}
|
||||
|
||||
int zts_simple_tcp_client(const char* remote_ipstr, unsigned short remote_port)
|
||||
{
|
||||
int fd, family = zts_util_get_ip_family(remote_ipstr);
|
||||
if ((fd = zts_socket(family, ZTS_SOCK_STREAM, 0)) < 0) {
|
||||
return fd; // Failed to create socket
|
||||
}
|
||||
int timeout = 0;
|
||||
if ((fd = zts_simple_connect(fd, remote_ipstr, remote_port, timeout)) < 0) {
|
||||
zts_close(fd);
|
||||
return fd; // Failed to connect
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int zts_simple_tcp_server(
|
||||
const char* local_ipstr,
|
||||
unsigned short local_port,
|
||||
char* remote_ipstr,
|
||||
int len,
|
||||
unsigned short* remote_port)
|
||||
{
|
||||
int listen_fd, family = zts_util_get_ip_family(local_ipstr);
|
||||
if ((listen_fd = zts_socket(family, ZTS_SOCK_STREAM, 0)) < 0) {
|
||||
return listen_fd; // Failed to create socket
|
||||
}
|
||||
if ((listen_fd = zts_simple_bind(listen_fd, local_ipstr, local_port)) < 0) {
|
||||
return listen_fd; // Failed to bind
|
||||
}
|
||||
int backlog = 0;
|
||||
if ((listen_fd = zts_listen(listen_fd, backlog)) < 0) {
|
||||
return listen_fd; // Failed to listen
|
||||
}
|
||||
int acc_fd = 0;
|
||||
if ((acc_fd = zts_simple_accept(listen_fd, remote_ipstr, len, remote_port)) < 0) {
|
||||
return acc_fd; // Failed to accept
|
||||
}
|
||||
zts_close(listen_fd);
|
||||
return acc_fd;
|
||||
}
|
||||
|
||||
int zts_simple_udp_server(const char* local_ipstr, unsigned short local_port)
|
||||
{
|
||||
int fd, family = zts_util_get_ip_family(local_ipstr);
|
||||
if ((fd = zts_socket(family, ZTS_SOCK_DGRAM, 0)) < 0) {
|
||||
return fd; // Failed to create socket
|
||||
}
|
||||
if ((fd = zts_simple_bind(fd, local_ipstr, local_port)) < 0) {
|
||||
zts_close(fd);
|
||||
return fd; // Failed to connect
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int zts_simple_udp_client(const char* remote_ipstr)
|
||||
{
|
||||
int fd, family = zts_util_get_ip_family(remote_ipstr);
|
||||
if ((fd = zts_socket(family, ZTS_SOCK_DGRAM, 0)) < 0) {
|
||||
return fd; // Failed to create socket
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int zts_setsockopt(int fd, int level, int optname, const void* optval, zts_socklen_t optlen)
|
||||
int zts_bsd_setsockopt(int fd, int level, int optname, const void* optval, zts_socklen_t optlen)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -268,7 +93,7 @@ int zts_setsockopt(int fd, int level, int optname, const void* optval, zts_sockl
|
||||
return lwip_setsockopt(fd, level, optname, optval, optlen);
|
||||
}
|
||||
|
||||
int zts_getsockopt(int fd, int level, int optname, void* optval, zts_socklen_t* optlen)
|
||||
int zts_bsd_getsockopt(int fd, int level, int optname, void* optval, zts_socklen_t* optlen)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -276,7 +101,7 @@ int zts_getsockopt(int fd, int level, int optname, void* optval, zts_socklen_t*
|
||||
return lwip_getsockopt(fd, level, optname, optval, (socklen_t*)optlen);
|
||||
}
|
||||
|
||||
int zts_getsockname(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
int zts_bsd_getsockname(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -290,7 +115,7 @@ int zts_getsockname(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
return lwip_getsockname(fd, (sockaddr*)addr, (socklen_t*)addrlen);
|
||||
}
|
||||
|
||||
int zts_getpeername(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
int zts_bsd_getpeername(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -304,7 +129,7 @@ int zts_getpeername(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
return lwip_getpeername(fd, (sockaddr*)addr, (socklen_t*)addrlen);
|
||||
}
|
||||
|
||||
int zts_close(int fd)
|
||||
int zts_bsd_close(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -312,7 +137,12 @@ int zts_close(int fd)
|
||||
return lwip_close(fd);
|
||||
}
|
||||
|
||||
int zts_select(int nfds, zts_fd_set* readfds, zts_fd_set* writefds, zts_fd_set* exceptfds, struct zts_timeval* timeout)
|
||||
int zts_bsd_select(
|
||||
int nfds,
|
||||
zts_fd_set* readfds,
|
||||
zts_fd_set* writefds,
|
||||
zts_fd_set* exceptfds,
|
||||
struct zts_timeval* timeout)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -320,7 +150,7 @@ int zts_select(int nfds, zts_fd_set* readfds, zts_fd_set* writefds, zts_fd_set*
|
||||
return lwip_select(nfds, (fd_set*)readfds, (fd_set*)writefds, (fd_set*)exceptfds, (timeval*)timeout);
|
||||
}
|
||||
|
||||
int zts_fcntl(int fd, int cmd, int flags)
|
||||
int zts_bsd_fcntl(int fd, int cmd, int flags)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -328,7 +158,7 @@ int zts_fcntl(int fd, int cmd, int flags)
|
||||
return lwip_fcntl(fd, cmd, flags);
|
||||
}
|
||||
|
||||
int zts_poll(struct zts_pollfd* fds, nfds_t nfds, int timeout)
|
||||
int zts_bsd_poll(struct zts_pollfd* fds, nfds_t nfds, int timeout)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -336,7 +166,7 @@ int zts_poll(struct zts_pollfd* fds, nfds_t nfds, int timeout)
|
||||
return lwip_poll((pollfd*)fds, nfds, timeout);
|
||||
}
|
||||
|
||||
int zts_ioctl(int fd, unsigned long request, void* argp)
|
||||
int zts_bsd_ioctl(int fd, unsigned long request, void* argp)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -347,7 +177,7 @@ int zts_ioctl(int fd, unsigned long request, void* argp)
|
||||
return lwip_ioctl(fd, request, argp);
|
||||
}
|
||||
|
||||
ssize_t zts_send(int fd, const void* buf, size_t len, int flags)
|
||||
ssize_t zts_bsd_send(int fd, const void* buf, size_t len, int flags)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -359,7 +189,7 @@ ssize_t zts_send(int fd, const void* buf, size_t len, int flags)
|
||||
}
|
||||
|
||||
ssize_t
|
||||
zts_sendto(int fd, const void* buf, size_t len, int flags, const struct zts_sockaddr* addr, zts_socklen_t addrlen)
|
||||
zts_bsd_sendto(int fd, const void* buf, size_t len, int flags, const struct zts_sockaddr* addr, zts_socklen_t addrlen)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -373,7 +203,7 @@ zts_sendto(int fd, const void* buf, size_t len, int flags, const struct zts_sock
|
||||
return lwip_sendto(fd, buf, len, flags, (sockaddr*)addr, addrlen);
|
||||
}
|
||||
|
||||
ssize_t zts_sendmsg(int fd, const struct zts_msghdr* msg, int flags)
|
||||
ssize_t zts_bsd_sendmsg(int fd, const struct zts_msghdr* msg, int flags)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -381,7 +211,7 @@ ssize_t zts_sendmsg(int fd, const struct zts_msghdr* msg, int flags)
|
||||
return lwip_sendmsg(fd, (const struct msghdr*)msg, flags);
|
||||
}
|
||||
|
||||
ssize_t zts_recv(int fd, void* buf, size_t len, int flags)
|
||||
ssize_t zts_bsd_recv(int fd, void* buf, size_t len, int flags)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -392,7 +222,7 @@ ssize_t zts_recv(int fd, void* buf, size_t len, int flags)
|
||||
return lwip_recv(fd, buf, len, flags);
|
||||
}
|
||||
|
||||
ssize_t zts_recvfrom(int fd, void* buf, size_t len, int flags, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
ssize_t zts_bsd_recvfrom(int fd, void* buf, size_t len, int flags, struct zts_sockaddr* addr, zts_socklen_t* addrlen)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -403,7 +233,7 @@ ssize_t zts_recvfrom(int fd, void* buf, size_t len, int flags, struct zts_sockad
|
||||
return lwip_recvfrom(fd, buf, len, flags, (sockaddr*)addr, (socklen_t*)addrlen);
|
||||
}
|
||||
|
||||
ssize_t zts_recvmsg(int fd, struct zts_msghdr* msg, int flags)
|
||||
ssize_t zts_bsd_recvmsg(int fd, struct zts_msghdr* msg, int flags)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -414,7 +244,7 @@ ssize_t zts_recvmsg(int fd, struct zts_msghdr* msg, int flags)
|
||||
return lwip_recvmsg(fd, (struct msghdr*)msg, flags);
|
||||
}
|
||||
|
||||
ssize_t zts_read(int fd, void* buf, size_t len)
|
||||
ssize_t zts_bsd_read(int fd, void* buf, size_t len)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -425,7 +255,7 @@ ssize_t zts_read(int fd, void* buf, size_t len)
|
||||
return lwip_read(fd, buf, len);
|
||||
}
|
||||
|
||||
ssize_t zts_readv(int fd, const struct zts_iovec* iov, int iovcnt)
|
||||
ssize_t zts_bsd_readv(int fd, const struct zts_iovec* iov, int iovcnt)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -433,7 +263,7 @@ ssize_t zts_readv(int fd, const struct zts_iovec* iov, int iovcnt)
|
||||
return lwip_readv(fd, (iovec*)iov, iovcnt);
|
||||
}
|
||||
|
||||
ssize_t zts_write(int fd, const void* buf, size_t len)
|
||||
ssize_t zts_bsd_write(int fd, const void* buf, size_t len)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -444,7 +274,7 @@ ssize_t zts_write(int fd, const void* buf, size_t len)
|
||||
return lwip_write(fd, buf, len);
|
||||
}
|
||||
|
||||
ssize_t zts_writev(int fd, const struct zts_iovec* iov, int iovcnt)
|
||||
ssize_t zts_bsd_writev(int fd, const struct zts_iovec* iov, int iovcnt)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -452,7 +282,7 @@ ssize_t zts_writev(int fd, const struct zts_iovec* iov, int iovcnt)
|
||||
return lwip_writev(fd, (iovec*)iov, iovcnt);
|
||||
}
|
||||
|
||||
int zts_shutdown(int fd, int how)
|
||||
int zts_bsd_shutdown(int fd, int how)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -460,7 +290,7 @@ int zts_shutdown(int fd, int how)
|
||||
return lwip_shutdown(fd, how);
|
||||
}
|
||||
|
||||
struct zts_hostent* zts_gethostbyname(const char* name)
|
||||
struct zts_hostent* zts_bsd_gethostbyname(const char* name)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return NULL;
|
||||
@@ -554,7 +384,231 @@ int zts_util_ipstr_to_saddr(
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
|
||||
int zts_simple_set_no_delay(int fd, int enabled)
|
||||
int zts_socket(int family, int type, int protocol)
|
||||
{
|
||||
return zts_bsd_socket(family, type, protocol);
|
||||
}
|
||||
|
||||
int zts_connect(int fd, const char* ipstr, unsigned short port, int timeout_ms)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
if (timeout_ms < 0) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
if (timeout_ms == 0) {
|
||||
timeout_ms = 30000; // Default
|
||||
}
|
||||
int div = 4; // Must be > 0, Four connection attempts per second
|
||||
int n_tries = (timeout_ms / 1000) * div;
|
||||
int connect_delay = 1000 / div;
|
||||
int err = ZTS_ERR_SOCKET;
|
||||
|
||||
zts_socklen_t addrlen = 0;
|
||||
struct zts_sockaddr_storage ss;
|
||||
struct zts_sockaddr* sa = NULL;
|
||||
|
||||
// Convert to standard address structure
|
||||
|
||||
addrlen = sizeof(ss);
|
||||
zts_util_ipstr_to_saddr(ipstr, port, (struct zts_sockaddr*)&ss, &addrlen);
|
||||
sa = (struct zts_sockaddr*)&ss;
|
||||
|
||||
if (addrlen > 0 && sa != NULL) {
|
||||
if (zts_get_blocking(fd)) {
|
||||
do {
|
||||
err = zts_bsd_connect(fd, sa, addrlen);
|
||||
zts_util_delay(connect_delay);
|
||||
n_tries--;
|
||||
} while ((err < 0) && (zts_errno != 0) && (n_tries > 0));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
|
||||
int zts_bind(int fd, const char* ipstr, unsigned short port)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
zts_socklen_t addrlen = 0;
|
||||
struct zts_sockaddr_storage ss;
|
||||
struct zts_sockaddr* sa = NULL;
|
||||
|
||||
addrlen = sizeof(ss);
|
||||
int err = ZTS_ERR_OK;
|
||||
if ((err = zts_util_ipstr_to_saddr(ipstr, port, (struct zts_sockaddr*)&ss, &addrlen)) != ZTS_ERR_OK) {
|
||||
return err;
|
||||
}
|
||||
sa = (struct zts_sockaddr*)&ss;
|
||||
return zts_bsd_bind(fd, sa, addrlen);
|
||||
}
|
||||
|
||||
int zts_listen(int fd, int backlog)
|
||||
{
|
||||
return zts_bsd_listen(fd, backlog);
|
||||
}
|
||||
|
||||
int zts_accept(int fd, char* remote_addr, int len, unsigned short* port)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
if (len != ZTS_INET6_ADDRSTRLEN) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
zts_sockaddr_storage ss;
|
||||
zts_socklen_t addrlen = sizeof(ss);
|
||||
|
||||
int acc_fd = zts_bsd_accept(fd, (zts_sockaddr*)&ss, (zts_socklen_t*)&addrlen);
|
||||
int err = ZTS_ERR_OK;
|
||||
if ((err = zts_util_ntop((struct zts_sockaddr*)&ss, addrlen, remote_addr, len, port)) < ZTS_ERR_OK) {
|
||||
return err;
|
||||
}
|
||||
return acc_fd;
|
||||
}
|
||||
|
||||
ssize_t zts_send(int fd, const void* buf, size_t len, int flags)
|
||||
{
|
||||
return zts_bsd_send(fd, buf, len, flags);
|
||||
}
|
||||
|
||||
ssize_t zts_recv(int fd, void* buf, size_t len, int flags)
|
||||
{
|
||||
return zts_bsd_recv(fd, buf, len, flags);
|
||||
}
|
||||
|
||||
ssize_t zts_read(int fd, void* buf, size_t len)
|
||||
{
|
||||
return zts_bsd_read(fd, buf, len);
|
||||
}
|
||||
|
||||
ssize_t zts_write(int fd, const void* buf, size_t len)
|
||||
{
|
||||
return zts_bsd_write(fd, buf, len);
|
||||
}
|
||||
|
||||
int zts_shutdown_rd(int fd)
|
||||
{
|
||||
return zts_bsd_shutdown(fd, ZTS_SHUT_RD);
|
||||
}
|
||||
|
||||
int zts_shutdown_wr(int fd)
|
||||
{
|
||||
return zts_bsd_shutdown(fd, ZTS_SHUT_WR);
|
||||
}
|
||||
|
||||
int zts_shutdown_rdwr(int fd)
|
||||
{
|
||||
return zts_bsd_shutdown(fd, ZTS_SHUT_RDWR);
|
||||
}
|
||||
|
||||
int zts_close(int fd)
|
||||
{
|
||||
return zts_bsd_close(fd);
|
||||
}
|
||||
|
||||
int zts_getpeername(int fd, char* remote_addr_str, int len, unsigned short* port)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
if (len != ZTS_INET6_ADDRSTRLEN) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
struct zts_sockaddr_storage ss;
|
||||
struct zts_sockaddr* sa = (struct zts_sockaddr*)&ss;
|
||||
int err = ZTS_ERR_OK;
|
||||
zts_socklen_t addrlen = sizeof(ss);
|
||||
if ((err = zts_bsd_getpeername(fd, sa, &addrlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return zts_util_ntop(sa, addrlen, remote_addr_str, len, port);
|
||||
}
|
||||
|
||||
int zts_getsockname(int fd, char* local_addr_str, int len, unsigned short* port)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
if (len != ZTS_INET6_ADDRSTRLEN) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
struct zts_sockaddr_storage ss;
|
||||
struct zts_sockaddr* sa = (struct zts_sockaddr*)&ss;
|
||||
int err = ZTS_ERR_OK;
|
||||
zts_socklen_t addrlen = sizeof(ss);
|
||||
if ((err = zts_bsd_getsockname(fd, sa, &addrlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return zts_util_ntop(sa, addrlen, local_addr_str, len, port);
|
||||
}
|
||||
|
||||
int zts_tcp_client(const char* remote_ipstr, unsigned short remote_port)
|
||||
{
|
||||
int fd, family = zts_util_get_ip_family(remote_ipstr);
|
||||
if ((fd = zts_bsd_socket(family, ZTS_SOCK_STREAM, 0)) < 0) {
|
||||
return fd; // Failed to create socket
|
||||
}
|
||||
int timeout = 0;
|
||||
if ((fd = zts_connect(fd, remote_ipstr, remote_port, timeout)) < 0) {
|
||||
zts_bsd_close(fd);
|
||||
return fd; // Failed to connect
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int zts_tcp_server(
|
||||
const char* local_ipstr,
|
||||
unsigned short local_port,
|
||||
char* remote_ipstr,
|
||||
int len,
|
||||
unsigned short* remote_port)
|
||||
{
|
||||
int listen_fd, family = zts_util_get_ip_family(local_ipstr);
|
||||
if ((listen_fd = zts_bsd_socket(family, ZTS_SOCK_STREAM, 0)) < 0) {
|
||||
return listen_fd; // Failed to create socket
|
||||
}
|
||||
if ((listen_fd = zts_bind(listen_fd, local_ipstr, local_port)) < 0) {
|
||||
return listen_fd; // Failed to bind
|
||||
}
|
||||
int backlog = 0;
|
||||
if ((listen_fd = zts_bsd_listen(listen_fd, backlog)) < 0) {
|
||||
return listen_fd; // Failed to listen
|
||||
}
|
||||
int acc_fd = 0;
|
||||
if ((acc_fd = zts_accept(listen_fd, remote_ipstr, len, remote_port)) < 0) {
|
||||
return acc_fd; // Failed to accept
|
||||
}
|
||||
zts_bsd_close(listen_fd);
|
||||
return acc_fd;
|
||||
}
|
||||
|
||||
int zts_udp_server(const char* local_ipstr, unsigned short local_port)
|
||||
{
|
||||
int fd, family = zts_util_get_ip_family(local_ipstr);
|
||||
if ((fd = zts_bsd_socket(family, ZTS_SOCK_DGRAM, 0)) < 0) {
|
||||
return fd; // Failed to create socket
|
||||
}
|
||||
if ((fd = zts_bind(fd, local_ipstr, local_port)) < 0) {
|
||||
zts_bsd_close(fd);
|
||||
return fd; // Failed to connect
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int zts_udp_client(const char* remote_ipstr)
|
||||
{
|
||||
int fd, family = zts_util_get_ip_family(remote_ipstr);
|
||||
if ((fd = zts_bsd_socket(family, ZTS_SOCK_DGRAM, 0)) < 0) {
|
||||
return fd; // Failed to create socket
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int zts_set_no_delay(int fd, int enabled)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -562,23 +616,23 @@ int zts_simple_set_no_delay(int fd, int enabled)
|
||||
if (enabled != 0 && enabled != 1) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
return zts_setsockopt(fd, ZTS_IPPROTO_TCP, ZTS_TCP_NODELAY, (void*)&enabled, sizeof(int));
|
||||
return zts_bsd_setsockopt(fd, ZTS_IPPROTO_TCP, ZTS_TCP_NODELAY, (void*)&enabled, sizeof(int));
|
||||
}
|
||||
|
||||
int zts_simple_get_no_delay(int fd)
|
||||
int zts_get_no_delay(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
int err, optval = 0;
|
||||
zts_socklen_t len = sizeof(optval);
|
||||
if ((err = zts_getsockopt(fd, ZTS_IPPROTO_TCP, ZTS_TCP_NODELAY, (void*)&optval, &len)) < 0) {
|
||||
if ((err = zts_bsd_getsockopt(fd, ZTS_IPPROTO_TCP, ZTS_TCP_NODELAY, (void*)&optval, &len)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return optval != 0;
|
||||
}
|
||||
|
||||
int zts_simple_set_linger(int fd, int enabled, int value)
|
||||
int zts_set_linger(int fd, int enabled, int value)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -592,10 +646,10 @@ int zts_simple_set_linger(int fd, int enabled, int value)
|
||||
struct zts_linger linger;
|
||||
linger.l_onoff = enabled;
|
||||
linger.l_linger = value;
|
||||
return zts_setsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_LINGER, (void*)&linger, sizeof(linger));
|
||||
return zts_bsd_setsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_LINGER, (void*)&linger, sizeof(linger));
|
||||
}
|
||||
|
||||
int zts_simple_get_linger_enabled(int fd)
|
||||
int zts_get_linger_enabled(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -603,13 +657,13 @@ int zts_simple_get_linger_enabled(int fd)
|
||||
struct zts_linger linger;
|
||||
zts_socklen_t len = sizeof(linger);
|
||||
int err;
|
||||
if ((err = zts_getsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_LINGER, (void*)&linger, &len)) < 0) {
|
||||
if ((err = zts_bsd_getsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_LINGER, (void*)&linger, &len)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return linger.l_onoff;
|
||||
}
|
||||
|
||||
int zts_simple_get_linger_value(int fd)
|
||||
int zts_get_linger_value(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -617,26 +671,26 @@ int zts_simple_get_linger_value(int fd)
|
||||
struct zts_linger linger;
|
||||
zts_socklen_t len = sizeof(linger);
|
||||
int err;
|
||||
if ((err = zts_getsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_LINGER, (void*)&linger, &len)) < 0) {
|
||||
if ((err = zts_bsd_getsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_LINGER, (void*)&linger, &len)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return linger.l_linger;
|
||||
}
|
||||
|
||||
int zts_simple_get_pending_data_size(int fd)
|
||||
int zts_get_pending_data_size(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
int bytes_available = 0;
|
||||
int err = ZTS_ERR_OK;
|
||||
if ((err = zts_ioctl(fd, ZTS_FIONREAD, &bytes_available)) < 0) {
|
||||
if ((err = zts_bsd_ioctl(fd, ZTS_FIONREAD, &bytes_available)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return bytes_available;
|
||||
}
|
||||
|
||||
int zts_simple_set_reuse_addr(int fd, int enabled)
|
||||
int zts_set_reuse_addr(int fd, int enabled)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -644,23 +698,23 @@ int zts_simple_set_reuse_addr(int fd, int enabled)
|
||||
if (enabled != 0 && enabled != 1) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
return zts_setsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_REUSEADDR, (void*)&enabled, sizeof(enabled));
|
||||
return zts_bsd_setsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_REUSEADDR, (void*)&enabled, sizeof(enabled));
|
||||
}
|
||||
|
||||
int zts_simple_get_reuse_addr(int fd)
|
||||
int zts_get_reuse_addr(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
int err, optval = 0;
|
||||
zts_socklen_t optlen = sizeof(optval);
|
||||
if ((err = zts_getsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_REUSEADDR, (void*)&optval, &optlen)) < 0) {
|
||||
if ((err = zts_bsd_getsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_REUSEADDR, (void*)&optval, &optlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return optval != 0;
|
||||
}
|
||||
|
||||
int zts_simple_set_recv_timeout(int fd, int seconds, int microseconds)
|
||||
int zts_set_recv_timeout(int fd, int seconds, int microseconds)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -671,10 +725,10 @@ int zts_simple_set_recv_timeout(int fd, int seconds, int microseconds)
|
||||
struct timeval tv;
|
||||
tv.tv_sec = seconds;
|
||||
tv.tv_usec = microseconds;
|
||||
return zts_setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void*)&tv, sizeof(tv));
|
||||
return zts_bsd_setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void*)&tv, sizeof(tv));
|
||||
}
|
||||
|
||||
int zts_simple_get_recv_timeout(int fd)
|
||||
int zts_get_recv_timeout(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -682,13 +736,13 @@ int zts_simple_get_recv_timeout(int fd)
|
||||
struct timeval tv;
|
||||
zts_socklen_t optlen = sizeof(tv);
|
||||
int err;
|
||||
if ((err = zts_getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void*)&tv, &optlen)) < 0) {
|
||||
if ((err = zts_bsd_getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void*)&tv, &optlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return tv.tv_sec; // TODO microseconds
|
||||
}
|
||||
|
||||
int zts_simple_set_send_timeout(int fd, int seconds, int microseconds)
|
||||
int zts_set_send_timeout(int fd, int seconds, int microseconds)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -699,10 +753,10 @@ int zts_simple_set_send_timeout(int fd, int seconds, int microseconds)
|
||||
struct timeval tv;
|
||||
tv.tv_sec = seconds;
|
||||
tv.tv_usec = microseconds;
|
||||
return zts_setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (void*)&tv, sizeof(tv));
|
||||
return zts_bsd_setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (void*)&tv, sizeof(tv));
|
||||
}
|
||||
|
||||
int zts_simple_get_send_timeout(int fd)
|
||||
int zts_get_send_timeout(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -710,13 +764,13 @@ int zts_simple_get_send_timeout(int fd)
|
||||
struct zts_timeval tv;
|
||||
zts_socklen_t optlen = sizeof(tv);
|
||||
int err;
|
||||
if ((err = zts_getsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (void*)&tv, &optlen)) < 0) {
|
||||
if ((err = zts_bsd_getsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (void*)&tv, &optlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return tv.tv_sec; // TODO microseconds
|
||||
}
|
||||
|
||||
int zts_simple_set_send_buf_size(int fd, int size)
|
||||
int zts_set_send_buf_size(int fd, int size)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -724,23 +778,23 @@ int zts_simple_set_send_buf_size(int fd, int size)
|
||||
if (size < 0) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
return zts_setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&size, sizeof(int));
|
||||
return zts_bsd_setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&size, sizeof(int));
|
||||
}
|
||||
|
||||
int zts_simple_get_send_buf_size(int fd)
|
||||
int zts_get_send_buf_size(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
int err, optval = 0;
|
||||
zts_socklen_t optlen = sizeof(optval);
|
||||
if ((err = zts_getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char*)&optval, &optlen)) < 0) {
|
||||
if ((err = zts_bsd_getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char*)&optval, &optlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return optval;
|
||||
}
|
||||
|
||||
int zts_simple_set_recv_buf_size(int fd, int size)
|
||||
int zts_set_recv_buf_size(int fd, int size)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -748,23 +802,23 @@ int zts_simple_set_recv_buf_size(int fd, int size)
|
||||
if (size < 0) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
return zts_setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void*)&size, sizeof(int));
|
||||
return zts_bsd_setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void*)&size, sizeof(int));
|
||||
}
|
||||
|
||||
int zts_simple_get_recv_buf_size(int fd)
|
||||
int zts_get_recv_buf_size(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
int err, optval = 0;
|
||||
zts_socklen_t optlen = sizeof(optval);
|
||||
if ((err = zts_getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char*)&optval, &optlen)) < 0) {
|
||||
if ((err = zts_bsd_getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char*)&optval, &optlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return optval;
|
||||
}
|
||||
|
||||
int zts_simple_set_ttl(int fd, int ttl)
|
||||
int zts_set_ttl(int fd, int ttl)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -772,23 +826,23 @@ int zts_simple_set_ttl(int fd, int ttl)
|
||||
if (ttl < 0 || ttl > 255) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
return zts_setsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
|
||||
return zts_bsd_setsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
|
||||
}
|
||||
|
||||
int zts_simple_get_ttl(int fd)
|
||||
int zts_get_ttl(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
int err, ttl = 0;
|
||||
zts_socklen_t optlen = sizeof(ttl);
|
||||
if ((err = zts_getsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, &optlen)) < 0) {
|
||||
if ((err = zts_bsd_getsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, &optlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return ttl;
|
||||
}
|
||||
|
||||
int zts_simple_set_blocking(int fd, int enabled)
|
||||
int zts_set_blocking(int fd, int enabled)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -796,29 +850,29 @@ int zts_simple_set_blocking(int fd, int enabled)
|
||||
if (enabled != 0 && enabled != 1) {
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
int flags = zts_fcntl(fd, ZTS_F_GETFL, 0);
|
||||
int flags = zts_bsd_fcntl(fd, ZTS_F_GETFL, 0);
|
||||
if (! enabled) {
|
||||
return zts_fcntl(fd, ZTS_F_SETFL, flags | ZTS_O_NONBLOCK);
|
||||
return zts_bsd_fcntl(fd, ZTS_F_SETFL, flags | ZTS_O_NONBLOCK);
|
||||
}
|
||||
else {
|
||||
// Default
|
||||
return zts_fcntl(fd, ZTS_F_SETFL, flags & (~ZTS_O_NONBLOCK));
|
||||
return zts_bsd_fcntl(fd, ZTS_F_SETFL, flags & (~ZTS_O_NONBLOCK));
|
||||
}
|
||||
}
|
||||
|
||||
int zts_simple_get_blocking(int fd)
|
||||
int zts_get_blocking(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
int flags = zts_fcntl(fd, ZTS_F_GETFL, 0);
|
||||
int flags = zts_bsd_fcntl(fd, ZTS_F_GETFL, 0);
|
||||
if (flags < 0) {
|
||||
return flags;
|
||||
}
|
||||
return ! (flags & ZTS_O_NONBLOCK);
|
||||
}
|
||||
|
||||
int zts_simple_set_keepalive(int fd, int enabled)
|
||||
int zts_set_keepalive(int fd, int enabled)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
@@ -827,17 +881,17 @@ int zts_simple_set_keepalive(int fd, int enabled)
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
int keepalive = enabled;
|
||||
return zts_setsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_KEEPALIVE, &keepalive, sizeof(keepalive));
|
||||
return zts_bsd_setsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_KEEPALIVE, &keepalive, sizeof(keepalive));
|
||||
}
|
||||
|
||||
int zts_simple_get_keepalive(int fd)
|
||||
int zts_get_keepalive(int fd)
|
||||
{
|
||||
if (! transport_ok()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
int err, optval = 0;
|
||||
zts_socklen_t optlen = sizeof(optval);
|
||||
if ((err = zts_getsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_KEEPALIVE, (void*)&optval, &optlen)) < 0) {
|
||||
if ((err = zts_bsd_getsockopt(fd, ZTS_SOL_SOCKET, ZTS_SO_KEEPALIVE, (void*)&optval, &optlen)) < 0) {
|
||||
return err;
|
||||
}
|
||||
return optval != 0;
|
||||
|
||||
Reference in New Issue
Block a user