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,7 +19,7 @@
#include <sodium.h>
#ifndef CLOCK_MONOTONIC_COARSE
#if !defined(CLOCK_MONOTONIC_COARSE) && defined(CLOCK_MONOTONIC)
# define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
#endif
@@ -199,6 +199,7 @@ static char *sk_get_name (int fd)
return str_cat(strs, COUNT(strs));
}
#ifdef TCP_INFO
static socklen_t sk_get_info (int fd, struct tcp_info *ti)
{
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_advmss, ti->tcpi_reordering);
}
#endif
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;
int version = 0;
#ifdef TCP_INFO
struct {
struct timespec time;
struct tcp_info info;
} tcpinfo = {0};
#endif
struct option opts[] = {
{ "dev", &dev, option_str },
@@ -738,6 +742,7 @@ int main (int argc, char **argv)
return 1;
}
#if defined(CLOCK_MONOTONIC_COARSE) && defined(TCP_INFO)
struct timespec 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))
print_tcp_info(&tcpinfo.info);
}
#endif
buffer_shift(&sock.write.buf);