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.13 by root, Thu Dec 14 01:12:35 2006 UTC vs.
Revision 1.14 by root, Thu Dec 14 01:21:58 2006 UTC

80#endif 80#endif
81} 81}
82 82
83/*********************************************************************** 83/***********************************************************************
84 * 84 *
85 * SockList functions/utilities 85 * packet functions/utilities
86 * 86 *
87 **********************************************************************/ 87 **********************************************************************/
88 88
89SockList &SockList::operator <<(const data &v) 89packet &packet::operator <<(const data &v)
90{ 90{
91 if (v.len) 91 if (v.len)
92 { 92 {
93 memcpy (buf + len, v.ptr, v.len); 93 memcpy (buf + len, v.ptr, v.len);
94 len += v.len; 94 len += v.len;
95 } 95 }
96 96
97 return *this; 97 return *this;
98} 98}
99 99
100SockList &SockList::operator <<(const data8 &v) 100packet &packet::operator <<(const data8 &v)
101{ 101{
102 unsigned int len = min (v.len, 0x00FF); 102 unsigned int len = min (v.len, 0x00FF);
103 return *this << uint8 (len) << data (v.ptr, len); 103 return *this << uint8 (len) << data (v.ptr, len);
104} 104}
105 105
106SockList &SockList::operator <<(const data16 &v) 106packet &packet::operator <<(const data16 &v)
107{ 107{
108 unsigned int len = min (v.len, 0xFFFF); 108 unsigned int len = min (v.len, 0xFFFF);
109 return *this << uint16 (len) << data (v.ptr, len); 109 return *this << uint16 (len) << data (v.ptr, len);
110} 110}
111 111
112SockList &SockList::operator <<(const char *v) 112packet &packet::operator <<(const char *v)
113{ 113{
114 return *this << data (v, strlen (v ? v : 0)); 114 return *this << data (v, strlen (v ? v : 0));
115} 115}
116 116
117void 117void
118SockList::printf (const char *format, ...) 118packet::printf (const char *format, ...)
119{ 119{
120 va_list ap; 120 va_list ap;
121 va_start (ap, format); 121 va_start (ap, format);
122 122
123 len += vsnprintf ((char *)buf + len, MAXSOCKBUF, format, ap); 123 len += vsnprintf ((char *)buf + len, MAXSOCKBUF, format, ap);
366 * Takes a string of data, and writes it out to the socket. A very handy 366 * Takes a string of data, and writes it out to the socket. A very handy
367 * shortcut function. 367 * shortcut function.
368 */ 368 */
369 369
370void 370void
371NewSocket::send_packet (SockList &sl) 371NewSocket::send_packet (packet &sl)
372{ 372{
373 Send_With_Handling (this, &sl); 373 Send_With_Handling (this, &sl);
374} 374}
375 375
376void 376void
377NewSocket::send_packet (const char *buf, int len) 377NewSocket::send_packet (const char *buf, int len)
378{ 378{
379 SockList sl (MAXSOCKBUF); 379 packet sl;
380 380
381 sl << data (buf, len); 381 sl << data (buf, len);
382 send_packet (sl); 382 send_packet (sl);
383 sl.free ();
384} 383}
385 384
386void 385void
387NewSocket::send_packet (const char *buf) 386NewSocket::send_packet (const char *buf)
388{ 387{
390} 389}
391 390
392/** 391/**
393 * Calls Write_To_Socket to send data to the client. 392 * Calls Write_To_Socket to send data to the client.
394 * 393 *
395 * The only difference in this function is that we take a SockList 394 * The only difference in this function is that we take a packet
396 *, and we prepend the length information. 395 *, and we prepend the length information.
397 */ 396 */
398void 397void
399Send_With_Handling (NewSocket *ns, SockList *msg) 398Send_With_Handling (NewSocket *ns, packet *msg)
400{ 399{
401 unsigned char sbuf[4]; 400 unsigned char sbuf[4];
402 401
403 if (ns->status == Ns_Dead || !msg) 402 if (ns->status == Ns_Dead || !msg)
404 return; 403 return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines