]>
Commit | Line | Data |
---|---|---|
aed188fd AJ |
1 | #ifndef _SQUID_SRC_COMM_OPENERSTATEDATA_H |
2 | #define _SQUID_SRC_COMM_OPENERSTATEDATA_H | |
cfd66529 | 3 | |
cfd66529 | 4 | #include "base/AsyncCall.h" |
aed188fd | 5 | #include "base/AsyncJob.h" |
cfd66529 | 6 | #include "cbdata.h" |
e52e78c4 | 7 | #include "CommCalls.h" |
40d34a62 | 8 | #include "comm_err_t.h" |
f9b72e0c | 9 | #include "comm/forward.h" |
cfd66529 | 10 | |
dc49061a A |
11 | namespace Comm |
12 | { | |
4accd6d8 | 13 | |
cfd66529 | 14 | /** |
aed188fd | 15 | * Async-opener of a Comm connection. |
cfd66529 | 16 | */ |
aed188fd | 17 | class ConnOpener : public AsyncJob |
cfd66529 | 18 | { |
5229395c AJ |
19 | protected: |
20 | virtual void start(); | |
e52e78c4 AJ |
21 | virtual void swanSong(); |
22 | ||
40d9f0fc | 23 | public: |
d471b08a AK |
24 | void noteAbort() { mustStop("externally aborted"); } |
25 | ||
9e64d84e AR |
26 | typedef CbcPointer<ConnOpener> Pointer; |
27 | ||
5229395c | 28 | virtual bool doneAll() const; |
e52e78c4 | 29 | |
40d9f0fc | 30 | ConnOpener(Comm::ConnectionPointer &, AsyncCall::Pointer &handler, time_t connect_timeout); |
e52e78c4 AJ |
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 | ||
739b352a | 36 | private: |
5b67dfa4 | 37 | // Undefined because two openers cannot share a connection |
aed188fd | 38 | ConnOpener(const ConnOpener &); |
5229395c | 39 | ConnOpener & operator =(const ConnOpener &c); |
cfd66529 | 40 | |
2832d7c0 | 41 | void earlyAbort(const CommCloseCbParams &); |
418b3087 | 42 | void timeout(const CommTimeoutCbParams &); |
5f621cd0 | 43 | void doneConnecting(comm_err_t errFlag, int xerrno); |
418b3087 AJ |
44 | static void InProgressConnectRetry(int fd, void *data); |
45 | static void DelayedConnectRetry(void *data); | |
46 | void connect(); | |
47 | void connected(); | |
dd829807 | 48 | void lookupLocalAddress(); |
e52e78c4 | 49 | |
40d9f0fc | 50 | private: |
5229395c | 51 | char *host_; ///< domain name we are trying to connect to. |
a95ff429 AJ |
52 | int temporaryFd_; ///< the FD being opened. Do NOT set conn_->fd until it is fully open. |
53 | Comm::ConnectionPointer conn_; ///< single connection currently to be opened. | |
5229395c AJ |
54 | AsyncCall::Pointer callback_; ///< handler to be called on connection completion. |
55 | ||
56 | int totalTries_; ///< total number of connection attempts over all destinations so far. | |
57 | int failRetries_; ///< number of retries current destination has been tried. | |
58 | ||
cfd66529 | 59 | /** |
739b352a | 60 | * time at which to abandon the connection. |
cfd66529 AJ |
61 | * the connection-done callback will be passed COMM_TIMEOUT |
62 | */ | |
5229395c | 63 | time_t connectTimeout_; |
cfd66529 | 64 | |
5229395c | 65 | /// time at which this series of connection attempts was started. |
802540f2 | 66 | time_t connectStart_; |
cfd66529 | 67 | |
e52e78c4 | 68 | /// handles to calls which we may need to cancel. |
5229395c AJ |
69 | struct Calls { |
70 | AsyncCall::Pointer earlyAbort_; | |
71 | AsyncCall::Pointer timeout_; | |
72 | } calls_; | |
e52e78c4 | 73 | |
aed188fd | 74 | CBDATA_CLASS2(ConnOpener); |
cfd66529 AJ |
75 | }; |
76 | ||
4accd6d8 AJ |
77 | }; // namespace Comm |
78 | ||
aed188fd | 79 | #endif /* _SQUID_SRC_COMM_CONNOPENER_H */ |