Changes in / [8ee163e2:5614a191]
- File:
-
- 1 edited
-
benchmark/io/sendfile/producer.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/sendfile/producer.c
r8ee163e2 r5614a191 47 47 int pipefd[2]; 48 48 struct io_uring ring; 49 50 char * buf;51 49 52 50 struct stats { … … 64 62 static void my_iouring (int out, int in, size_t size, struct stats *); 65 63 static void my_ringlink(int out, int in, size_t size, struct stats *); 66 static void my_readwrit(int out, int in, size_t size, struct stats *);67 64 typedef void (*sender_t)(int out, int in, size_t size, struct stats *); 68 65 … … 74 71 struct addrinfo * addr; 75 72 int file_fd; 76 int ret;77 73 switch(argc) { 78 74 case 3: … … 80 76 // Open the file 81 77 const char * const path = argv[2]; 82 ret = open(path, 0, O_RDONLY);78 int ret = open(path, 0, O_RDONLY); 83 79 if(ret < 0) { 84 80 fprintf( stderr, "cannot open file '%s': %s\n\n", path, strerror(errno) ); … … 180 176 io_uring_queue_init(16, &ring, 0); 181 177 178 { 179 char addr_str[INET_ADDRSTRLEN]; 180 struct sockaddr_in * address = (struct sockaddr_in *) addr->ai_addr; 181 inet_ntop( AF_INET, &address->sin_addr, addr_str, INET_ADDRSTRLEN ); 182 printf("sending '%s' to '%s:%i'\n", file_path, addr_str, ntohs(address->sin_port)); 183 } 184 185 int ret = pipe(pipefd); 186 if( ret < 0 ) { 187 fprintf( stderr, "pipe error: (%d) %s\n\n", (int)errno, strerror(errno) ); 188 exit( PIPE_ERROR ); 189 } 190 191 { 192 ret = fcntl(pipefd[0], F_GETPIPE_SZ); 193 if( ret < 0 ) { 194 fprintf( stderr, "pipe fcntl error: (%d) %s\n\n", (int)errno, strerror(errno) ); 195 exit( PIPE_ERROR ); 196 } 197 printf("%d\n", ret); 198 199 ret = fcntl(pipefd[1], F_GETPIPE_SZ); 200 if( ret < 0 ) { 201 fprintf( stderr, "pipe fcntl 2 error: (%d) %s\n\n", (int)errno, strerror(errno) ); 202 exit( PIPE_ERROR ); 203 } 204 printf("%d\n", ret); 205 } 206 182 207 size_t file_size = 0; 183 208 { … … 191 216 } 192 217 193 {194 char addr_str[INET_ADDRSTRLEN];195 struct sockaddr_in * address = (struct sockaddr_in *) addr->ai_addr;196 inet_ntop( AF_INET, &address->sin_addr, addr_str, INET_ADDRSTRLEN );197 printf("sending '%s' (%zu bytes) to '%s:%i'\n", file_path, file_size, addr_str, ntohs(address->sin_port));198 }199 200 ret = pipe(pipefd);201 if( ret < 0 ) {202 fprintf( stderr, "pipe error: (%d) %s\n\n", (int)errno, strerror(errno) );203 exit( PIPE_ERROR );204 }205 206 buf = malloc(file_size);207 208 printf("--- read + write ---\n");209 run(my_readwrit, addr, file_fd, file_size);210 218 printf("--- splice ---\n"); 211 219 run(my_splice , addr, file_fd, file_size); … … 406 414 io_uring_prep_splice(sqe, in, offset, pipefd[1], -1, size, 0); 407 415 sqe->user_data = SPLICE_IN; 408 sqe->flags = IOSQE_IO_LINK;409 416 has_in = true; 410 417 } … … 413 420 io_uring_prep_splice(sqe, pipefd[0], -1, out, -1, in_pipe, 0); 414 421 sqe->user_data = SPLICE_OUT; 422 if(has_in) sqe->flags = IOSQE_IO_LINK; 415 423 has_out = true; 416 424 } … … 473 481 st->calls++; 474 482 } 475 476 static void my_readwrit(int out, int in, size_t size, struct stats * st) {477 off_t offset = 0;478 size_t writes = 0;479 for(;;) {480 ssize_t reti = pread(in, buf, size, offset);481 if( reti < 0 ) {482 printf("Read in Error : (%d) %s\n\n", (int)errno, strerror(errno) );483 exit( 1 );484 }485 486 offset += reti;487 size -= reti;488 489 size_t in_buf = reti;490 for(;;) {491 ssize_t reto = write(out, buf, in_buf);492 if( reto < 0 ) {493 printf("Write out Error : (%d) %s\n\n", (int)errno, strerror(errno) );494 exit( 1 );495 }496 497 in_buf -= reto;498 writes += reto;499 if(0 == in_buf) break;500 st->shorts.w.cnt++;501 st->shorts.w.bytes += reto;502 }503 if(0 == size) break;504 st->shorts.r.cnt++;505 st->shorts.r.bytes += reti;506 }507 st->calls++;508 st->bytes += writes;509 }
Note:
See TracChangeset
for help on using the changeset viewer.