Skip to content

Commit

Permalink
Merge branch 'refs/heads/picoquicdemo-stop-sending'
Browse files Browse the repository at this point in the history
  • Loading branch information
hfstco committed Jul 7, 2024
2 parents 95d5de4 + a7e18a0 commit 8c49e1c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
11 changes: 10 additions & 1 deletion picohttp/democlient.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,14 @@ int picoquic_demo_client_callback(picoquic_cnx_t* cnx,
stream_ctx = picoquic_demo_client_find_stream(ctx, stream_id);
}
if (stream_ctx != NULL && stream_ctx->is_open) {
/*
* Request to stop sending if time is up.
*/
if(picoquic_current_time() > ctx->stop_sending_time) {
picoquic_stop_sending(cnx, stream_id, 0);
fprintf(stdout, "Request to stop sending.\n");
}

if (!stream_ctx->is_file_open && ctx->no_disk == 0) {
ret = picoquic_demo_client_open_stream_file(cnx, ctx, stream_ctx);
}
Expand Down Expand Up @@ -631,14 +639,15 @@ int picoquic_demo_client_initialize_context(
picoquic_demo_stream_desc_t const * demo_stream,
size_t nb_demo_streams,
char const * alpn,
int no_disk, int delay_fin)
int no_disk, int delay_fin, uint64_t stop_time)
{
memset(ctx, 0, sizeof(picoquic_demo_callback_ctx_t));
ctx->demo_stream = demo_stream;
ctx->nb_demo_streams = nb_demo_streams;
ctx->alpn = picoquic_parse_alpn(alpn);
ctx->no_disk = no_disk;
ctx->delay_fin = delay_fin;
ctx->stop_sending_time = stop_time;

return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion picohttp/democlient.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef struct st_picoquic_demo_client_callback_ctx_t {
int no_print;
int connection_ready;
int connection_closed;
uint64_t stop_sending_time;
} picoquic_demo_callback_ctx_t;

picoquic_alpn_enum picoquic_parse_alpn(char const * alpn);
Expand Down Expand Up @@ -116,7 +117,7 @@ int picoquic_demo_client_initialize_context(
picoquic_demo_stream_desc_t const * demo_stream,
size_t nb_demo_streams,
char const * alpn,
int no_disk, int delay_fin);
int no_disk, int delay_fin, uint64_t stop_time);
void picoquic_demo_client_delete_context(picoquic_demo_callback_ctx_t* ctx);

int demo_client_parse_scenario_desc(char const * text, size_t * nb_streams, picoquic_demo_stream_desc_t ** desc);
Expand Down
19 changes: 14 additions & 5 deletions picoquicfirst/picoquicdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ int client_loop_cb(picoquic_quic_t* quic, picoquic_packet_loop_cb_enum cb_mode,
/* Quic Client */
int quic_client(const char* ip_address_text, int server_port,
picoquic_quic_config_t * config, int force_migration,
int nb_packets_before_key_update, char const * client_scenario_text)
int nb_packets_before_key_update, uint64_t stop_sending_after, char const * client_scenario_text)
{
/* Start: start the QUIC process with cert and key files */
int ret = 0;
Expand Down Expand Up @@ -858,7 +858,10 @@ int quic_client(const char* ip_address_text, int server_port,
return -1;
}
else {
ret = picoquic_demo_client_initialize_context(&callback_ctx, client_sc, client_sc_nb, config->alpn, config->no_disk, 0);
if (stop_sending_after != -1) {
fprintf(stdout, "Stop sending after: %" PRIu64 "\n", stop_sending_after);
}
ret = picoquic_demo_client_initialize_context(&callback_ctx, client_sc, client_sc_nb, config->alpn, config->no_disk, 0, (stop_sending_after != -1 ) ? current_time + stop_sending_after : UINT64_MAX);
callback_ctx.out_dir = config->out_dir;
}
}
Expand Down Expand Up @@ -1251,6 +1254,7 @@ int main(int argc, char** argv)
int force_migration = 0;
int just_once = 0;
int is_client = 0;
uint64_t stop_sending_after = -1;
int ret;

/* Disable stdout buffering. */
Expand All @@ -1261,8 +1265,8 @@ int main(int argc, char** argv)
(void)WSA_START(MAKEWORD(2, 2), &wsaData);
#endif
picoquic_config_init(&config);
memcpy(option_string, "A:u:f:1", 7);
ret = picoquic_config_option_letters(option_string + 7, sizeof(option_string) - 7, NULL);
memcpy(option_string, "A:E:u:f:1", 9);
ret = picoquic_config_option_letters(option_string + 9, sizeof(option_string) - 7, NULL);

if (ret == 0) {
/* Get the parameters */
Expand All @@ -1284,6 +1288,11 @@ int main(int argc, char** argv)
case '1':
just_once = 1;
break;
case 'E':
if ((stop_sending_after = atoi(optarg)) <= 0) {
fprintf(stderr, "Invalid time: %s\n", optarg);
usage();
}
case 'A':
config.multipath_alt_config = malloc(sizeof(char) * (strlen(optarg) + 1));
memcpy(config.multipath_alt_config, optarg, sizeof(char) * (strlen(optarg) + 1));
Expand Down Expand Up @@ -1346,7 +1355,7 @@ int main(int argc, char** argv)
/* Run as client */
printf("Starting Picoquic (v%s) connection to server = %s, port = %d\n", PICOQUIC_VERSION, server_name, server_port);
ret = quic_client(server_name, server_port, &config,
force_migration, nb_packets_before_update, client_scenario);
force_migration, nb_packets_before_update, stop_sending_after, client_scenario);

printf("Client exit with code = %d\n", ret);
}
Expand Down

0 comments on commit 8c49e1c

Please sign in to comment.