ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/lowlevel.C
(Generate patch)

Comparing deliantra/server/socket/lowlevel.C (file contents):
Revision 1.43 by root, Sat Jun 9 22:54:04 2007 UTC vs.
Revision 1.47 by root, Tue Jun 12 10:29:52 2007 UTC

19 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22 */ 22 */
23 23
24/**
25 * \file
26 * Low-level socket-related functions.
27 *
28 * \date 2003-12-02
29 *
30 * Contains some base functions that both the client and server
31 * can use. As such, depending what we are being compiled for will
32 * determine what we can include. the client is designed have
33 * CFCLIENT defined as part of its compile flags.
34 */
35
36using namespace std; 24using namespace std;
37 25
38#include <global.h> 26#include <global.h>
39#include <sproto.h> 27#include <sproto.h>
40#include <cstdarg> 28#include <cstdarg>
41 29
42#ifdef __linux__ 30#if HAVE_TCP_INFO
43# include <sys/types.h> 31# include <sys/types.h>
44# include <sys/socket.h> 32# include <sys/socket.h>
45# include <netinet/in.h> 33# include <netinet/in.h>
46# include <netinet/tcp.h> 34# include <netinet/tcp.h>
47#endif 35#endif
57client::flush () 45client::flush ()
58{ 46{
59 if (destroyed ()) 47 if (destroyed ())
60 return; 48 return;
61 49
62#ifdef __linux__ 50#if HAVE_TCP_INFO
63 // check about once per second, spread evenly over all clients 51 // check about once per second, spread evenly over all clients
64 if (!((pticks + fd) & 7)) 52 // do this only when player is active
53 if (!((pticks + fd) & 7) && pl && pl->active)
65 { 54 {
66 // check time of last ack, and, if too old, kill connection 55 // check time of last ack, and, if too old, kill connection
67 struct tcp_info tcpi; 56 struct tcp_info tcpi;
68 socklen_t len = sizeof (tcpi); 57 socklen_t len = sizeof (tcpi);
69 58
70 if (!getsockopt (fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) && len == sizeof (tcpi)) 59 if (!getsockopt (fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) && len == sizeof (tcpi))
71 { 60 {
61 if (tcpi.tcpi_snd_mss)
62 mss = tcpi.tcpi_snd_mss;
63
72 rtt = tcpi.tcpi_rtt; 64 rtt = tcpi.tcpi_rtt;
73 rttvar = tcpi.tcpi_rttvar; 65 rttvar = tcpi.tcpi_rttvar;
74 66
75 if (tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000)) 67 if (tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000))
76 { 68 {
93 */ 85 */
94 86
95 // write a nop to the socket at least every IDLE_NOP seconds. 87 // write a nop to the socket at least every IDLE_NOP seconds.
96 if (!outputbuffer.len) 88 if (!outputbuffer.len)
97 { 89 {
98 if (last_send + IDLE_PING <= NOW) 90 if (last_send + IDLE_PING <= NOW && pl && pl->active)
99 { 91 {
100 // this is a bit ugly, but map1/map1a seem to be the only 92 // this is a bit ugly, but map1/map1a seem to be the only
101 // nop'able commands and they are quite small. 93 // nop'able commands and they are quite small.
102 packet sl (mapmode == Map1Cmd ? "map1" : "map1a"); 94 packet sl (mapmode == Map1Cmd ? "map1" : "map1a");
103 send_packet (sl); 95 send_packet (sl);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines