Merge pull request #2 from jedisct1/sad

Don't expect TCP_INFO and clock_gettime() to be portable
This commit is contained in:
angt
2015-11-07 23:38:37 +01:00

View File

@@ -19,8 +19,8 @@
#include <sodium.h> #include <sodium.h>
#ifndef CLOCK_MONOTONIC_COARSE #if !defined(CLOCK_MONOTONIC_COARSE) && defined(CLOCK_MONOTONIC)
#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC # define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
#endif #endif
#define GT_BUFFER_SIZE (4*1024*1024) #define GT_BUFFER_SIZE (4*1024*1024)
@@ -199,6 +199,7 @@ static char *sk_get_name (int fd)
return str_cat(strs, COUNT(strs)); return str_cat(strs, COUNT(strs));
} }
#ifdef TCP_INFO
static socklen_t sk_get_info (int fd, struct tcp_info *ti) static socklen_t sk_get_info (int fd, struct tcp_info *ti)
{ {
socklen_t len = sizeof(struct tcp_info); socklen_t len = sizeof(struct tcp_info);
@@ -227,6 +228,7 @@ static void print_tcp_info (struct tcp_info *ti)
ti->tcpi_rttvar, ti->tcpi_snd_ssthresh, ti->tcpi_snd_cwnd, ti->tcpi_rttvar, ti->tcpi_snd_ssthresh, ti->tcpi_snd_cwnd,
ti->tcpi_advmss, ti->tcpi_reordering); ti->tcpi_advmss, ti->tcpi_reordering);
} }
#endif
static struct addrinfo *ai_create (const char *host, const char *port, int listener) static struct addrinfo *ai_create (const char *host, const char *port, int listener)
{ {
@@ -637,10 +639,12 @@ int main (int argc, char **argv)
char *congestion = NULL; char *congestion = NULL;
int version = 0; int version = 0;
#ifdef TCP_INFO
struct { struct {
struct timespec time; struct timespec time;
struct tcp_info info; struct tcp_info info;
} tcpinfo = {0}; } tcpinfo = {0};
#endif
struct option opts[] = { struct option opts[] = {
{ "dev", &dev, option_str }, { "dev", &dev, option_str },
@@ -738,6 +742,7 @@ int main (int argc, char **argv)
return 1; return 1;
} }
#if defined(CLOCK_MONOTONIC_COARSE) && defined(TCP_INFO)
struct timespec now; struct timespec now;
clock_gettime(CLOCK_MONOTONIC_COARSE, &now); clock_gettime(CLOCK_MONOTONIC_COARSE, &now);
@@ -746,6 +751,7 @@ int main (int argc, char **argv)
if (sk_get_info(sock.fd, &tcpinfo.info)) if (sk_get_info(sock.fd, &tcpinfo.info))
print_tcp_info(&tcpinfo.info); print_tcp_info(&tcpinfo.info);
} }
#endif
buffer_shift(&sock.write.buf); buffer_shift(&sock.write.buf);