… | |
… | |
50 | // check about once per second, spread evenly over all clients |
50 | // check about once per second, spread evenly over all clients |
51 | // do this only when player is active |
51 | // do this only when player is active |
52 | if (!((pticks + fd) & 7) && pl && pl->active) |
52 | if (!((pticks + fd) & 7) && pl && pl->active) |
53 | { |
53 | { |
54 | // check time of last ack, and, if too old, kill connection |
54 | // check time of last ack, and, if too old, kill connection |
55 | struct tcp_info tcpi; |
|
|
56 | socklen_t len = sizeof (tcpi); |
55 | socklen_t len = sizeof (tcpi); |
57 | |
56 | |
58 | if (!getsockopt (fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) && len == sizeof (tcpi)) |
57 | if (!getsockopt (fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) && len == sizeof (tcpi)) |
59 | { |
58 | { |
60 | if (tcpi.tcpi_snd_mss) |
59 | if (tcpi.tcpi_snd_mss) |
61 | mss = tcpi.tcpi_snd_mss; |
60 | mss = tcpi.tcpi_snd_mss; |
62 | |
61 | |
63 | rtt = tcpi.tcpi_rtt; |
62 | //fprintf (stderr, "uack %d sst %d cwnd %d mss %d pmtu %d\n", |
64 | rttvar = tcpi.tcpi_rttvar; |
63 | // tcpi.tcpi_unacked, tcpi.tcpi_snd_ssthresh, tcpi.tcpi_snd_cwnd, tcpi.tcpi_advmss, tcpi.tcpi_pmtu); |
65 | |
64 | |
66 | if (tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000)) |
65 | if (tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000)) |
67 | { |
66 | { |
68 | send_msg (NDI_RED, "connection-timeout", "safety disconnect due to tcp/ip timeout (no packets received)"); |
67 | send_msg (NDI_RED, "connection-timeout", "safety disconnect due to tcp/ip timeout (no packets received)"); |
69 | write_outputbuffer (); |
68 | write_outputbuffer (); |