Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/sendfile/producer.c

    r3a40df6 r3263e2a4  
    4747int pipefd[2];
    4848struct io_uring ring;
    49 
    50 char * buf;
    5149
    5250struct stats {
     
    6462static void my_iouring (int out, int in, size_t size, struct stats *);
    6563static 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 *);
    6764typedef void (*sender_t)(int out, int in, size_t size, struct stats *);
    6865
     
    7471        struct addrinfo * addr;
    7572        int file_fd;
    76         int ret;
    7773        switch(argc) {
    7874        case 3:
     
    8076                        // Open the file
    8177                        const char * const path = argv[2];
    82                         ret = open(path, 0, O_RDONLY);
     78                        int ret = open(path, 0, O_RDONLY);
    8379                        if(ret < 0) {
    8480                                fprintf( stderr, "cannot open file '%s': %s\n\n", path, strerror(errno) );
     
    180176        io_uring_queue_init(16, &ring, 0);
    181177
     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
    182207        size_t file_size = 0;
    183208        {
     
    191216        }
    192217
    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);
    210218        printf("--- splice ---\n");
    211219        run(my_splice  , addr, file_fd, file_size);
     
    406414                        io_uring_prep_splice(sqe, in, offset, pipefd[1], -1, size, 0);
    407415                        sqe->user_data = SPLICE_IN;
    408                         sqe->flags = IOSQE_IO_LINK;
    409416                        has_in = true;
    410417                }
     
    413420                        io_uring_prep_splice(sqe, pipefd[0], -1, out, -1, in_pipe, 0);
    414421                        sqe->user_data = SPLICE_OUT;
     422                        if(has_in) sqe->flags = IOSQE_IO_LINK;
    415423                        has_out = true;
    416424                }
     
    473481        st->calls++;
    474482}
    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.