int tbx_ns_connect(tbx_ns_t *ns, const char *hostname, int port, tbx_ns_timeout_t timeout) { int err; lock_ns(ns); //** Simple check on the connection type ** switch (ns->sock_type) { case NS_TYPE_SOCK: case NS_TYPE_PHOEBUS: case NS_TYPE_1_SSL: case NS_TYPE_ZSOCK: break; default: log_printf(0, "net_connect: Invalid ns_type=%d Exiting!\n", ns->sock_type); unlock_ns(ns); return(1); } err = ns->connect(ns->sock, hostname, port, timeout); if (err != 0) { log_printf(5, "net_connect: select failed. Hostname: %s Port: %d select=%d errno: %d error: %s\n", hostname, port, err, errno, strerror(errno)); unlock_ns(ns); return(1); } ns->set_peer(ns->sock, ns->peer_address, sizeof(ns->peer_address)); ns->id = tbx_ns_generate_id(); log_printf(10, "net_connect: Made connection to %s:%d on ns=%d address=%s\n", hostname, port, ns->id, ns->peer_address); log_printf(10, "net_connect: final ns=%d\n", ns->id); unlock_ns(ns); return(0); }
void ns_clone(tbx_ns_t *dest_ns, tbx_ns_t *src_ns) { apr_thread_mutex_t *rl, *wl; apr_pool_t *mpool; //** Need to preserve the locks and pool they came from rl = dest_ns->read_lock; wl = dest_ns->write_lock; mpool = dest_ns->mpool; lock_ns(src_ns); memcpy(dest_ns, src_ns, sizeof(tbx_ns_t)); unlock_ns(src_ns); dest_ns->read_lock = rl; dest_ns->write_lock = wl; dest_ns->mpool = mpool; }
void tbx_ns_close(tbx_ns_t *ns) { lock_ns(ns); _close_ns(ns); unlock_ns(ns); }
void close_netstream(NetStream_t *ns) { lock_ns(ns); _close_ns(ns); unlock_ns(ns); }