]> git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/ConnOpener.h
Merge from trunk
[thirdparty/squid.git] / src / comm / ConnOpener.h
1 #ifndef _SQUID_SRC_COMM_OPENERSTATEDATA_H
2 #define _SQUID_SRC_COMM_OPENERSTATEDATA_H
3
4 #include "base/AsyncCall.h"
5 #include "base/AsyncJob.h"
6 #include "cbdata.h"
7 #include "comm/comm_err_t.h"
8 #include "comm/forward.h"
9
10 /**
11 * Async-opener of a Comm connection.
12 */
13 class ConnOpener : public AsyncJob
14 {
15 public:
16 /** attempt to open a connection. */
17 ConnOpener(Comm::ConnectionPointer &, AsyncCall::Pointer handler);
18
19 ~ConnOpener();
20
21 /** Actual start opening a TCP connection. */
22 void start();
23
24 private:
25 /* These objects may NOT be created without connections to act on. Do not define this operator. */
26 ConnOpener(const ConnOpener &);
27 /* These objects may NOT be copied. Do not define this operator. */
28 ConnOpener operator =(const ConnOpener &c);
29
30 /**
31 * Wrapper to start the connection attempts happening.
32 */
33 static void Connect(void *data);
34
35 /** retry */
36 static void ConnectRetry(int fd, void *data);
37
38 /**
39 * Temporary close handler used during connect.
40 * Handles the case(s) when a partially setup connection gets closed early.
41 */
42 static void EarlyAbort(int fd, void *data);
43
44 /**
45 * Temporary timeout handler used during connect.
46 * Handles the case(s) when a partially setup connection gets timed out.
47 */
48 static void ConnectTimeout(int fd, void *data);
49
50 /**
51 * Connection attempt are completed. One way or the other.
52 * Pass the results back to the external handler.
53 */
54 void callCallback(comm_err_t status, int xerrno);
55
56 public:
57 /**
58 * time at which to abandon the connection.
59 * the connection-done callback will be passed COMM_TIMEOUT
60 */
61 time_t connect_timeout;
62
63 void setHost(const char *); ///< set the hostname note for this connection
64 const char * getHost(void) const; ///< get the hostname noted for this connection
65
66 private:
67 char *host; ///< domain name we are trying to connect to.
68
69 Comm::ConnectionPointer solo; ///< single connection currently being opened.
70 AsyncCall::Pointer callback; ///< handler to be called on connection completion.
71
72 int total_tries; ///< total number of connection attempts over all destinations so far.
73 int fail_retries; ///< number of retries current destination has been tried.
74 time_t connstart; ///< time at which this series of connection attempts was started.
75
76 CBDATA_CLASS2(ConnOpener);
77 };
78
79 #endif /* _SQUID_SRC_COMM_CONNOPENER_H */