aboutsummaryrefslogtreecommitdiff
path: root/examples/http3-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/http3-client.c')
-rw-r--r--examples/http3-client.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/examples/http3-client.c b/examples/http3-client.c
index 1dad8c8..03b1133 100644
--- a/examples/http3-client.c
+++ b/examples/http3-client.c
@@ -53,6 +53,9 @@ struct conn_io {
int sock;
+ struct sockaddr_storage local_addr;
+ socklen_t local_addr_len;
+
quiche_conn *conn;
quiche_h3_conn *http3;
@@ -144,8 +147,10 @@ static void recv_cb(EV_P_ ev_io *w, int revents) {
quiche_recv_info recv_info = {
(struct sockaddr *) &peer_addr,
-
peer_addr_len,
+
+ (struct sockaddr *) &conn_io->local_addr,
+ conn_io->local_addr_len,
};
ssize_t done = quiche_conn_recv(conn_io->conn, buf, read, &recv_info);
@@ -334,11 +339,13 @@ static void timeout_cb(EV_P_ ev_timer *w, int revents) {
if (quiche_conn_is_closed(conn_io->conn)) {
quiche_stats stats;
+ quiche_path_stats path_stats;
quiche_conn_stats(conn_io->conn, &stats);
+ quiche_conn_path_stats(conn_io->conn, 0, &path_stats);
fprintf(stderr, "connection closed, recv=%zu sent=%zu lost=%zu rtt=%" PRIu64 "ns\n",
- stats.recv, stats.sent, stats.lost, stats.rtt);
+ stats.recv, stats.sent, stats.lost, path_stats.rtt);
ev_break(EV_A_ EVBREAK_ONE);
return;
@@ -414,7 +421,23 @@ int main(int argc, char *argv[]) {
return -1;
}
- quiche_conn *conn = quiche_connect(host, (const uint8_t*) scid, sizeof(scid),
+ struct conn_io *conn_io = malloc(sizeof(*conn_io));
+ if (conn_io == NULL) {
+ fprintf(stderr, "failed to allocate connection IO\n");
+ return -1;
+ }
+
+ conn_io->local_addr_len = sizeof(conn_io->local_addr);
+ if (getsockname(sock, (struct sockaddr *)&conn_io->local_addr,
+ &conn_io->local_addr_len) != 0)
+ {
+ perror("failed to get local address of socket");
+ return -1;
+ };
+
+ quiche_conn *conn = quiche_connect(host, (const uint8_t *) scid, sizeof(scid),
+ (struct sockaddr *) &conn_io->local_addr,
+ conn_io->local_addr_len,
peer->ai_addr, peer->ai_addrlen, config);
if (conn == NULL) {
@@ -422,12 +445,6 @@ int main(int argc, char *argv[]) {
return -1;
}
- struct conn_io *conn_io = malloc(sizeof(*conn_io));
- if (conn_io == NULL) {
- fprintf(stderr, "failed to allocate connection IO\n");
- return -1;
- }
-
conn_io->sock = sock;
conn_io->conn = conn;
conn_io->host = host;