@@ -49,6 +49,8 @@ static struct {
4949 off_t offset ; /* Reset it after writing this many bytes */
5050} g_reset_stream ;
5151
52+ static size_t g_max_file_bytes ; /* If set, limit file read to this many bytes */
53+
5254struct file {
5355 LIST_ENTRY (file ) next_file ;
5456 const char * filename ;
@@ -167,7 +169,10 @@ client_on_new_stream (void *stream_if_ctx, lsquic_stream_t *stream)
167169 st_h -> file -> fd = -1 ;
168170 st_h -> file -> reader .lsqr_read = test_reader_read ;
169171 st_h -> file -> reader .lsqr_size = test_reader_size ;
170- st_h -> file -> reader .lsqr_ctx = create_lsquic_reader_ctx (st_h -> file -> filename );
172+ if (g_max_file_bytes > 0 )
173+ st_h -> file -> reader .lsqr_ctx = create_lsquic_reader_ctx_max_bytes (st_h -> file -> filename , g_max_file_bytes );
174+ else
175+ st_h -> file -> reader .lsqr_ctx = create_lsquic_reader_ctx (st_h -> file -> filename );
171176 if (!st_h -> file -> reader .lsqr_ctx )
172177 exit (1 );
173178 }
@@ -440,6 +445,7 @@ usage (const char *prog)
440445"Options:\n"
441446" -f FILE File to send to the server -- must be specified at least\n"
442447" once.\n"
448+ " -n BYTES Limit number of bytes to read from file(s).\n"
443449" -b Use buffering API for sending files over rather than\n"
444450" the efficient version.\n"
445451" -p PRIORITY Applicatble to previous file specified with -f\n"
@@ -466,9 +472,12 @@ main (int argc, char **argv)
466472 prog_init (& prog , 0 , & sports , & client_file_stream_if , & client_ctx );
467473 prog .prog_api .ea_alpn = "md5" ;
468474
469- while (-1 != (opt = getopt (argc , argv , PROG_OPTS "bhr:f:p:" )))
475+ while (-1 != (opt = getopt (argc , argv , PROG_OPTS "bhr:f:p:n: " )))
470476 {
471477 switch (opt ) {
478+ case 'n' :
479+ g_max_file_bytes = atoll (optarg );
480+ break ;
472481 case 'p' :
473482 if (file )
474483 file -> priority = atoi (optarg );
0 commit comments