--- gvpe/src/vpn_tcp.C 2007/11/13 02:12:08 1.19 +++ gvpe/src/vpn_tcp.C 2007/12/12 00:17:13 1.25 @@ -59,18 +59,22 @@ } }; -struct tcp_si_map : public map { - void cleaner_cb (ev::timer &w, int revents); ev::timer cleaner; +struct tcp_si_map : public map +{ + inline void cleaner_cb (ev::timer &w, int revents); ev::timer cleaner; tcp_si_map () - : cleaner(this, &tcp_si_map::cleaner_cb) { + ev_default_loop (0); + cleaner.set (this); cleaner.start (::conf.keepalive / 2, ::conf.keepalive / 2); } } tcp_si; -struct tcp_connection : ev::io { +struct tcp_connection : ev::io +{ + int tos; tstamp last_activity; const sockinfo si; vpn &v; @@ -88,7 +92,7 @@ int proxy_req_len; #endif - void tcpv4_ev (ev::io &w, int revents); + inline void tcpv4_ev (ev::io &w, int revents); bool send_packet (vpn_packet *pkt, int tos); bool write_packet (); @@ -106,7 +110,7 @@ void tcp_si_map::cleaner_cb (ev::timer &w, int revents) { - tstamp to = ev::ev_now () - ::conf.keepalive - 30 - 60; + tstamp to = ev_now () - ::conf.keepalive - 30 - 60; for (iterator i = begin (); i != end(); ) if (i->second->last_activity >= to) @@ -203,7 +207,7 @@ void tcp_connection::tcpv4_ev (ev::io &w, int revents) { - last_activity = ev::ev_now (); + last_activity = ev_now (); if (revents & EV_WRITE) { @@ -348,7 +352,7 @@ bool tcp_connection::send_packet (vpn_packet *pkt, int tos) { - last_activity = ev::ev_now (); + last_activity = ev_now (); if (state == IDLE) { @@ -411,7 +415,11 @@ // how this maps to the underlying tcp packets we don't know // and we don't care. at least we tried ;) #if defined(SOL_IP) && defined(IP_TOS) - setsockopt (fd, SOL_IP, IP_TOS, &tos, sizeof tos); + if (tos != this->tos) + { + this->tos = tos; + setsockopt (fd, SOL_IP, IP_TOS, &tos, sizeof tos); + } #endif w_pkt = pkt; @@ -440,7 +448,8 @@ if (fd >= 0) { close (fd); - fd = -1; + tos = -1; + fd = -1; } delete r_pkt; r_pkt = 0; @@ -453,11 +462,14 @@ } tcp_connection::tcp_connection (int fd_, const sockinfo &si_, vpn &v_) -: v(v_), si(si_), ev::io(this, &tcp_connection::tcpv4_ev) +: v(v_), si(si_) { - last_activity = ev::ev_now (); + set (this); + + last_activity = ev_now (); r_pkt = 0; w_pkt = 0; + tos = -1; fd = fd_; #if ENABLE_HTTP_PROXY proxy_req = 0;