]>
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" |
cfd66529 | 8 | #include "comm/comm_err_t.h" |
f9b72e0c | 9 | #include "comm/forward.h" |
cfd66529 | 10 | |
4accd6d8 AJ |
11 | namespace Comm { |
12 | ||
cfd66529 | 13 | /** |
aed188fd | 14 | * Async-opener of a Comm connection. |
cfd66529 | 15 | */ |
aed188fd | 16 | class ConnOpener : public AsyncJob |
cfd66529 | 17 | { |
5229395c AJ |
18 | protected: |
19 | virtual void start(); | |
e52e78c4 AJ |
20 | virtual void swanSong(); |
21 | ||
40d9f0fc | 22 | public: |
5229395c | 23 | virtual bool doneAll() const; |
e52e78c4 | 24 | |
40d9f0fc | 25 | ConnOpener(Comm::ConnectionPointer &, AsyncCall::Pointer &handler, time_t connect_timeout); |
e52e78c4 AJ |
26 | ~ConnOpener(); |
27 | ||
28 | void setHost(const char *); ///< set the hostname note for this connection | |
29 | const char * getHost() const; ///< get the hostname noted for this connection | |
30 | ||
739b352a | 31 | private: |
5b67dfa4 | 32 | // Undefined because two openers cannot share a connection |
aed188fd | 33 | ConnOpener(const ConnOpener &); |
5229395c | 34 | ConnOpener & operator =(const ConnOpener &c); |
cfd66529 | 35 | |
e52e78c4 | 36 | void connect(const CommConnectCbParams &unused); |
e52e78c4 | 37 | void earlyAbort(const CommConnectCbParams &); |
e52e78c4 | 38 | void timeout(const CommTimeoutCbParams &unused); |
5229395c | 39 | void doneConnecting(comm_err_t status, int xerrno); |
e52e78c4 | 40 | static void ConnectRetry(int fd, void *data); |
dd829807 | 41 | void lookupLocalAddress(); |
e52e78c4 | 42 | |
40d9f0fc | 43 | private: |
5229395c AJ |
44 | char *host_; ///< domain name we are trying to connect to. |
45 | Comm::ConnectionPointer conn_; ///< single connection currently being opened. | |
46 | AsyncCall::Pointer callback_; ///< handler to be called on connection completion. | |
47 | ||
48 | int totalTries_; ///< total number of connection attempts over all destinations so far. | |
49 | int failRetries_; ///< number of retries current destination has been tried. | |
50 | ||
cfd66529 | 51 | /** |
739b352a | 52 | * time at which to abandon the connection. |
cfd66529 AJ |
53 | * the connection-done callback will be passed COMM_TIMEOUT |
54 | */ | |
5229395c | 55 | time_t connectTimeout_; |
cfd66529 | 56 | |
5229395c AJ |
57 | /// time at which this series of connection attempts was started. |
58 | time_t connStart_; | |
cfd66529 | 59 | |
e52e78c4 | 60 | /// handles to calls which we may need to cancel. |
5229395c | 61 | struct Calls { |
5d779c44 | 62 | AsyncCall::Pointer connect_; |
5229395c AJ |
63 | AsyncCall::Pointer earlyAbort_; |
64 | AsyncCall::Pointer timeout_; | |
65 | } calls_; | |
e52e78c4 | 66 | |
aed188fd | 67 | CBDATA_CLASS2(ConnOpener); |
cfd66529 AJ |
68 | }; |
69 | ||
4accd6d8 AJ |
70 | }; // namespace Comm |
71 | ||
aed188fd | 72 | #endif /* _SQUID_SRC_COMM_CONNOPENER_H */ |