}
}
+static inline long long timespec_sub_usec(const struct timespec *left,
+ const struct timespec *right)
+{
+ struct timespec result;
+ timespec_sub(&result, left, right);
+ return result.tv_sec * SEC_TO_USEC +
+ result.tv_nsec / USEC_TO_NSEC;
+}
+
+static inline long long timespec2usec(const struct timespec *ts)
+{
+ return ts->tv_sec * SEC_TO_USEC + ts->tv_nsec / USEC_TO_NSEC;
+}
+
+
int create_ac_socket(unsigned int ac)
{
int sockfd;
struct sockaddr_in rem_addr;
int mlen, ret;
unsigned int ac, rem_addr_length;
- unsigned long int trans_time_usec;
- unsigned long int min_trans_time;
- struct timespec send_timestamp,recv_timestamp, trans_time, time_from_reset;
+ long long int trans_time_usec, client_to_server_usec, server_to_client_usec;
+ long long int min_trans_time;
+ struct timespec send_timestamp, server_timestamp, recv_timestamp;
fd_set fdset;
min_trans_time = ~0;
perror("receiver select");
goto out;
}
- mlen = recvfrom(ac_sockfd[ac], &msg, sizeof(msg), 0, \
+ mlen = recvfrom(ac_sockfd[ac], &msg, sizeof(msg), 0,
(struct sockaddr*)&rem_addr, &rem_addr_length);
if (mlen < 0) {
perror("Chyba pri prijimani pozadavku");
}
clock_gettime(CLOCK_MONOTONIC,&recv_timestamp);
send_timestamp = msg.send_timestamp;
+ server_timestamp = msg.sendback_timestamp;
/* Check whether this message was sent after reset_statistics() */
- timespec_sub(&time_from_reset, &send_timestamp, &reset_timestamp);
- if (time_from_reset.tv_sec < 0) {
- printf("ted\n");
+
+ if (timespec_sub_usec(&send_timestamp, &reset_timestamp) < 0) {
continue; /* If so, don't count it */
}
- timespec_sub(&trans_time,&recv_timestamp ,&send_timestamp);
- trans_time_usec = (trans_time.tv_sec * SEC_TO_USEC + \
- trans_time.tv_nsec / USEC_TO_NSEC) /2;
-
+
+ trans_time_usec = timespec_sub_usec(&recv_timestamp ,&send_timestamp);
+ client_to_server_usec = timespec_sub_usec(&server_timestamp, &send_timestamp);
+ server_to_client_usec = timespec_sub_usec(&recv_timestamp, &server_timestamp);
+
+ trans_time_usec /= 2;
+
if (trans_time_usec < MAX_DELAY_US)
delay_stats[ac][trans_time_usec/opt_granularity_usec]++;