]> git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/ConnOpener.h
Add ConnOpener to Comm namespace
[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 "CommCalls.h"
8 #include "comm/comm_err_t.h"
9 #include "comm/forward.h"
10
11 namespace Comm {
12
13 /**
14 * Async-opener of a Comm connection.
15 */
16 class ConnOpener : public AsyncJob
17 {
18 public:
19 // ****** AsynJob API implementation ******
20
21 /** Actual start opening a TCP connection. */
22 void start();
23
24 virtual bool doneAll() const;
25 virtual void swanSong();
26
27 public:
28 // ****** ConnOpener API iplementation ******
29
30 /** attempt to open a connection. */
31 ConnOpener(Comm::ConnectionPointer &, AsyncCall::Pointer &handler, time_t connect_timeout);
32 ~ConnOpener();
33
34 void setHost(const char *); ///< set the hostname note for this connection
35 const char * getHost() const; ///< get the hostname noted for this connection
36
37 private:
38 /* These objects may NOT be created without connections to act on. Do not define this operator. */
39 ConnOpener(const ConnOpener &);
40 /* These objects may NOT be copied. Do not define this operator. */
41 ConnOpener operator =(const ConnOpener &c);
42
43 /** Make an FD connection attempt.
44 * Handles the case(s) when a partially setup connection gets closed early.
45 */
46 void connect(const CommConnectCbParams &unused);
47
48 /** Abort connection attempt.
49 * Handles the case(s) when a partially setup connection gets closed early.
50 */
51 void earlyAbort(const CommConnectCbParams &);
52
53 /**
54 * Handles the case(s) when a partially setup connection gets timed out.
55 * NP: When commSetTimeout accepts generic CommCommonCbParams this can die.
56 */
57 void timeout(const CommTimeoutCbParams &unused);
58
59 /**
60 * Connection attempt are completed. One way or the other.
61 * Pass the results back to the external handler.
62 */
63 void callCallback(comm_err_t status, int xerrno);
64
65 // Legacy Wrapper for the retry event after COMM_INPROGRESS
66 // As soon as comm IO accepts Async calls we can use a ConnOpener::connect call
67 static void ConnectRetry(int fd, void *data);
68
69 private:
70 /**
71 * time at which to abandon the connection.
72 * the connection-done callback will be passed COMM_TIMEOUT
73 */
74 time_t connect_timeout;
75
76 char *host; ///< domain name we are trying to connect to.
77
78 Comm::ConnectionPointer solo; ///< single connection currently being opened.
79 AsyncCall::Pointer callback; ///< handler to be called on connection completion.
80
81 int total_tries; ///< total number of connection attempts over all destinations so far.
82 int fail_retries; ///< number of retries current destination has been tried.
83 time_t connstart; ///< time at which this series of connection attempts was started.
84
85 /// handles to calls which we may need to cancel.
86 struct _calls {
87 AsyncCall::Pointer earlyabort;
88 AsyncCall::Pointer timeout;
89 } calls;
90
91 CBDATA_CLASS2(ConnOpener);
92 };
93
94 }; // namespace Comm
95
96 #endif /* _SQUID_SRC_COMM_CONNOPENER_H */