]> git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/ConnOpener.h
SourceFormat Enforcement
[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/forward.h"
8 #include "comm_err_t.h"
9 #include "CommCalls.h"
10
11 namespace Comm
12 {
13
14 /**
15 * Async-opener of a Comm connection.
16 */
17 class ConnOpener : public AsyncJob
18 {
19 protected:
20 virtual void start();
21 virtual void swanSong();
22
23 public:
24 void noteAbort() { mustStop("externally aborted"); }
25
26 typedef CbcPointer<ConnOpener> Pointer;
27
28 virtual bool doneAll() const;
29
30 ConnOpener(Comm::ConnectionPointer &, AsyncCall::Pointer &handler, time_t connect_timeout);
31 ~ConnOpener();
32
33 void setHost(const char *); ///< set the hostname note for this connection
34 const char * getHost() const; ///< get the hostname noted for this connection
35
36 private:
37 // Undefined because two openers cannot share a connection
38 ConnOpener(const ConnOpener &);
39 ConnOpener & operator =(const ConnOpener &c);
40
41 void earlyAbort(const CommCloseCbParams &);
42 void timeout(const CommTimeoutCbParams &);
43 void sendAnswer(comm_err_t errFlag, int xerrno, const char *why);
44 static void InProgressConnectRetry(int fd, void *data);
45 static void DelayedConnectRetry(void *data);
46 void connect();
47 void connected();
48 void lookupLocalAddress();
49
50 void retrySleep();
51 void restart();
52
53 bool createFd();
54 void closeFd();
55 void keepFd();
56 void cleanFd();
57
58 void cancelSleep();
59
60 private:
61 char *host_; ///< domain name we are trying to connect to.
62 int temporaryFd_; ///< the FD being opened. Do NOT set conn_->fd until it is fully open.
63 Comm::ConnectionPointer conn_; ///< single connection currently to be opened.
64 AsyncCall::Pointer callback_; ///< handler to be called on connection completion.
65
66 int totalTries_; ///< total number of connection attempts over all destinations so far.
67 int failRetries_; ///< number of retries current destination has been tried.
68
69 /// if we are not done by then, we will call back with COMM_TIMEOUT
70 time_t deadline_;
71
72 /// handles to calls which we may need to cancel.
73 struct Calls {
74 AsyncCall::Pointer earlyAbort_;
75 AsyncCall::Pointer timeout_;
76 /// Whether we are idling before retrying to connect; not yet a call
77 /// [that we can cancel], but it will probably become one eventually.
78 bool sleep_;
79 } calls_;
80
81 CBDATA_CLASS2(ConnOpener);
82 };
83
84 }; // namespace Comm
85
86 #endif /* _SQUID_SRC_COMM_CONNOPENER_H */