void writer(struct libvchan *ctrl) { int size; unsigned long long write_size = 0; struct timeval tv1, tv2; long t = 0, t1, t2; //int f = open("a", O_RDONLY); while (write_size < total_size) { size = write_size + blocksize > total_size ? total_size - write_size : blocksize; //read(f, buf, size); gettimeofday(&tv1, NULL); size = libvchan_write(ctrl, buf, size); gettimeofday(&tv2, NULL); t1 = tv1.tv_sec*1000000 + tv1.tv_usec; t2 = tv2.tv_sec*1000000 + tv2.tv_usec; t += (t2 - t1); if (size < 0) { perror("vchan write"); exit(1); } write_size += size; } //close(f); printf("BW: %.3f MB/s (%llu bytes in %ld usec), Size: %.2fMB, time: %.3fsec\n", BW(write_size,t), write_size, t, ((double)write_size/(1024*1024)), ((double)t/1000000)); }
static void puffout_strings(libvchan_t * con) { size_t sz, len; vchan_header_t head; DPRINTF(DBG_SERVER,"hello: waiting for hello message\n"); /* Wait for hello */ libvchan_wait(con); sz = libvchan_read(con, &head, sizeof(head)); assert(sz == sizeof(head)); assert(head.msg_type == MSG_HELLO); head.msg_type = MSG_ACK; len = head.len; DPRINTF(DBG_SERVER,"hello: sending hello msg ack\n"); /* Send off ack */ sz = libvchan_write(con, &head, sizeof(head)); assert(sz == sizeof(head)); DPRINTF(DBG_SERVER,"hello: waiting for string\n"); /* Read data */ libvchan_wait(con); sz = libvchan_read(con, &char_buf, len); assert(sz == len); DPRINTF(DBG_SERVER,"hello: got string: %s\n", char_buf); // head.msg_type = MSG_CONC; // sz = libvchan_write(con, &head, sizeof(head)); // assert(sz == sizeof(head)); }
int write_data_exact(libvchan_t *vchan, char *buf, int size) { int written = 0; int ret; while (written < size) { ret = libvchan_write(vchan, buf + written, size - written); if (ret <= 0) handle_vchan_error(vchan, "write data"); written += ret; } // fprintf(stderr, "sent %d bytes\n", size); return size; }
static int write_to_vchan(libvchan_t *ctrl, char *buf, int size) { static int all = 0, waited = 0, nonwaited = 0, full = 0; ssize_t l; fd_set rfds; struct timeval tv = { 0, 0 }; int ret, fd = libvchan_fd_for_select(ctrl); FD_ZERO(&rfds); FD_SET(fd, &rfds); all++; ret = select(fd + 1, &rfds, NULL, NULL, &tv); if (ret == -1) { pa_log("Failed to select() in vchan: %s", pa_cstrerror(errno)); return -1; } if (ret) { if (libvchan_wait(ctrl) < 0) { pa_log("Failed libvchan_wait"); return -1; } waited++; } else nonwaited++; if (libvchan_buffer_space(ctrl)) { l = libvchan_write(ctrl, buf, size); } else { l = -1; errno = EAGAIN; full++; } if ((all % 8000) == 0) { pa_log ("write_to_vchan: all=%d waited=%d nonwaited=%d full=%d\n", all, waited, nonwaited, full); } return l; }