… | |
… | |
75 | vpn_packet *r_pkt; |
75 | vpn_packet *r_pkt; |
76 | u32 r_len, r_ofs; |
76 | u32 r_len, r_ofs; |
77 | |
77 | |
78 | void tcpv4_ev (io_watcher &w, short revents); |
78 | void tcpv4_ev (io_watcher &w, short revents); |
79 | |
79 | |
80 | void send_packet (vpn_packet *pkt, int tos); |
80 | bool send_packet (vpn_packet *pkt, int tos); |
81 | |
81 | |
82 | void error (); // abort conenction && cleanup |
82 | void error (); // abort conenction && cleanup |
83 | |
83 | |
84 | operator tcp_si_map::value_type() |
84 | operator tcp_si_map::value_type() |
85 | { |
85 | { |
… | |
… | |
128 | tcp_si.insert (*i); |
128 | tcp_si.insert (*i); |
129 | } |
129 | } |
130 | } |
130 | } |
131 | } |
131 | } |
132 | |
132 | |
133 | void |
133 | bool |
134 | vpn::send_tcpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) |
134 | vpn::send_tcpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) |
135 | { |
135 | { |
136 | tcp_si_map::iterator info = tcp_si.find (&si); |
136 | tcp_si_map::iterator info = tcp_si.find (&si); |
137 | |
137 | |
138 | tcp_connection *i; |
138 | tcp_connection *i; |
… | |
… | |
143 | tcp_si.insert (*i); |
143 | tcp_si.insert (*i); |
144 | } |
144 | } |
145 | else |
145 | else |
146 | i = info->second; |
146 | i = info->second; |
147 | |
147 | |
148 | i->send_packet (pkt, tos); |
148 | return i->send_packet (pkt, tos); |
149 | } |
149 | } |
150 | |
150 | |
151 | void tcp_connection::error () |
151 | void tcp_connection::error () |
152 | { |
152 | { |
153 | if (fd >= 0) |
153 | if (fd >= 0) |
… | |
… | |
222 | return; |
222 | return; |
223 | } |
223 | } |
224 | } |
224 | } |
225 | } |
225 | } |
226 | |
226 | |
227 | void |
227 | bool |
228 | tcp_connection::send_packet (vpn_packet *pkt, int tos) |
228 | tcp_connection::send_packet (vpn_packet *pkt, int tos) |
229 | { |
229 | { |
230 | last_activity = NOW; |
230 | last_activity = NOW; |
231 | |
231 | |
232 | if (state == IDLE) |
232 | if (state == IDLE) |
… | |
… | |
267 | vec[1].iov_len = pkt->len; |
267 | vec[1].iov_len = pkt->len; |
268 | |
268 | |
269 | if (sizeof (u16) + pkt->len != writev (fd, vec, 2)) |
269 | if (sizeof (u16) + pkt->len != writev (fd, vec, 2)) |
270 | error (); |
270 | error (); |
271 | } |
271 | } |
|
|
272 | |
|
|
273 | return state != ERROR; |
272 | } |
274 | } |
273 | |
275 | |
274 | tcp_connection::tcp_connection (int fd_, const sockinfo &si_, vpn &v_) |
276 | tcp_connection::tcp_connection (int fd_, const sockinfo &si_, vpn &v_) |
275 | : v(v_), si(si_), io_watcher(this, &tcp_connection::tcpv4_ev) |
277 | : v(v_), si(si_), io_watcher(this, &tcp_connection::tcpv4_ev) |
276 | { |
278 | { |