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.10 by pcg, Thu Oct 16 02:41:21 2003 UTC vs.
Revision 1.11 by pcg, Sat Jan 17 01:18:36 2004 UTC

1/* 1/*
2 vpn_tcp.C -- handle the tcp part of the protocol. 2 vpn_tcp.C -- handle the tcp part of the protocol.
3 Copyright (C) 2003 Marc Lehmann <pcg@goof.com> 3 Copyright (C) 2003-2004 Marc Lehmann <pcg@goof.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
101 ~tcp_connection (); 101 ~tcp_connection ();
102}; 102};
103 103
104void tcp_si_map::cleaner_cb (time_watcher &w) 104void tcp_si_map::cleaner_cb (time_watcher &w)
105{ 105{
106 w.at = NOW + 600; 106 w.start (NOW + 600);
107
107 tstamp to = NOW - ::conf.keepalive - 30 - 60; 108 tstamp to = NOW - ::conf.keepalive - 30 - 60;
108 109
109 for (iterator i = begin (); i != end(); ) 110 for (iterator i = begin (); i != end(); )
110 if (i->second->last_activity >= to) 111 if (i->second->last_activity >= to)
111 ++i; 112 ++i;
117} 118}
118 119
119void 120void
120vpn::tcpv4_ev (io_watcher &w, short revents) 121vpn::tcpv4_ev (io_watcher &w, short revents)
121{ 122{
122 if (revents & (POLLIN | POLLERR)) 123 if (revents & EVENT_READ)
123 { 124 {
124 struct sockaddr_in sa; 125 struct sockaddr_in sa;
125 socklen_t sa_len = sizeof (sa); 126 socklen_t sa_len = sizeof (sa);
126 int len; 127 int len;
127 128
199void 200void
200tcp_connection::tcpv4_ev (io_watcher &w, short revents) 201tcp_connection::tcpv4_ev (io_watcher &w, short revents)
201{ 202{
202 last_activity = NOW; 203 last_activity = NOW;
203 204
204 if (revents & (POLLERR | POLLHUP)) 205 if (revents & EVENT_WRITE)
205 {
206 error ();
207 return;
208 }
209
210 if (revents & POLLOUT)
211 { 206 {
212 if (state == CONNECTING) 207 if (state == CONNECTING)
213 { 208 {
214 state = ESTABLISHED; 209 state = ESTABLISHED;
215 set (POLLIN); 210 set (EVENT_READ);
216#if ENABLE_HTTP_PROXY 211#if ENABLE_HTTP_PROXY
217 if (::conf.proxy_host && ::conf.proxy_port) 212 if (::conf.proxy_host && ::conf.proxy_port)
218 { 213 {
219 state = CONNECTING_PROXY; 214 state = CONNECTING_PROXY;
215
220 write (fd, proxy_req, proxy_req_len); 216 if (write (fd, proxy_req, proxy_req_len) == 0)
217 {
218 error ();
219 return;
220 }
221
221 free (proxy_req); proxy_req = 0; 222 free (proxy_req); proxy_req = 0;
222 } 223 }
223#endif 224#endif
224 } 225 }
225 else if (state == ESTABLISHED) 226 else if (state == ESTABLISHED)
228 { 229 {
229 if (write_packet ()) 230 if (write_packet ())
230 { 231 {
231 delete w_pkt; w_pkt = 0; 232 delete w_pkt; w_pkt = 0;
232 233
233 set (POLLIN); 234 set (EVENT_READ);
234 } 235 }
235 } 236 }
236 else 237 else
237 set (POLLIN); 238 set (EVENT_READ);
238 } 239 }
239 else 240 else
240 set (POLLIN); 241 set (EVENT_READ);
241 } 242 }
242 243
243 if (revents & POLLIN) 244 if (revents & EVENT_READ)
244 { 245 {
245 if (state == ESTABLISHED) 246 if (state == ESTABLISHED)
246 for (;;) 247 for (;;)
247 { 248 {
248 if (!r_pkt) 249 if (!r_pkt)
282 break; 283 break;
283 } 284 }
284 else if (len < 0 && (errno == EINTR || errno == EAGAIN)) 285 else if (len < 0 && (errno == EINTR || errno == EAGAIN))
285 break; 286 break;
286 287
288 // len == 0 <-> EOF
287 error (); 289 error ();
288 break; 290 break;
289 } 291 }
290#if ENABLE_HTTP_PROXY 292#if ENABLE_HTTP_PROXY
291 else if (state == CONNECTING_PROXY) 293 else if (state == CONNECTING_PROXY)
386 388
387 if (connect (fd, csi->sav4 (), csi->salenv4 ()) >= 0 389 if (connect (fd, csi->sav4 (), csi->salenv4 ()) >= 0
388 || errno == EINPROGRESS) 390 || errno == EINPROGRESS)
389 { 391 {
390 state = CONNECTING; 392 state = CONNECTING;
391 start (fd, POLLOUT); 393 start (fd, EVENT_WRITE);
392 } 394 }
393 else 395 else
394 close (fd); 396 close (fd);
395 } 397 }
396 } 398 }
415 else 417 else
416 { 418 {
417 w_pkt = new vpn_packet; 419 w_pkt = new vpn_packet;
418 w_pkt->set (*pkt); 420 w_pkt->set (*pkt);
419 421
420 set (POLLIN | POLLOUT); 422 set (EVENT_READ | EVENT_WRITE);
421 } 423 }
422 } 424 }
423 } 425 }
424 426
425 return state != ERROR; 427 return state != ERROR;
461 } 463 }
462 else 464 else
463 { 465 {
464 active = false; 466 active = false;
465 state = ESTABLISHED; 467 state = ESTABLISHED;
466 start (fd, POLLIN); 468 start (fd, EVENT_READ);
467 } 469 }
468} 470}
469 471
470tcp_connection::~tcp_connection () 472tcp_connection::~tcp_connection ()
471{ 473{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines