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.22 by root, Sat Dec 16 21:40:26 2006 UTC vs.
Revision 1.26 by root, Wed Dec 20 09:14:22 2006 UTC

37#include <sproto.h> 37#include <sproto.h>
38#include <sys/types.h> 38#include <sys/types.h>
39#include <sys/time.h> 39#include <sys/time.h>
40#include <sys/socket.h> 40#include <sys/socket.h>
41#include <netinet/in.h> 41#include <netinet/in.h>
42#include <netinet/tcp.h>
43#include <netinet/ip.h>
42#include <netdb.h> 44#include <netdb.h>
43 45
44#include <unistd.h> 46#include <unistd.h>
45#include <arpa/inet.h> 47#include <arpa/inet.h>
46 48
52 * client. 54 * client.
53 */ 55 */
54client::client (int fd, const char *peername) 56client::client (int fd, const char *peername)
55: fd (fd), host (strdup (peername)), 57: fd (fd), host (strdup (peername)),
56 socket_ev (this, &client::socket_cb), 58 socket_ev (this, &client::socket_cb),
57 cmd_ev (this, &client::cmd_cb) 59 cmd_ev (this, &client::cmd_cb),
60 cc_inv (this), cc_other (this)
58{ 61{
59 { 62 {
60 struct linger linger_opt; 63 struct linger linger_opt;
61 64
62 linger_opt.l_onoff = 0; 65 linger_opt.l_onoff = 0;
63 linger_opt.l_linger = 0; 66 linger_opt.l_linger = 0;
64 67
65 if (setsockopt (fd, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof (struct linger))) 68 if (setsockopt (fd, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof (struct linger)))
66 LOG (llevError, "Cannot setsockopt(SO_LINGER): %s\n", strerror (errno)); 69 LOG (llevError, "SO_LINGER: %s\n", strerror (errno));
67 } 70 }
71
72 {
73 int val = IPTOS_LOWDELAY;
74
75 if (setsockopt (fd, IPPROTO_IP, IP_TOS, &val, sizeof (val)))
76 LOG (llevError, "IP_TOS: %s\n", strerror (errno));
77 }
78
79 {
80 int val = 1;
81
82 if (setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)))
83 LOG (llevError, "TCP_NODELAY: %s\n", strerror (errno));
84 }
85
86#ifdef __linux__
87 {
88 int val;
89
90 // set some very aggressive keepalive parameters
91 val = 10;
92 if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof (val)))
93 LOG (llevError, "TCP_KEEPIDLE: %s\n", strerror (errno));
94
95 val = 5;
96 if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof (val)))
97 LOG (llevError, "TCP_KEEPCNT: %s\n", strerror (errno));
98
99 val = 1;
100 if (setsockopt (fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof (val)))
101 LOG (llevError, "TCP_KEEPINTVL: %s\n", strerror (errno));
102 }
103#endif
68 104
69 { 105 {
70 int bufsize = 65535; /*Supposed absolute upper limit */ 106 int bufsize = 65535; /*Supposed absolute upper limit */
71 int oldbufsize; 107 int oldbufsize;
72 int buflen = sizeof (int); 108 int buflen = sizeof (int);
127 pl->socket = 0; 163 pl->socket = 0;
128 164
129 if (fd >= 0) 165 if (fd >= 0)
130 close (fd); 166 close (fd);
131 167
132 free (faces_sent); 168 sfree<uint8> (faces_sent, nrofpixmaps);
133 free (stats.range); 169 free (stats.range);
134 free (stats.title); 170 free (stats.title);
135 free (host); 171 free (host);
136} 172}
137 173

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines