… | |
… | |
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 | |
55 | void |
55 | void |
56 | Socket_Flush (NewSocket * ns) |
56 | Socket_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 | |
144 | int |
144 | int |
145 | NewSocket::read_packet () |
145 | client_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 | |
190 | void |
190 | void |
191 | NewSocket::skip_packet (int len) |
191 | client_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 | |
210 | static void |
210 | static void |
211 | add_to_buffer (NewSocket *ns, char *buf, int len) |
211 | add_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 | */ |
254 | void |
254 | void |
255 | write_socket_buffer (NewSocket * ns) |
255 | write_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 | */ |
313 | void |
313 | void |
314 | NewSocket::send (void *buf_, int len) |
314 | client_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 | |
380 | void |
380 | void |
381 | NewSocket::send_packet (packet &sl) |
381 | client_socket::send_packet (packet &sl) |
382 | { |
382 | { |
383 | Send_With_Handling (this, &sl); |
383 | Send_With_Handling (this, &sl); |
384 | } |
384 | } |
385 | |
385 | |
386 | void |
386 | void |
387 | NewSocket::send_packet (const char *buf, int len) |
387 | client_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 | |
395 | void |
395 | void |
396 | NewSocket::send_packet (const char *buf) |
396 | client_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 | */ |
407 | void |
407 | void |
408 | Send_With_Handling (NewSocket *ns, packet *msg) |
408 | Send_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; |