support client ports

This commit is contained in:
Quentin 2021-01-14 11:47:50 +01:00
parent b4cdf34011
commit 946295ca80

View file

@ -34,6 +34,8 @@ int streq(char* s1, char* s2) {
return strcmp(s1, s2) == 0; return strcmp(s1, s2) == 0;
} }
GHashTable* measurements;
struct evt_core_fdinfo* register_timer(struct evt_core_ctx* evts, struct measlat_ctx* mctx, struct measure_state* ms, struct timespec* next_tick) { struct evt_core_fdinfo* register_timer(struct evt_core_ctx* evts, struct measlat_ctx* mctx, struct measure_state* ms, struct timespec* next_tick) {
struct timespec now; struct timespec now;
struct itimerspec timer_config; struct itimerspec timer_config;
@ -188,6 +190,9 @@ int on_tcp_co(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
sprintf(to_fdinfo.url, "tcp:read:127.0.0.1:%s", port); sprintf(to_fdinfo.url, "tcp:read:127.0.0.1:%s", port);
evt_core_add_fd (ctx, &to_fdinfo); evt_core_add_fd (ctx, &to_fdinfo);
uint16_t myPort = ntohs(addr.sin_port);
printf("client port is %u\n", myPort);
return 0; return 0;
co_error: co_error:
@ -396,8 +401,14 @@ void spawn_tcp_client(struct evt_core_ctx* evts) {
printf("--- TCP client registered\n"); printf("--- TCP client registered\n");
struct measure_state ms = {0}; struct measure_state ms = {0};
struct sockaddr_in my_addr;
socklen_t my_addr_len = sizeof(my_addr);
ms.fd = tcp_sock; ms.fd = tcp_sock;
measure_state_init (&mctx->mp, &ms); measure_state_init (&mctx->mp, &ms);
getsockname(tcp_sock, (struct sockaddr *) &my_addr, &my_addr_len);
uint16_t myPort = ntohs(my_addr.sin_port);
printf("client port is %u\n", myPort);
register_timer (evts, mctx, &ms, NULL); register_timer (evts, mctx, &ms, NULL);
} }
@ -448,6 +459,8 @@ int main(int argc, char** argv) {
setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0);
printf("~ measlat ~\n"); printf("~ measlat ~\n");
measurements = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, free_ms);
int opt; int opt;
struct measlat_ctx mctx = {0}; struct measlat_ctx mctx = {0};
struct evt_core_ctx evts = {0}; struct evt_core_ctx evts = {0};
@ -521,8 +534,10 @@ int main(int argc, char** argv) {
// 5. Run main loop // 5. Run main loop
evt_core_loop(&evts); evt_core_loop(&evts);
g_hash_table_destroy (measurements);
return 0; return 0;
usage: usage:
g_hash_table_destroy (measurements);
fprintf(stderr, "Usage: %s [-h <host>] [-p <port>] [-l] [-r] [-t <udp|tor>] [-c <count>] [-i <ms>] [-s <bytes>]\n", argv[0]); fprintf(stderr, "Usage: %s [-h <host>] [-p <port>] [-l] [-r] [-t <udp|tor>] [-c <count>] [-i <ms>] [-s <bytes>]\n", argv[0]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }