… | |
… | |
33 | */ |
33 | */ |
34 | |
34 | |
35 | using namespace std; |
35 | using 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 | |
55 | void |
54 | void |
56 | client_socket::flush () |
55 | client::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 | |
93 | void |
92 | void |
94 | client_socket::write_outputbuffer () |
93 | client::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 | |
203 | int |
202 | int |
204 | client_socket::read_packet () |
203 | client::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 | |
249 | void |
248 | void |
250 | client_socket::skip_packet (int len) |
249 | client::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 | */ |
268 | void |
267 | void |
269 | client_socket::send (void *buf_, int len) |
268 | client::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 | |
312 | void |
311 | void |
313 | client_socket::socket_cb (iow &w, int got) |
312 | client::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 | */ |
325 | void |
324 | void |
326 | client_socket::send_packet (packet &sl) |
325 | client::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 | |
351 | void |
350 | void |
352 | client_socket::send_packet (const char *buf, int len) |
351 | client::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 | |
360 | void |
359 | void |
361 | client_socket::send_packet (const char *buf) |
360 | client::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 | /****************************************************************************** |