diff options
| author | Joseph Henry <[email protected]> | 2017-07-25 23:40:24 -0700 |
|---|---|---|
| committer | Joseph Henry <[email protected]> | 2017-07-25 23:40:24 -0700 |
| commit | 4e36fe28d5224d8656da077e37aad44268bd807f (patch) | |
| tree | bc2db5a747de244c96ecbfc41d9f92d73c6f378c /src/picoTCP.cpp | |
| parent | bb60904899067c0d9bdb0a454a89d51c1bc711f8 (diff) | |
BSD-license-compatible, and NO_STACK build variants
Diffstat (limited to 'src/picoTCP.cpp')
| -rw-r--r-- | src/picoTCP.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/picoTCP.cpp b/src/picoTCP.cpp index eeb3e99..26aae22 100644 --- a/src/picoTCP.cpp +++ b/src/picoTCP.cpp @@ -502,6 +502,58 @@ namespace ZeroTier { } return loop_score; } + + int picoTCP::pico_Socket(struct pico_socket **p, int socket_family, int socket_type, int protocol) + { + int err = 0; + if(pico_ntimers() >= PICO_MAX_TIMERS) { + DEBUG_ERROR("cannot create additional socket, see PICO_MAX_TIMERS. current = %d", pico_ntimers()); + errno = EMFILE; + err = -1; + } + else + { + int protocol_version = 0; + struct pico_socket *psock; + if(socket_family == AF_INET) + protocol_version = PICO_PROTO_IPV4; + if(socket_family == AF_INET6) + protocol_version = PICO_PROTO_IPV6; + + if(socket_type == SOCK_DGRAM) { + DEBUG_ERROR("SOCK_DGRAM"); + psock = pico_socket_open( + protocol_version, PICO_PROTO_UDP, &ZeroTier::picoTCP::pico_cb_socket_activity); + if(psock) { // configure size of UDP SND/RCV buffers + // TODO + } + } + if(socket_type == SOCK_STREAM) { + psock = pico_socket_open( + protocol_version, PICO_PROTO_TCP, &ZeroTier::picoTCP::pico_cb_socket_activity); + if(psock) { // configure size of TCP SND/RCV buffers + int tx_buf_sz = ZT_STACK_TCP_SOCKET_TX_SZ; + int rx_buf_sz = ZT_STACK_TCP_SOCKET_RX_SZ; + int t_err = 0; + int value = 1; + pico_socket_setoption(psock, PICO_TCP_NODELAY, &value); + + if((t_err = pico_socket_setoption(psock, PICO_SOCKET_OPT_SNDBUF, &tx_buf_sz)) < 0) + DEBUG_ERROR("unable to set SNDBUF size, err = %d, pico_err = %d", t_err, pico_err); + if((t_err = pico_socket_setoption(psock, PICO_SOCKET_OPT_RCVBUF, &rx_buf_sz)) < 0) + DEBUG_ERROR("unable to set RCVBUF size, err = %d, pico_err = %d", t_err, pico_err); + + if(ZT_SOCK_BEHAVIOR_LINGER) { + int linger_time_ms = ZT_SOCK_BEHAVIOR_LINGER_TIME; + if((t_err = pico_socket_setoption(psock, PICO_SOCKET_OPT_LINGER, &linger_time_ms)) < 0) + DEBUG_ERROR("unable to set LINGER, err = %d, pico_err = %d", t_err, pico_err); + } + } + } + *p = psock; + } + return err; + } int picoTCP::pico_Connect(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen) { |
