int _read_netstream_block(tbx_ns_t *ns, apr_time_t end_time, tbx_tbuf_t *buffer, int pos, int size, int dolock) { int nleft, nbytes, err; tbx_ns_timeout_t dt; tbx_ns_timeout_set(&dt, 1, 0); nleft = size; nbytes = -100; err = NS_OK; while ((nleft > 0) && (err == NS_OK)) { nbytes = _tbx_ns_read(ns, buffer, pos, nleft, dt, dolock); log_printf(15, "read_netstream_block: ns=%d size=%d nleft=%d nbytes=%d pos=%d time=" TT "\n", tbx_ns_getid(ns), size, nleft, nbytes, pos, apr_time_now()); if (apr_time_now() > end_time) { log_printf(15, "read_netstream_block: ns=%d Command timed out! to=" TT " ct=" TT " \n", tbx_ns_getid(ns), end_time, apr_time_now()); err = NS_TIMEOUT; } if (nbytes < 0) { err = nbytes; //** Error with write } else if (nbytes > 0) { //** Normal write pos = pos + nbytes; nleft = nleft - nbytes; err = NS_OK; } } log_printf(15, "read_netstream_block: END ns=%d size=%d nleft=%d nbytes=%d pos=%d\n", tbx_ns_getid(ns), size, nleft, nbytes, pos); return(err); }
void hportal_wait(host_portal_t *hp, int dt) { apr_time_t t; if (dt < 0) return; //** If negative time has run out so return tbx_ns_timeout_set(&t, dt, 0); apr_thread_cond_timedwait(hp->cond, hp->lock, t); }
portal_context_t *create_hportal_context(portal_fn_t *imp) { portal_context_t *hpc; //log_printf(1, "create_hportal_context: start\n"); hpc = (portal_context_t *)malloc(sizeof(portal_context_t)); assert(hpc != NULL); memset(hpc, 0, sizeof(portal_context_t)); assert_result(apr_pool_create(&(hpc->pool), NULL), APR_SUCCESS); hpc->table = apr_hash_make(hpc->pool); assert(hpc->table != NULL); //log_printf(15, "create_hportal_context: hpc=%p hpc->table=%p\n", hpc, hpc->table); apr_thread_mutex_create(&(hpc->lock), APR_THREAD_MUTEX_DEFAULT, hpc->pool); hpc->fn = imp; hpc->next_check = time(NULL); hpc->count = 0; tbx_ns_timeout_set(&(hpc->dt), 1, 0); return(hpc); }