Debian Codegraph @

src/FDTunnel.hpp

raw
1 // This class is a generic multiplexing tunnel
2 // that uses blocking select() to be as efficient as possible. It tunnels
3 // between the two supplied FDs.
4
5 // For all support, instructions and copyright go to:
6 // http://e2guardian.org/
7 // Released under the GPL v2, with the OpenSSL exception described in the README file.
8
9 #ifndef __HPP_FDTUNNEL
10 #define __HPP_FDTUNNEL
11
12 // INCLUDES
13
14 #include "Socket.hpp"
15 #include <fcntl.h>
16 #include <cstdbool>
17
18 // DECLARATIONS
19
20 // transparently forward data from one FD to another, i.e. tunnel between them
21 class FDTunnel
22 {
23 public:
24 off_t throughput; // used to log total data from from to to
25
26 FDTunnel();
27
28 // tunnel from fdfrom to fdto
29 // return false if throughput larger than target throughput (for post upload size checking)
30 bool tunnel(Socket &sockfrom, Socket &sockto, bool twoway = false, off_t targetthroughput = -1, bool ignore = false,
31 bool chunked = false);
32
33 void reset();
34
35 private:
36 struct pollfd fromoutfds[1];
37 struct pollfd tooutfds[1];
38 struct pollfd twayfds[2];
39 int timeout = 120000;
40 char sfbuff[32768]; // buffer for the input
41
42 bool nots2nots_tunnel(Socket &sockfrom, Socket &sockto, int &fdto, int &fdfrom, bool twoway, off_t targetthroughput,
43 bool ignore);
44 bool iss2nots_tunnel(Socket &sockfrom, Socket &sockto, int &fdto, int &fdfrom, bool twoway, off_t targetthroughput,
45 bool ignore);
46 bool iss2iss_tunnel(Socket &sockfrom, Socket &sockto, int &fdto, int &fdfrom, bool twoway, off_t targetthroughput,
47 bool ignore);
48 };
49
50 #endif