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.15 by root, Thu Dec 14 01:59:10 2006 UTC vs.
Revision 1.16 by root, Thu Dec 14 02:37:37 2006 UTC

51// easily die in 20 seconds... 51// easily die in 20 seconds...
52#define SOCKET_TIMEOUT1 10 52#define SOCKET_TIMEOUT1 10
53#define SOCKET_TIMEOUT2 20 53#define SOCKET_TIMEOUT2 20
54 54
55void 55void
56Socket_Flush (NewSocket * ns) 56Socket_Flush (client_socket * ns)
57{ 57{
58#ifdef __linux__ 58#ifdef __linux__
59 // check time of last ack, and, if too old, kill connection 59 // check time of last ack, and, if too old, kill connection
60 struct tcp_info tcpi; 60 struct tcp_info tcpi;
61 socklen_t len = sizeof (tcpi); 61 socklen_t len = sizeof (tcpi);
140 * Start of read routines. 140 * Start of read routines.
141 * 141 *
142 ******************************************************************************/ 142 ******************************************************************************/
143 143
144int 144int
145NewSocket::read_packet () 145client_socket::read_packet ()
146{ 146{
147 for (;;) 147 for (;;)
148 { 148 {
149 if (inbuf_len >= 2) 149 if (inbuf_len >= 2)
150 { 150 {
186 cst_lst.ibytes += amount; 186 cst_lst.ibytes += amount;
187 } 187 }
188} 188}
189 189
190void 190void
191NewSocket::skip_packet (int len) 191client_socket::skip_packet (int len)
192{ 192{
193 inbuf_len -= len; 193 inbuf_len -= len;
194 memmove (inbuf, inbuf + len, inbuf_len); 194 memmove (inbuf, inbuf + len, inbuf_len);
195} 195}
196 196
206 * ns is the socket we are adding the data to, buf is the start of the 206 * ns is the socket we are adding the data to, buf is the start of the
207 * data, and len is the number of bytes to add. 207 * data, and len is the number of bytes to add.
208 */ 208 */
209 209
210static void 210static void
211add_to_buffer (NewSocket *ns, char *buf, int len) 211add_to_buffer (client_socket *ns, char *buf, int len)
212{ 212{
213 int avail, end; 213 int avail, end;
214 214
215 if ((len + ns->outputbuffer.len) > SOCKETBUFSIZE) 215 if ((len + ns->outputbuffer.len) > SOCKETBUFSIZE)
216 { 216 {
250 * 250 *
251 * When the socket is clear to write, and we have backlogged data, this 251 * When the socket is clear to write, and we have backlogged data, this
252 * is called to write it out. 252 * is called to write it out.
253 */ 253 */
254void 254void
255write_socket_buffer (NewSocket * ns) 255write_socket_buffer (client_socket * ns)
256{ 256{
257 int amt, max; 257 int amt, max;
258 258
259 if (ns->outputbuffer.len == 0) 259 if (ns->outputbuffer.len == 0)
260 { 260 {
309 * provided (ns). buf is the data to write, len is the number 309 * provided (ns). buf is the data to write, len is the number
310 * of bytes to write. IT doesn't return anything - rather, it 310 * of bytes to write. IT doesn't return anything - rather, it
311 * updates the ns structure if we get an error. 311 * updates the ns structure if we get an error.
312 */ 312 */
313void 313void
314NewSocket::send (void *buf_, int len) 314client_socket::send (void *buf_, int len)
315{ 315{
316 char *buf = (char *)buf_; 316 char *buf = (char *)buf_;
317 char *pos = buf; 317 char *pos = buf;
318 int amt = 0; 318 int amt = 0;
319 319
376 * Takes a string of data, and writes it out to the socket. A very handy 376 * Takes a string of data, and writes it out to the socket. A very handy
377 * shortcut function. 377 * shortcut function.
378 */ 378 */
379 379
380void 380void
381NewSocket::send_packet (packet &sl) 381client_socket::send_packet (packet &sl)
382{ 382{
383 Send_With_Handling (this, &sl); 383 Send_With_Handling (this, &sl);
384} 384}
385 385
386void 386void
387NewSocket::send_packet (const char *buf, int len) 387client_socket::send_packet (const char *buf, int len)
388{ 388{
389 packet sl; 389 packet sl;
390 390
391 sl << data (buf, len); 391 sl << data (buf, len);
392 send_packet (sl); 392 send_packet (sl);
393} 393}
394 394
395void 395void
396NewSocket::send_packet (const char *buf) 396client_socket::send_packet (const char *buf)
397{ 397{
398 send_packet (buf, strlen (buf)); 398 send_packet (buf, strlen (buf));
399} 399}
400 400
401/** 401/**
403 * 403 *
404 * The only difference in this function is that we take a packet 404 * The only difference in this function is that we take a packet
405 *, and we prepend the length information. 405 *, and we prepend the length information.
406 */ 406 */
407void 407void
408Send_With_Handling (NewSocket *ns, packet *msg) 408Send_With_Handling (client_socket *ns, packet *msg)
409{ 409{
410 unsigned char sbuf[4]; 410 unsigned char sbuf[4];
411 411
412 if (ns->status == Ns_Dead || !msg) 412 if (ns->status == Ns_Dead || !msg)
413 return; 413 return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines