Added stubs for poll/select, improved selftest/echotest, Added ringbuffer for more efficient RX/TX

This commit is contained in:
Joseph Henry
2017-07-12 11:44:31 -07:00
parent 78d97f7826
commit 494ec2508c
12 changed files with 1547 additions and 829 deletions

View File

@@ -86,14 +86,14 @@
#endif
#if ZT_DEBUG_LEVEL >= ZT_MSG_TEST
#define DEBUG_TEST(fmt, args...) fprintf(stderr, ZT_CYN "ZT_TEST [%d] : %16s:%5d:%25s: " fmt \
#define DEBUG_TEST(fmt, args...) fprintf(stderr, ZT_CYN "TEST [%d] : %16s:%5d:%25s: " fmt \
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#else
#define DEBUG_ERROR(fmt, args...)
#endif
#if ZT_DEBUG_LEVEL >= ZT_MSG_ERROR
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, ZT_RED "ZT_ERROR[%d] : %16s:%5d:%25s: " fmt \
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, ZT_RED "ERROR[%d] : %16s:%5d:%25s: " fmt \
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#else
#define DEBUG_ERROR(fmt, args...)
@@ -102,22 +102,22 @@
#if ZT_DEBUG_LEVEL >= ZT_MSG_INFO
#if defined(__ANDROID__)
#define DEBUG_INFO(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"ZT_INFO : %16s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
"INFO : %16s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#define DEBUG_BLANK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"ZT_INFO : %16s:%5d:" fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
"INFO : %16s:%5d:" fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#define DEBUG_ATTN(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"ZT_INFO : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
"INFO : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#define DEBUG_STACK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"ZT_STACK: %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
"STACK: %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_INFO(fmt, args...) fprintf(stderr, \
"ZT_INFO [%d] : %16s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
"INFO [%d] : %16s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#define DEBUG_ATTN(fmt, args...) fprintf(stderr, ZT_CYN \
"ZT_ATTN [%d] : %16s:%5d:%25s: " fmt "\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
"ATTN [%d] : %16s:%5d:%25s: " fmt "\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#define DEBUG_STACK(fmt, args...) fprintf(stderr, ZT_YEL \
"ZT_STACK[%d] : %16s:%5d:%25s: " fmt "\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
"STACK[%d] : %16s:%5d:%25s: " fmt "\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#define DEBUG_BLANK(fmt, args...) fprintf(stderr, \
"ZT_INFO [%d] : %16s:%5d:" fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, ##args)
"INFO [%d] : %16s:%5d:" fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, ##args)
#endif
#else
#define DEBUG_INFO(fmt, args...)
@@ -129,9 +129,9 @@
#if ZT_DEBUG_LEVEL >= ZT_MSG_TRANSFER
#if defined(__ANDROID__)
#define DEBUG_TRANS(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"ZT_TRANS : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
"TRANS : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, ZT_GRN "ZT_TRANS[%ld] : %16s:%5d:%25s: " fmt \
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, ZT_GRN "TRANS[%ld] : %16s:%5d:%25s: " fmt \
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#endif
#else
@@ -141,10 +141,10 @@
#if ZT_DEBUG_LEVEL >= ZT_MSG_EXTRA
#if defined(__ANDROID__)
#define DEBUG_EXTRA(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"ZT_EXTRA : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
"EXTRA : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_EXTRA(fmt, args...) fprintf(stderr, \
"ZT_EXTRA[%d] : %16s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
"EXTRA[%d] : %16s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#endif
#else
#define DEBUG_EXTRA(fmt, args...)
@@ -153,9 +153,9 @@
#if ZT_DEBUG_LEVEL >= ZT_MSG_FLOW
#if defined(__ANDROID__)
#define DEBUG_FLOW(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"ZT_FLOW : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
"FLOW : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_FLOW(fmt, args...) fprintf(stderr, "ZT_FLOW [%ld] : %16s:%5d:%25s: " fmt "\n", \
#define DEBUG_FLOW(fmt, args...) fprintf(stderr, "FLOW [%ld] : %16s:%5d:%25s: " fmt "\n", \
ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#endif
#else

View File

@@ -37,7 +37,7 @@
#define ZT_PHY_POLL_INTERVAL 10 // ms
#define ZT_ACCEPT_RECHECK_DELAY 100 // ms (for blocking zts_accept() calls)
#define ZT_CONNECT_RECHECK_DELAY 100 // ms (for blocking zts_connect() calls)
#define ZT_API_CHECK_INTERVAL 500 // ms
#define ZT_API_CHECK_INTERVAL 100 // ms
#define MAX_PICO_FRAME_RX_BUF_SZ ZT_MAX_MTU * 128
@@ -46,7 +46,11 @@
#define ZT_UDP_TX_BUF_SZ ZT_MAX_MTU
#define ZT_UDP_RX_BUF_SZ ZT_MAX_MTU * 10
#define ZT_SDK_RPC_DIR_PREFIX "rpc.d"
#define ZT_STACK_TCP_SOCKET_TX_SZ 2048
#define ZT_STACK_TCP_SOCKET_RX_SZ 2048
#define ZT_STACK_SOCKET_RD_MAX 2048
#define ZT_STACK_SOCKET_WR_MAX 2048
#define ZT_CORE_VERSION_MAJOR 1
#define ZT_CORE_VERSION_MINOR 2
@@ -75,7 +79,7 @@
// a short period of time by default as a precaution.
#define ZT_SOCK_BEHAVIOR_LINGER true
#define ZT_SOCK_BEHAVIOR_LINGER_TIME 3 // s
#define ZT_SOCK_BEHAVIOR_LINGER_TIME 10000 // ms
// Wait time for socket closure if data is still present in the write queue
#define ZT_SDK_CLTIME 60
@@ -104,6 +108,7 @@
#define ZT_SEND_SIG int fd, const void *buf, size_t len, int flags
#define ZT_READ_SIG int fd, void *buf, size_t len
#define ZT_WRITE_SIG int fd, const void *buf, size_t len
#define ZT_SHUTDOWN_SIG int fd, int how
#define ZT_SOCKET_SIG int socket_family, int socket_type, int protocol
#define ZT_CONNECT_SIG int fd, const struct sockaddr *addr, socklen_t addrlen
#define ZT_BIND_SIG int fd, const struct sockaddr *addr, socklen_t addrlen
@@ -111,6 +116,8 @@
#define ZT_ACCEPT4_SIG int fd, struct sockaddr *addr, socklen_t *addrlen, int flags
#define ZT_ACCEPT_SIG int fd, struct sockaddr *addr, socklen_t *addrlen
#define ZT_CLOSE_SIG int fd
#define ZT_POLL_SIG struct pollfd *fds, nfds_t nfds, int timeout
#define ZT_SELECT_SIG int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout
#define ZT_GETSOCKNAME_SIG int fd, struct sockaddr *addr, socklen_t *addrlen
#define ZT_GETPEERNAME_SIG int fd, struct sockaddr *addr, socklen_t *addrlen
#define ZT_FCNTL_SIG int fd, int cmd, int flags
@@ -326,6 +333,16 @@ int zts_getpeername(ZT_GETPEERNAME_SIG);
*/
int zts_close(ZT_CLOSE_SIG);
/**
* waits for one of a set of file descriptors to become ready to perform I/O.
*/
int zts_poll(ZT_POLL_SIG);
/**
* monitor multiple file descriptors, waiting until one or more of the file descriptors become "ready"
*/
int zts_select(ZT_SELECT_SIG);
/**
* Issue file control commands on a socket
*/
@@ -367,6 +384,11 @@ int zts_read(ZT_READ_SIG);
*/
int zts_write(ZT_WRITE_SIG);
/*
* Sends a FIN segment
*/
int zts_shutdown(ZT_SHUTDOWN_SIG);
/****************************************************************************/
/* SDK Socket API Helper functions/objects --- DONT CALL THESE DIRECTLY */
/****************************************************************************/
@@ -377,6 +399,11 @@ namespace ZeroTier
extern ZeroTier::picoTCP *picostack;
}
/*
* Gets a pointer to a pico_socket given a file descriptor
*/
int zts_get_pico_socket(int fd, struct pico_socket *s);
/**
* Returns the number of sockets either already provisioned or waiting to be
* Some network stacks may have a limit on the number of sockets that they can
@@ -397,6 +424,11 @@ int pico_ntimers();
*/
void *zts_start_service(void *thread_id);
/*
*
*/
void handle_general_failure();
#include "Debug.hpp"
#ifdef __cplusplus