… | |
… | |
45 | { |
45 | { |
46 | if (destroyed ()) |
46 | if (destroyed ()) |
47 | return; |
47 | return; |
48 | |
48 | |
49 | #if HAVE_TCP_INFO |
49 | #if HAVE_TCP_INFO |
50 | // check about once per second, spread evenly over all clients |
|
|
51 | // do this only when player is active |
|
|
52 | if (!((pticks + fd) & 7) && pl && pl->active) |
|
|
53 | { |
|
|
54 | // check time of last ack, and, if too old, kill connection |
50 | // check time of last ack, and, if too old, kill connection |
55 | socklen_t len = sizeof (tcpi); |
51 | socklen_t len = sizeof (tcpi); |
56 | |
52 | |
57 | if (!getsockopt (fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) && len == sizeof (tcpi)) |
53 | if (!getsockopt (fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) && len == sizeof (tcpi)) |
58 | { |
54 | { |
59 | if (tcpi.tcpi_snd_mss) |
55 | if (tcpi.tcpi_snd_mss) |
60 | mss = tcpi.tcpi_snd_mss; |
56 | mss = tcpi.tcpi_snd_mss; |
61 | |
57 | |
62 | //fprintf (stderr, "uack %d sst %d cwnd %d mss %d pmtu %d\n", |
58 | #if 0 |
|
|
59 | fprintf (stderr, "uack %d ack %d lost %d ret %d fack %d sst %d cwnd %d mss %d pmtu %d advmss %d EXC %d\n", |
|
|
60 | tcpi.tcpi_unacked, |
|
|
61 | tcpi.tcpi_sacked, |
|
|
62 | tcpi.tcpi_lost, |
|
|
63 | tcpi.tcpi_retrans, |
|
|
64 | tcpi.tcpi_fackets, |
63 | // tcpi.tcpi_unacked, tcpi.tcpi_snd_ssthresh, tcpi.tcpi_snd_cwnd, tcpi.tcpi_advmss, tcpi.tcpi_pmtu); |
65 | tcpi.tcpi_snd_ssthresh, tcpi.tcpi_snd_cwnd, tcpi.tcpi_advmss, tcpi.tcpi_pmtu, tcpi.tcpi_advmss, |
|
|
66 | |
|
|
67 | tcpi.tcpi_snd_cwnd - (tcpi.tcpi_unacked - tcpi.tcpi_sacked)); |
|
|
68 | #endif |
64 | |
69 | |
|
|
70 | // do this only when player is active |
|
|
71 | if (pl && pl->active |
65 | if (tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000)) |
72 | && tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000)) |
66 | { |
73 | { |
67 | send_msg (NDI_RED | NDI_REPLY, "connection-timeout", "safety disconnect due to tcp/ip timeout (no packets received)"); |
74 | send_msg (NDI_RED | NDI_REPLY, "connection-timeout", "safety disconnect due to tcp/ip timeout (no packets received)"); |
68 | write_outputbuffer (); |
75 | write_outputbuffer (); |
69 | |
76 | |
70 | LOG (llevDebug, "connection on fd %d closed due to ack timeout (%u/%u/%u)\n", fd, |
77 | LOG (llevDebug, "connection on fd %d closed due to ack timeout (%u/%u/%u)\n", fd, |
71 | (unsigned)tcpi.tcpi_last_ack_recv, (unsigned)tcpi.tcpi_last_data_sent, (unsigned)tcpi.tcpi_unacked); |
78 | (unsigned)tcpi.tcpi_last_ack_recv, (unsigned)tcpi.tcpi_last_data_sent, (unsigned)tcpi.tcpi_unacked); |
72 | destroy (); |
79 | destroy (); |
73 | } |
|
|
74 | } |
80 | } |
75 | } |
81 | } |
76 | #endif |
82 | #endif |
77 | |
83 | |
78 | /** |
84 | /** |