void putData(ivc_connection_t *con, void *buffer, size_t size) { void *buf_cur = buffer, *buf_end = (void*)((uintptr_t)buffer + size); unsigned long item_size = size; uint32_t avail, wrt_amount; assert( con->outbuf ); /* wait until we have enough data to write the size, then do so */ do { avail = con->outsize - getAvail(con->outmod, con->output); } while(avail < sizeof(unsigned long)); writeRaw(con, &item_size, sizeof(unsigned long)); /* write out the data */ while(buf_cur < buf_end) { avail = con->outsize - getAvail(con->outmod, con->output); wrt_amount = (avail > item_size) ? item_size : avail; if(wrt_amount > 0) { writeRaw(con, buf_cur, wrt_amount); buf_cur = (void*)((uintptr_t)buf_cur + wrt_amount); item_size -= wrt_amount; } else usleep(0); } assert(item_size == 0); }
void *getData(ivc_connection_t *con) { void *item_start, *item_cur, *item_end; uint32_t avail, rd_amount; unsigned long item_size; assert( con->inbuf ); /* wait until we have enough data to read the size */ do { avail = getAvail(con->inmod, con->input); } while(avail < sizeof(unsigned long)); /* read the size, allocate the buffer, compute various pointers */ readRaw(con, &item_size, sizeof(unsigned long)); item_start = item_cur = malloc(item_size); item_end = (void*)((uintptr_t)item_start + item_size); /* read in the data */ while(item_cur < item_end) { avail = getAvail(con->inmod, con->input); rd_amount = (avail > item_size) ? item_size : avail; if(rd_amount > 0) { readRaw(con, item_cur, rd_amount); item_cur = (void*)((uintptr_t)item_cur + rd_amount); item_size -= rd_amount; } else usleep(0); } assert(item_size == 0); return item_start; }
// get the Bitcoin exposition double getActivePos(Parameters& params){ return getAvail(params, "btc"); }
double getActivePos(CURL *curl, Parameters params) { return getAvail(curl, params, "btc"); }