Commit 5c8cffa3 authored by Joanne Hugé's avatar Joanne Hugé

Make the server print intervals between packet receptions

parent fa4f28e6
......@@ -76,8 +76,8 @@ int main(int argc, char *argv[]) {
main_param_t main_param;
// Default values
param.interval = 1;
param.max_cycles = -1;
param.interval = 100000 * 1000;
param.max_cycles = 0;
param.priority = 99;
main_param.refresh_rate = 50000;
......@@ -93,9 +93,12 @@ int main(int argc, char *argv[]) {
for (;;) {
usleep(main_param.refresh_rate);
#ifdef DEBUG_ENABLE
printf("Nb cycles: %d\n", param.stats.nb_cycles);
#endif
if (param.max_cycles == param.stats.nb_cycles) break;
if(param.max_cycles)
if(param.max_cycles == param.stats.nb_cycles) break;
}
exit(EXIT_SUCCESS);
......
......@@ -2,16 +2,24 @@
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#define NSEC_PER_SEC UINT64_C(1000000000)
#define SERVER_PORT "50000"
#define BUFFER_SIZE 1024
static inline uint64_t calcdiff_ns(struct timespec t1, struct timespec t2);
static inline uint64_t max(uint64_t a, uint64_t b);
static inline uint64_t min(uint64_t a, uint64_t b);
static void *get_in_addr(struct sockaddr *sa) {
if (sa->sa_family == AF_INET) return &(((struct sockaddr_in *)sa)->sin_addr);
return &(((struct sockaddr_in6 *)sa)->sin6_addr);
......@@ -19,6 +27,9 @@ static void *get_in_addr(struct sockaddr *sa) {
int main() {
int status;
struct timespec current, previous;
uint64_t diff;
int sockfd = 0;
struct addrinfo hints, *servinfo, *servinfo_it;
......@@ -72,17 +83,33 @@ int main() {
printf("recvfrom error\n");
return 2;
}
clock_gettime(CLOCK_MONOTONIC, &current);
inet_ntop(client_addr.ss_family,
get_in_addr((struct sockaddr *)&client_addr), client_addr_str,
sizeof(client_addr_str));
buf[bytes_received] = '\0';
printf("got packet from %s: %s (%d long)\n", client_addr_str, buf,
bytes_received);
diff = calcdiff_ns(current, previous);
printf("%ld: got packet from %s: %s (%d long)\n", diff, client_addr_str,
buf, bytes_received);
previous = current;
}
close(sockfd);
return 0;
}
static inline uint64_t calcdiff_ns(struct timespec t1, struct timespec t2) {
uint64_t diff;
diff = NSEC_PER_SEC * (uint64_t)((int)t1.tv_sec - (int)t2.tv_sec);
diff += ((int)t1.tv_nsec - (int)t2.tv_nsec);
return diff;
}
static inline uint64_t max(uint64_t a, uint64_t b) { return a > b ? a : b; }
static inline uint64_t min(uint64_t a, uint64_t b) { return a < b ? a : b; }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment