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

Comparing deliantra/server/socket/init.C (file contents):
Revision 1.39 by root, Sun Mar 11 02:12:45 2007 UTC vs.
Revision 1.43 by root, Mon Apr 2 18:55:22 2007 UTC

61 cmd_ev (this, &client::cmd_cb), 61 cmd_ev (this, &client::cmd_cb),
62 cc_inv (this), cc_other (this) 62 cc_inv (this), cc_other (this)
63{ 63{
64 refcnt_inc (); // the socket is an external reference 64 refcnt_inc (); // the socket is an external reference
65 65
66 mss = 1500 - 52; // 1500 typical ethernet frame, 66 typical tcp header overhead
67
66 { 68 {
67 struct linger linger_opt; 69 struct linger linger_opt;
68 70
69 linger_opt.l_onoff = 0; 71 linger_opt.l_onoff = 0;
70 linger_opt.l_linger = 0; 72 linger_opt.l_linger = 0;
72 if (setsockopt (fd, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof (struct linger))) 74 if (setsockopt (fd, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof (struct linger)))
73 LOG (llevError, "SO_LINGER: %s\n", strerror (errno)); 75 LOG (llevError, "SO_LINGER: %s\n", strerror (errno));
74 } 76 }
75 77
76 { 78 {
79 int val;
80
81#ifdef IP_TOS
77 int val = IPTOS_LOWDELAY; 82 val = IPTOS_LOWDELAY;
78
79 if (setsockopt (fd, IPPROTO_IP, IP_TOS, &val, sizeof (val))) 83 if (setsockopt (fd, IPPROTO_IP, IP_TOS, &val, sizeof (val)))
80 LOG (llevError, "IP_TOS: %s\n", strerror (errno)); 84 LOG (llevError, "IP_TOS: %s\n", strerror (errno));
81 } 85#endif
82 86
83 { 87#ifdef TCP_NODELAY
84 int val = 1; 88 val = 1;
85
86 if (setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val))) 89 if (setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)))
87 LOG (llevError, "TCP_NODELAY: %s\n", strerror (errno)); 90 LOG (llevError, "TCP_NODELAY: %s\n", strerror (errno));
91#endif
92
93 // set some very aggressive keepalive parameters
94#ifdef TCP_KEEPIDLE
95 val = 10;
96 if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof (val)))
97 LOG (llevError, "TCP_KEEPIDLE: %s\n", strerror (errno));
98#endif
99
100#ifdef TCP_KEEPCNT
101 val = 5;
102 if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof (val)))
103 LOG (llevError, "TCP_KEEPCNT: %s\n", strerror (errno));
104#endif
105
106#ifdef TCP_KEEPINTVL
107 val = 1;
108 if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof (val)))
109 LOG (llevError, "TCP_KEEPINTVL: %s\n", strerror (errno));
110#endif
111
112 // try to find the mss value in use
113#ifdef TCP_MAXSEG
114 socklen_t sl = sizeof (val);
115 if (!getsockopt (fd, IPPROTO_TCP, TCP_MAXSEG, &val, &sl) && sl == sizeof (val))
116 mss = val;
117#endif
88 } 118 }
89
90#ifdef __linux__
91 {
92 int val;
93
94 // set some very aggressive keepalive parameters
95 val = 10;
96 if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof (val)))
97 LOG (llevError, "TCP_KEEPIDLE: %s\n", strerror (errno));
98
99 val = 5;
100 if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof (val)))
101 LOG (llevError, "TCP_KEEPCNT: %s\n", strerror (errno));
102
103 val = 1;
104 if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof (val)))
105 LOG (llevError, "TCP_KEEPINTVL: %s\n", strerror (errno));
106 }
107#endif
108 119
109 { 120 {
110 int bufsize = 65535; /*Supposed absolute upper limit */ 121 int bufsize = 65535; /*Supposed absolute upper limit */
111 int oldbufsize; 122 int oldbufsize;
112 int buflen = sizeof (int); 123 int buflen = sizeof (int);
129 mapmode = Map0Cmd; 140 mapmode = Map0Cmd;
130 darkness = 1; 141 darkness = 1;
131 mapx = 11; 142 mapx = 11;
132 mapy = 11; 143 mapy = 11;
133 itemcmd = 1; /* Default is version item1 command */ 144 itemcmd = 1; /* Default is version item1 command */
145 max_rate = 100000 / (1000000 / MAX_TIME); // ~1mbit is assumed per default
134 146
135 /* Do this so we don't send a face command for the client for 147 /* Do this so we don't send a face command for the client for
136 * this face. Face 0 is sent to the client to say clear 148 * this face. Face 0 is sent to the client to say clear
137 * face information. 149 * face information.
138 */ 150 */
139 faces_sent[0] = NS_FACESENT_FACE; 151 faces_sent[0] = true;
140 152
141 socket_ev.prio (PE_PRIO_NORMAL); 153 socket_ev.prio (PE_PRIO_NORMAL);
142 socket_ev.fd (fd); 154 socket_ev.fd (fd);
143 socket_ev.poll (PE_R); 155 socket_ev.poll (PE_R);
144 156

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines