コード例 #1
0
ファイル: network.c プロジェクト: accre/lstore
int _tbx_ns_read(tbx_ns_t *ns, tbx_tbuf_t *buffer, unsigned int boff, int size, tbx_ns_timeout_t timeout, int dolock)
{
    int total_bytes, i;
    tbx_tbuf_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);
    }

    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;
            tbx_tbuf_single(&ns_tb, size, &(ns->buffer[ns->start]));
            tbx_tbuf_copy(&ns_tb, 0, buffer, boff, size, 1);
            ns->start = ns->start + total_bytes;
        } else {
            total_bytes = i;
            tbx_tbuf_single(&ns_tb, i, &(ns->buffer[ns->start]));
            tbx_tbuf_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", tbx_ns_getid(ns));
    }
    )
コード例 #2
0
ファイル: network.c プロジェクト: accre/lstore
int tbx_ns_chksum_write_flush(tbx_ns_t *ns)
{
    char chksum_value[CHKSUM_MAX_SIZE];
    int err, n;
    tbx_tbuf_t buf;

    log_printf(15, "ns_write_chksum_flush: injecting chksum!  ns=%d type=%d bytesleft=" I64T " bsize=" I64T "\n",
               tbx_ns_getid(ns), tbx_chksum_type(&(ns->write_chksum.chksum)), ns->write_chksum.bytesleft, ns->write_chksum.blocksize);
    tbx_log_flush();

    if (ns_write_chksum_state(ns) == 0) return(0);
    if (ns->write_chksum.bytesleft == ns->write_chksum.blocksize) return(0);  //** Nothing to do

    n = tbx_chksum_size(&(ns->write_chksum.chksum), CHKSUM_DIGEST_HEX);
    tbx_chksum_get(&(ns->write_chksum.chksum), CHKSUM_DIGEST_HEX, chksum_value);

    ns->write_chksum.is_running = 0;  //** Don't want to get in an endless loop
    tbx_tbuf_single(&buf, n, chksum_value);
    err = _write_netstream_block(ns, apr_time_now() + apr_time_make(5,0), &buf, 0, n, 0);
    ns->write_chksum.is_running = 1;

    if (err != 0) {
        log_printf(10, "ns_write_chksum_flush: ns=%d Error writing chksum! error=%d\n", tbx_ns_getid(ns), err);
        return(err);
    }

    chksum_value[n] = '\0';
    log_printf(15, "ns_write_chksum_flush: ns=%d chksum_value=%s\n", tbx_ns_getid(ns), chksum_value);
    log_printf(15, "ns_write_chksum_flush: end of routine!  ns=%d\n err=%d", tbx_ns_getid(ns), err);
    tbx_log_flush();

    return(err);
}
コード例 #3
0
ファイル: network.c プロジェクト: accre/lstore
int tbx_ns_chksum_read_flush(tbx_ns_t *ns)
{
    char ns_value[CHKSUM_MAX_SIZE], chksum_value[CHKSUM_MAX_SIZE];
    int err, n;
    tbx_tbuf_t buf;

    log_printf(15, "ns_read_chksum_flush: Reading chksum!  ns=%d type=%d bleft=" I64T " bsize=" I64T " state=%d\n",
               tbx_ns_getid(ns), tbx_chksum_type(&(ns->read_chksum.chksum)), ns->read_chksum.bytesleft, ns->read_chksum.blocksize, ns_read_chksum_state(ns));
    tbx_log_flush();

    if (ns_read_chksum_state(ns) == 0) return(0);
    if (ns->read_chksum.bytesleft == ns->read_chksum.blocksize) return(0);  //** Nothing to do

    n = tbx_chksum_size(&(ns->read_chksum.chksum), CHKSUM_DIGEST_HEX);


    ns->read_chksum.is_running = 0;  //** Don't want to get in an endless loop
    tbx_tbuf_single(&buf, n, ns_value);
    err = _read_netstream_block(ns, apr_time_now() + apr_time_make(5,0), &buf, 0, n, 0);
    ns_value[n] = '\0';
    ns->read_chksum.is_running = 1;

    log_printf(15, "ns_read_chksum_flush: Finished reading chksum!  ns=%d\n", tbx_ns_getid(ns));
    tbx_log_flush();

    if (err != 0) {
        log_printf(10, "ns_read_chksum_flush: ns=%d Error reading chksum! error=%d\n", tbx_ns_getid(ns), err);
        return(err);
    }

    tbx_chksum_get(&(ns->read_chksum.chksum), CHKSUM_DIGEST_HEX, chksum_value);
    log_printf(15, "ns_read_chksum_flush: after tbx_chksum_get!  ns=%d\n", tbx_ns_getid(ns));
    tbx_log_flush();
    err = (strncmp(chksum_value, ns_value, n) == 0) ? 0 : 1;

    log_printf(15, "ns_read_chksum_flush: ns=%d     ns_value=%s  cmp=%d\n", tbx_ns_getid(ns), ns_value, err);
    log_printf(15, "ns_read_chksum_flush: ns=%d chksum_value=%s\n", tbx_ns_getid(ns), chksum_value);
    if (err != 0) {
        log_printf(1, "ns_read_chksum_flush: ns=%d chksum error!\n", tbx_ns_getid(ns));
        log_printf(1, "ns_read_chksum_flush: ns=%d     ns_value=%s  cmp=%d\n", tbx_ns_getid(ns), ns_value, err);
        log_printf(1, "ns_read_chksum_flush: ns=%d chksum_value=%s\n", tbx_ns_getid(ns), chksum_value);
    }

    log_printf(15, "ns_read_chksum_flush: end of routine!  ns=%d\n err=%d", tbx_ns_getid(ns), err);
    tbx_log_flush();

    return(err);
}
コード例 #4
0
ファイル: ibp_sync.c プロジェクト: PerilousApricot/lstore
unsigned long int IBP_load(ibp_cap_t *cap, ibp_timer_t  *timer, char *data,
                           unsigned long int size, unsigned long int offset)
{
    ibp_op_t op;
    int err;
    tbx_tbuf_t buf;

    tbx_tbuf_single(&buf, size, data);

    make_ibp_sync_context();

    init_ibp_op(_ibp_sync, &op);
    set_ibp_read_op(&op, cap, offset, &buf, 0, size, timer->ClientTimeout);
    err = ibp_sync_command(&op);
    gop_free(ibp_get_gop(&op), OP_FINALIZE);

    if (err != IBP_OK) return(0);
    return(size);
}