diff options
Diffstat (limited to 'examples/client.c')
-rw-r--r-- | examples/client.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/examples/client.c b/examples/client.c index 0df9665..ebe049b 100644 --- a/examples/client.c +++ b/examples/client.c @@ -51,6 +51,9 @@ struct conn_io { int sock; + struct sockaddr_storage local_addr; + socklen_t local_addr_len; + quiche_conn *conn; }; @@ -122,8 +125,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); @@ -206,11 +211,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; @@ -282,7 +289,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) { @@ -290,12 +313,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; |