--- gvpe/src/vpn_tcp.C 2003/04/07 01:12:56 1.4 +++ gvpe/src/vpn_tcp.C 2004/01/17 01:18:36 1.11 @@ -1,5 +1,6 @@ /* vpn_tcp.C -- handle the tcp part of the protocol. + Copyright (C) 2003-2004 Marc Lehmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,19 +30,16 @@ #include #include -#include #include -#include #include -#include #include #include #include +#include #include -#include -#include -#include + +#include "netcompat.h" #include "vpn.h" @@ -105,7 +103,8 @@ void tcp_si_map::cleaner_cb (time_watcher &w) { - w.at = NOW + 600; + w.start (NOW + 600); + tstamp to = NOW - ::conf.keepalive - 30 - 60; for (iterator i = begin (); i != end(); ) @@ -121,7 +120,7 @@ void vpn::tcpv4_ev (io_watcher &w, short revents) { - if (revents & (POLLIN | POLLERR)) + if (revents & EVENT_READ) { struct sockaddr_in sa; socklen_t sa_len = sizeof (sa); @@ -171,9 +170,10 @@ u16 plen = htons (w_pkt->len); iovec vec[2]; - vec[0].iov_base = ((u8 *)&plen) + w_ofs; + //TODO: char* is the right type? hardly... + vec[0].iov_base = (char *)((u8 *)&plen) + w_ofs; vec[0].iov_len = 2 - w_ofs; - vec[1].iov_base = &((*w_pkt)[0]); + vec[1].iov_base = (char *)&((*w_pkt)[0]); vec[1].iov_len = w_len - 2; len = writev (fd, vec, 2); @@ -202,23 +202,23 @@ { last_activity = NOW; - if (revents & (POLLERR | POLLHUP)) - { - error (); - return; - } - - if (revents & POLLOUT) + if (revents & EVENT_WRITE) { if (state == CONNECTING) { state = ESTABLISHED; - set (POLLIN); + set (EVENT_READ); #if ENABLE_HTTP_PROXY if (::conf.proxy_host && ::conf.proxy_port) { state = CONNECTING_PROXY; - write (fd, proxy_req, proxy_req_len); + + if (write (fd, proxy_req, proxy_req_len) == 0) + { + error (); + return; + } + free (proxy_req); proxy_req = 0; } #endif @@ -231,17 +231,17 @@ { delete w_pkt; w_pkt = 0; - set (POLLIN); + set (EVENT_READ); } } else - set (POLLIN); + set (EVENT_READ); } else - set (POLLIN); + set (EVENT_READ); } - if (revents & POLLIN) + if (revents & EVENT_READ) { if (state == ESTABLISHED) for (;;) @@ -285,6 +285,7 @@ else if (len < 0 && (errno == EINTR || errno == EAGAIN)) break; + // len == 0 <-> EOF error (); break; } @@ -322,14 +323,16 @@ if (i < 12) { - slog (L_ERR, _("unable to do proxy-forwarding, short response")); + slog (L_ERR, _("(%s): unable to do proxy-forwarding, short response"), + (const char *)si); error (); } else if (r[0] != 'H' || r[1] != 'T' || r[2] != 'T' || r[3] != 'P' || r[4] != '/' || r[5] != '1' // http-major || r[9] != '2') // response { - slog (L_ERR, _("malformed or unexpected proxy response (%.12s)"), r); + slog (L_ERR, _("(%s): malformed or unexpected proxy response (%.12s)"), + (const char *)si, r); error (); } else @@ -387,7 +390,7 @@ || errno == EINPROGRESS) { state = CONNECTING; - start (fd, POLLOUT); + start (fd, EVENT_WRITE); } else close (fd); @@ -401,7 +404,9 @@ { // 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); +#endif w_pkt = pkt; w_ofs = 0; @@ -414,7 +419,7 @@ w_pkt = new vpn_packet; w_pkt->set (*pkt); - set (POLLIN | POLLOUT); + set (EVENT_READ | EVENT_WRITE); } } } @@ -460,7 +465,7 @@ { active = false; state = ESTABLISHED; - start (fd, POLLIN); + start (fd, EVENT_READ); } }