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.12 by pcg, Thu Mar 3 16:54:34 2005 UTC vs.
Revision 1.16 by pcg, Sat Jul 9 02:49:06 2005 UTC

14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with gvpe; if not, write to the Free Software 18 along with gvpe; if not, write to the Free Software
19 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/ 20*/
21 21
22#include "config.h" 22#include "config.h"
23 23
24#if ENABLE_TCP 24#if ENABLE_TCP
61 61
62struct tcp_si_map : public map<const sockinfo *, tcp_connection *, lt_sockinfo> { 62struct tcp_si_map : public map<const sockinfo *, tcp_connection *, lt_sockinfo> {
63 void cleaner_cb (time_watcher &w); time_watcher cleaner; 63 void cleaner_cb (time_watcher &w); time_watcher cleaner;
64 64
65 tcp_si_map () 65 tcp_si_map ()
66 : cleaner(this, &tcp_si_map::cleaner_cb) 66 : cleaner(this, &tcp_si_map::cleaner_cb)
67 {
68 cleaner.start (0);
69 } 67 { }
68
70} tcp_si; 69} tcp_si;
71 70
72struct tcp_connection : io_watcher { 71struct tcp_connection : io_watcher {
73 tstamp last_activity; 72 tstamp last_activity;
74 const sockinfo si; 73 const sockinfo si;
93 bool write_packet (); 92 bool write_packet ();
94 93
95 void error (); // abort conenction && cleanup 94 void error (); // abort conenction && cleanup
96 95
97 operator tcp_si_map::value_type() 96 operator tcp_si_map::value_type()
98 { 97 {
99 return tcp_si_map::value_type (&si, this); 98 return tcp_si_map::value_type (&si, this);
100 } 99 }
101 100
102 tcp_connection (int fd_, const sockinfo &si_, vpn &v_); 101 tcp_connection (int fd_, const sockinfo &si_, vpn &v_);
103 ~tcp_connection (); 102 ~tcp_connection ();
104}; 103};
105 104
130 129
131 int fd = accept (w.fd, (sockaddr *)&sa, &sa_len); 130 int fd = accept (w.fd, (sockaddr *)&sa, &sa_len);
132 131
133 if (fd >= 0) 132 if (fd >= 0)
134 { 133 {
134 fcntl (fd, F_SETFL, O_NONBLOCK);
135 fcntl (fd, F_SETFD, FD_CLOEXEC);
136
135 sockinfo si(sa, PROT_TCPv4); 137 sockinfo si(sa, PROT_TCPv4);
136 138
137 slog (L_DEBUG, _("%s: accepted tcp connection"), (const char *)si);//D 139 slog (L_DEBUG, _("%s: accepted tcp connection"), (const char *)si);//D
138
139 fcntl (fd, F_SETFL, O_NONBLOCK);
140 140
141 tcp_connection *i = new tcp_connection (fd, si, *this); 141 tcp_connection *i = new tcp_connection (fd, si, *this);
142 tcp_si.insert (*i); 142 tcp_si.insert (*i);
143 } 143 }
144 } 144 }
389 fcntl (fd, F_SETFL, O_NONBLOCK); 389 fcntl (fd, F_SETFL, O_NONBLOCK);
390 390
391 if (connect (fd, csi->sav4 (), csi->salenv4 ()) >= 0 391 if (connect (fd, csi->sav4 (), csi->salenv4 ()) >= 0
392 || errno == EINPROGRESS) 392 || errno == EINPROGRESS)
393 { 393 {
394 fcntl (fd, F_SETFL, O_NONBLOCK);
395 fcntl (fd, F_SETFD, FD_CLOEXEC);
396
394 state = CONNECTING; 397 state = CONNECTING;
395 start (fd, EVENT_WRITE); 398 start (fd, EVENT_WRITE);
396 } 399 }
397 else 400 else
398 close (fd); 401 close (fd);
448} 451}
449 452
450tcp_connection::tcp_connection (int fd_, const sockinfo &si_, vpn &v_) 453tcp_connection::tcp_connection (int fd_, const sockinfo &si_, vpn &v_)
451: v(v_), si(si_), io_watcher(this, &tcp_connection::tcpv4_ev) 454: v(v_), si(si_), io_watcher(this, &tcp_connection::tcpv4_ev)
452{ 455{
456 if (!tcp_si.cleaner.active)
457 tcp_si.cleaner.start (0);
458
453 last_activity = NOW; 459 last_activity = NOW;
454 r_pkt = 0; 460 r_pkt = 0;
455 w_pkt = 0; 461 w_pkt = 0;
456 fd = fd_; 462 fd = fd_;
457#if ENABLE_HTTP_PROXY 463#if ENABLE_HTTP_PROXY

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines