int _tbx_ns_write(tbx_ns_t *ns, tbx_tbuf_t *buffer, unsigned int boff, int bsize, tbx_ns_timeout_t timeout, int dolock) { int total_bytes, i; if (dolock == 1) lock_write_ns(ns); if (ns->sock_status(ns->sock) != 1) { log_printf(15, "write_netstream: connection closed! ns=%d\n", ns->id); if (dolock == 1) unlock_write_ns(ns); return(-1); } if (bsize == 0) { if (dolock == 1) unlock_write_ns(ns); return(0); } if (ns_write_chksum_state(ns) == 1) { //** We have chksumming enabled if (bsize > ns->write_chksum.bytesleft) { bsize = ns->write_chksum.bytesleft; //** Truncate at the block } } total_bytes = ns->write(ns->sock, buffer, boff, bsize, timeout); if (total_bytes == -1) { log_printf(10, "write_netstream: Dead connection! ns=%d\n", tbx_ns_getid(ns)); } ns->last_write = apr_time_now(); if ((ns_write_chksum_state(ns) == 1) && (total_bytes > 0)) { //** We have chksumming enabled tbx_chksum_add(&(ns->write_chksum.chksum), total_bytes, buffer, boff); //** Chksum it ns->write_chksum.bytesleft -= total_bytes; if (ns->write_chksum.bytesleft <= 0) { //** Reached the block size so inject the chksum i = tbx_ns_chksum_write_flush(ns); if (i != 0) total_bytes = NS_CHKSUM; //** Reset the chksum ns->write_chksum.bytesleft = ns->write_chksum.blocksize; tbx_chksum_reset(&(ns->write_chksum.chksum)); } } if (dolock == 1) unlock_write_ns(ns); return(total_bytes); }
void lock_ns(tbx_ns_t *ns) { lock_read_ns(ns); lock_write_ns(ns); }
void lock_ns(NetStream_t *ns) { lock_read_ns(ns); lock_write_ns(ns); }