Changeset 8ee163e2
- Timestamp:
- Feb 17, 2022, 12:57:12 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- f0567a8
- Parents:
- 5614a191 (diff), 3a40df6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/sendfile/producer.c
r5614a191 r8ee163e2 47 47 int pipefd[2]; 48 48 struct io_uring ring; 49 50 char * buf; 49 51 50 52 struct stats { … … 62 64 static void my_iouring (int out, int in, size_t size, struct stats *); 63 65 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 *); 64 67 typedef void (*sender_t)(int out, int in, size_t size, struct stats *); 65 68 … … 71 74 struct addrinfo * addr; 72 75 int file_fd; 76 int ret; 73 77 switch(argc) { 74 78 case 3: … … 76 80 // Open the file 77 81 const char * const path = argv[2]; 78 intret = open(path, 0, O_RDONLY);82 ret = open(path, 0, O_RDONLY); 79 83 if(ret < 0) { 80 84 fprintf( stderr, "cannot open file '%s': %s\n\n", path, strerror(errno) ); … … 176 180 io_uring_queue_init(16, &ring, 0); 177 181 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 207 182 size_t file_size = 0; 208 183 { … … 216 191 } 217 192 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); 218 210 printf("--- splice ---\n"); 219 211 run(my_splice , addr, file_fd, file_size); … … 414 406 io_uring_prep_splice(sqe, in, offset, pipefd[1], -1, size, 0); 415 407 sqe->user_data = SPLICE_IN; 408 sqe->flags = IOSQE_IO_LINK; 416 409 has_in = true; 417 410 } … … 420 413 io_uring_prep_splice(sqe, pipefd[0], -1, out, -1, in_pipe, 0); 421 414 sqe->user_data = SPLICE_OUT; 422 if(has_in) sqe->flags = IOSQE_IO_LINK;423 415 has_out = true; 424 416 } … … 481 473 st->calls++; 482 474 } 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.