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.21 by root, Fri Dec 15 00:14:13 2006 UTC vs.
Revision 1.22 by root, Fri Dec 15 19:59:20 2006 UTC

33 */ 33 */
34 34
35using namespace std; 35using namespace std;
36 36
37#include <global.h> 37#include <global.h>
38#include <newclient.h>
39#include <sproto.h> 38#include <sproto.h>
40#include <cstdarg> 39#include <cstdarg>
41 40
42#ifdef __linux__ 41#ifdef __linux__
43# include <sys/types.h> 42# include <sys/types.h>
51// easily die in 20 seconds... 50// easily die in 20 seconds...
52#define SOCKET_TIMEOUT1 10 51#define SOCKET_TIMEOUT1 10
53#define SOCKET_TIMEOUT2 20 52#define SOCKET_TIMEOUT2 20
54 53
55void 54void
56client_socket::flush () 55client::flush ()
57{ 56{
58#ifdef __linux__ 57#ifdef __linux__
59 // check time of last ack, and, if too old, kill connection 58 // check time of last ack, and, if too old, kill connection
60 struct tcp_info tcpi; 59 struct tcp_info tcpi;
61 socklen_t len = sizeof (tcpi); 60 socklen_t len = sizeof (tcpi);
89 88
90 write_outputbuffer (); 89 write_outputbuffer ();
91} 90}
92 91
93void 92void
94client_socket::write_outputbuffer () 93client::write_outputbuffer ()
95{ 94{
96 while (outputbuffer.len) 95 while (outputbuffer.len)
97 { 96 {
98 int res = write (fd, outputbuffer.data + outputbuffer.start, 97 int res = write (fd, outputbuffer.data + outputbuffer.start,
99 min (outputbuffer.len, SOCKETBUFSIZE - outputbuffer.start)); 98 min (outputbuffer.len, SOCKETBUFSIZE - outputbuffer.start));
199 * Start of read routines. 198 * Start of read routines.
200 * 199 *
201 ******************************************************************************/ 200 ******************************************************************************/
202 201
203int 202int
204client_socket::read_packet () 203client::read_packet ()
205{ 204{
206 for (;;) 205 for (;;)
207 { 206 {
208 if (inbuf_len >= 2) 207 if (inbuf_len >= 2)
209 { 208 {
245 cst_lst.ibytes += amount; 244 cst_lst.ibytes += amount;
246 } 245 }
247} 246}
248 247
249void 248void
250client_socket::skip_packet (int len) 249client::skip_packet (int len)
251{ 250{
252 inbuf_len -= len; 251 inbuf_len -= len;
253 memmove (inbuf, inbuf + len, inbuf_len); 252 memmove (inbuf, inbuf + len, inbuf_len);
254} 253}
255 254
264 * 263 *
265 * ns is the socket we are adding the data to, buf is the start of the 264 * ns is the socket we are adding the data to, buf is the start of the
266 * data, and len is the number of bytes to add. 265 * data, and len is the number of bytes to add.
267 */ 266 */
268void 267void
269client_socket::send (void *buf_, int len) 268client::send (void *buf_, int len)
270{ 269{
271 char *buf = (char *)buf_; 270 char *buf = (char *)buf_;
272 char *pos = buf; 271 char *pos = buf;
273 int amt = 0; 272 int amt = 0;
274 273
308 307
309 outputbuffer.len += len; 308 outputbuffer.len += len;
310} 309}
311 310
312void 311void
313client_socket::socket_cb (iow &w, int got) 312client::socket_cb (iow &w, int got)
314{ 313{
315 write_outputbuffer (); 314 write_outputbuffer ();
316 315
317 if (!outputbuffer.len) 316 if (!outputbuffer.len)
318 socket_ev.poll (socket_ev.poll () & ~PE_W); 317 socket_ev.poll (socket_ev.poll () & ~PE_W);
321/** 320/**
322 * Takes a string of data, and writes it out to the socket. A very handy 321 * Takes a string of data, and writes it out to the socket. A very handy
323 * shortcut function. 322 * shortcut function.
324 */ 323 */
325void 324void
326client_socket::send_packet (packet &sl) 325client::send_packet (packet &sl)
327{ 326{
328 if (status == Ns_Dead) 327 if (status == Ns_Dead)
329 return; 328 return;
330 329
331 if (sl.length () >= MAXSOCKBUF) 330 if (sl.length () >= MAXSOCKBUF)
347 346
348 send (sl.buf_, sl.length () + sl.hdrlen); 347 send (sl.buf_, sl.length () + sl.hdrlen);
349} 348}
350 349
351void 350void
352client_socket::send_packet (const char *buf, int len) 351client::send_packet (const char *buf, int len)
353{ 352{
354 packet sl; 353 packet sl;
355 354
356 sl << data (buf, len); 355 sl << data (buf, len);
357 send_packet (sl); 356 send_packet (sl);
358} 357}
359 358
360void 359void
361client_socket::send_packet (const char *buf) 360client::send_packet (const char *buf)
362{ 361{
363 send_packet (buf, strlen (buf)); 362 send_packet (buf, strlen (buf));
364} 363}
365 364
366/****************************************************************************** 365/******************************************************************************

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines