]>
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" |
f9b72e0c | 7 | #include "comm/forward.h" |
602d9612 A |
8 | #include "comm_err_t.h" |
9 | #include "CommCalls.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 &); |
923b75ce | 43 | void sendAnswer(comm_err_t errFlag, int xerrno, const char *why); |
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 | |
f6c0d1ab | 50 | void retrySleep(); |
923b75ce AR |
51 | void restart(); |
52 | ||
53 | bool createFd(); | |
54 | void closeFd(); | |
55 | void keepFd(); | |
56 | void cleanFd(); | |
57 | ||
58 | void cancelSleep(); | |
59 | ||
40d9f0fc | 60 | private: |
5229395c | 61 | char *host_; ///< domain name we are trying to connect to. |
a95ff429 AJ |
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. | |
5229395c AJ |
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 | ||
923b75ce AR |
69 | /// if we are not done by then, we will call back with COMM_TIMEOUT |
70 | time_t deadline_; | |
cfd66529 | 71 | |
e52e78c4 | 72 | /// handles to calls which we may need to cancel. |
5229395c AJ |
73 | struct Calls { |
74 | AsyncCall::Pointer earlyAbort_; | |
75 | AsyncCall::Pointer timeout_; | |
923b75ce AR |
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_; | |
5229395c | 79 | } calls_; |
e52e78c4 | 80 | |
aed188fd | 81 | CBDATA_CLASS2(ConnOpener); |
cfd66529 AJ |
82 | }; |
83 | ||
4accd6d8 AJ |
84 | }; // namespace Comm |
85 | ||
aed188fd | 86 | #endif /* _SQUID_SRC_COMM_CONNOPENER_H */ |