… | |
… | |
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 | |
89 | SockList &SockList::operator <<(const data &v) |
89 | packet &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 | |
100 | SockList &SockList::operator <<(const data8 &v) |
100 | packet &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 | |
106 | SockList &SockList::operator <<(const data16 &v) |
106 | packet &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 | |
112 | SockList &SockList::operator <<(const char *v) |
112 | packet &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 | |
117 | void |
117 | void |
118 | SockList::printf (const char *format, ...) |
118 | packet::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 | |
370 | void |
370 | void |
371 | NewSocket::send_packet (SockList &sl) |
371 | NewSocket::send_packet (packet &sl) |
372 | { |
372 | { |
373 | Send_With_Handling (this, &sl); |
373 | Send_With_Handling (this, &sl); |
374 | } |
374 | } |
375 | |
375 | |
376 | void |
376 | void |
377 | NewSocket::send_packet (const char *buf, int len) |
377 | NewSocket::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 | |
386 | void |
385 | void |
387 | NewSocket::send_packet (const char *buf) |
386 | NewSocket::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 | */ |
398 | void |
397 | void |
399 | Send_With_Handling (NewSocket *ns, SockList *msg) |
398 | Send_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; |