Пример #1
0
int _read_netstream(NetStream_t *ns, tbuffer_t *buffer, int boff, int size, Net_timeout_t timeout, int dolock)
{
    int total_bytes, i;
    tbuffer_t ns_tb;

    if (size == 0) return(0);

    if (dolock == 1) lock_read_ns(ns);

    if (ns->sock_status(ns->sock) != 1) {
        log_printf(15, "read_netstream: Dead connection!  ns=%d\n", ns->id);
        if (dolock == 1) unlock_read_ns(ns);
        return(-1);
    }

    total_bytes = 0;

    if (ns_read_chksum_state(ns) == 1) {  //** We have chksumming enabled
        if (size > ns->read_chksum.bytesleft) {
            size = ns->read_chksum.bytesleft;  //** Truncate at the block
        }
    }

    //*** 1st grab anything currently in the network buffer ***
    if (ns->end >= ns->start) {
        i = ns->end - ns->start + 1;
        if (i>size) {
            total_bytes = size;
            tbuffer_single(&ns_tb, size, &(ns->buffer[ns->start]));
            tbuffer_copy(&ns_tb, 0, buffer, boff, size, 1);
            ns->start = ns->start + total_bytes;
        } else {
            total_bytes = i;
            tbuffer_single(&ns_tb, i, &(ns->buffer[ns->start]));
            tbuffer_copy(&ns_tb, 0, buffer, boff, i, 1);
            ns->start = 0;
            ns->end = -1;
        }
    } else {  //*** Now grab some data off the network port ****
        total_bytes = ns->read(ns->sock, buffer, boff, size, timeout);
    }

    debug_code(
    if (total_bytes > 0) {
//        debug_printf(10, "read_netstream: Command : !");
//        for (i=0; i< total_bytes; i++) debug_printf(10, "%c", buffer[i]);
//        debug_printf(10, "! * nbytes =%d\n", total_bytes); flush_debug();
} else if (total_bytes == 0) {
    debug_printf(10, "read_netstream: No data!\n");
    } else {
        log_printf(10, "read_netstream:  Dead connection! ns=%d\n", ns_getid(ns));
    }
    )
Пример #2
0
void unlock_ns(tbx_ns_t *ns)
{
    unlock_write_ns(ns);
    unlock_read_ns(ns);
}
Пример #3
0
void unlock_ns(NetStream_t *ns)
{
    unlock_write_ns(ns);
    unlock_read_ns(ns);
}