Function libzt::utils::zts_connect[][src]

pub unsafe extern "C" fn zts_connect(
    fd: c_int,
    ipstr: *const c_char,
    port: c_ushort,
    timeout_ms: c_int
) -> c_int
Expand description

@brief Connect a socket to a remote host

This convenience function exists because ZeroTier uses transport-triggered links. This means that links between peers do not exist until peers try to talk to each other. This can be a problem during connection procedures since some of the initial packets are lost. To alleviate the need to try zts_bsd_connect many times, this function will keep re-trying for you, even if no known routes exist. However, if the socket is set to non-blocking mode it will behave identically to zts_bsd_connect and return immediately upon failure.

@param fd Socket file descriptor @param ipstr Human-readable IP string @param port Port @param timeout_ms (Approximate) amount of time in milliseconds before connection attempt is aborted. Will block for 30 seconds if timeout is set to 0.

@return ZTS_ERR_OK if successful, ZTS_ERR_SOCKET if the function times out with no connection made, ZTS_ERR_SERVICE if the node experiences a problem, ZTS_ERR_ARG if invalid argument. Sets zts_errno