ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/vpn_tcp.C
(Generate patch)

Comparing gvpe/src/vpn_tcp.C (file contents):
Revision 1.19 by pcg, Tue Nov 13 02:12:08 2007 UTC vs.
Revision 1.21 by pcg, Sun Dec 2 00:39:06 2007 UTC

69 } 69 }
70 70
71} tcp_si; 71} tcp_si;
72 72
73struct tcp_connection : ev::io { 73struct tcp_connection : ev::io {
74 int tos;
74 tstamp last_activity; 75 tstamp last_activity;
75 const sockinfo si; 76 const sockinfo si;
76 vpn &v; 77 vpn &v;
77 bool active; // this connection has been actively established 78 bool active; // this connection has been actively established
78 enum { ERROR, IDLE, CONNECTING, CONNECTING_PROXY, ESTABLISHED } state; 79 enum { ERROR, IDLE, CONNECTING, CONNECTING_PROXY, ESTABLISHED } state;
104 ~tcp_connection (); 105 ~tcp_connection ();
105}; 106};
106 107
107void tcp_si_map::cleaner_cb (ev::timer &w, int revents) 108void tcp_si_map::cleaner_cb (ev::timer &w, int revents)
108{ 109{
109 tstamp to = ev::ev_now () - ::conf.keepalive - 30 - 60; 110 tstamp to = ev_now () - ::conf.keepalive - 30 - 60;
110 111
111 for (iterator i = begin (); i != end(); ) 112 for (iterator i = begin (); i != end(); )
112 if (i->second->last_activity >= to) 113 if (i->second->last_activity >= to)
113 ++i; 114 ++i;
114 else 115 else
201} 202}
202 203
203void 204void
204tcp_connection::tcpv4_ev (ev::io &w, int revents) 205tcp_connection::tcpv4_ev (ev::io &w, int revents)
205{ 206{
206 last_activity = ev::ev_now (); 207 last_activity = ev_now ();
207 208
208 if (revents & EV_WRITE) 209 if (revents & EV_WRITE)
209 { 210 {
210 if (state == CONNECTING) 211 if (state == CONNECTING)
211 { 212 {
346} 347}
347 348
348bool 349bool
349tcp_connection::send_packet (vpn_packet *pkt, int tos) 350tcp_connection::send_packet (vpn_packet *pkt, int tos)
350{ 351{
351 last_activity = ev::ev_now (); 352 last_activity = ev_now ();
352 353
353 if (state == IDLE) 354 if (state == IDLE)
354 { 355 {
355 // woaw, the first lost packet ;) 356 // woaw, the first lost packet ;)
356 fd = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP); 357 fd = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
409 if (!w_pkt) 410 if (!w_pkt)
410 { 411 {
411 // how this maps to the underlying tcp packets we don't know 412 // how this maps to the underlying tcp packets we don't know
412 // and we don't care. at least we tried ;) 413 // and we don't care. at least we tried ;)
413#if defined(SOL_IP) && defined(IP_TOS) 414#if defined(SOL_IP) && defined(IP_TOS)
415 if (tos != this->tos)
416 {
417 this->tos = tos;
414 setsockopt (fd, SOL_IP, IP_TOS, &tos, sizeof tos); 418 setsockopt (fd, SOL_IP, IP_TOS, &tos, sizeof tos);
419 }
415#endif 420#endif
416 421
417 w_pkt = pkt; 422 w_pkt = pkt;
418 w_ofs = 0; 423 w_ofs = 0;
419 w_len = pkt->len + 2; // length + size header 424 w_len = pkt->len + 2; // length + size header
438 stop (); 443 stop ();
439 444
440 if (fd >= 0) 445 if (fd >= 0)
441 { 446 {
442 close (fd); 447 close (fd);
448 tos = -1;
443 fd = -1; 449 fd = -1;
444 } 450 }
445 451
446 delete r_pkt; r_pkt = 0; 452 delete r_pkt; r_pkt = 0;
447 delete w_pkt; w_pkt = 0; 453 delete w_pkt; w_pkt = 0;
448#if ENABLE_HTTP_PROXY 454#if ENABLE_HTTP_PROXY
453} 459}
454 460
455tcp_connection::tcp_connection (int fd_, const sockinfo &si_, vpn &v_) 461tcp_connection::tcp_connection (int fd_, const sockinfo &si_, vpn &v_)
456: v(v_), si(si_), ev::io(this, &tcp_connection::tcpv4_ev) 462: v(v_), si(si_), ev::io(this, &tcp_connection::tcpv4_ev)
457{ 463{
458 last_activity = ev::ev_now (); 464 last_activity = ev_now ();
459 r_pkt = 0; 465 r_pkt = 0;
460 w_pkt = 0; 466 w_pkt = 0;
467 tos = -1;
461 fd = fd_; 468 fd = fd_;
462#if ENABLE_HTTP_PROXY 469#if ENABLE_HTTP_PROXY
463 proxy_req = 0; 470 proxy_req = 0;
464#endif 471#endif
465 472

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines