]>
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 AJ |
17 | { |
18 | public: | |
e52e78c4 | 19 | // ****** AsynJob API implementation ****** |
cfd66529 | 20 | |
aed188fd AJ |
21 | /** Actual start opening a TCP connection. */ |
22 | void start(); | |
739b352a | 23 | |
294775b5 | 24 | virtual bool doneAll() const; |
e52e78c4 AJ |
25 | virtual void swanSong(); |
26 | ||
40d9f0fc | 27 | public: |
e52e78c4 AJ |
28 | // ****** ConnOpener API iplementation ****** |
29 | ||
30 | /** attempt to open a connection. */ | |
40d9f0fc | 31 | ConnOpener(Comm::ConnectionPointer &, AsyncCall::Pointer &handler, time_t connect_timeout); |
e52e78c4 AJ |
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 | ||
739b352a AJ |
37 | private: |
38 | /* These objects may NOT be created without connections to act on. Do not define this operator. */ | |
aed188fd | 39 | ConnOpener(const ConnOpener &); |
739b352a | 40 | /* These objects may NOT be copied. Do not define this operator. */ |
aed188fd | 41 | ConnOpener operator =(const ConnOpener &c); |
cfd66529 | 42 | |
e52e78c4 AJ |
43 | /** Make an FD connection attempt. |
44 | * Handles the case(s) when a partially setup connection gets closed early. | |
cfd66529 | 45 | */ |
e52e78c4 | 46 | void connect(const CommConnectCbParams &unused); |
cfd66529 | 47 | |
e52e78c4 | 48 | /** Abort connection attempt. |
cfd66529 AJ |
49 | * Handles the case(s) when a partially setup connection gets closed early. |
50 | */ | |
e52e78c4 | 51 | void earlyAbort(const CommConnectCbParams &); |
cfd66529 | 52 | |
aed188fd | 53 | /** |
aed188fd | 54 | * Handles the case(s) when a partially setup connection gets timed out. |
e52e78c4 | 55 | * NP: When commSetTimeout accepts generic CommCommonCbParams this can die. |
aed188fd | 56 | */ |
e52e78c4 | 57 | void timeout(const CommTimeoutCbParams &unused); |
aed188fd | 58 | |
cfd66529 AJ |
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 | ||
e52e78c4 AJ |
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 | ||
40d9f0fc | 69 | private: |
cfd66529 | 70 | /** |
739b352a | 71 | * time at which to abandon the connection. |
cfd66529 AJ |
72 | * the connection-done callback will be passed COMM_TIMEOUT |
73 | */ | |
74 | time_t connect_timeout; | |
75 | ||
aed188fd AJ |
76 | char *host; ///< domain name we are trying to connect to. |
77 | ||
f9b72e0c AJ |
78 | Comm::ConnectionPointer solo; ///< single connection currently being opened. |
79 | AsyncCall::Pointer callback; ///< handler to be called on connection completion. | |
cfd66529 AJ |
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 | ||
e52e78c4 AJ |
85 | /// handles to calls which we may need to cancel. |
86 | struct _calls { | |
87 | AsyncCall::Pointer earlyabort; | |
88 | AsyncCall::Pointer timeout; | |
89 | } calls; | |
90 | ||
aed188fd | 91 | CBDATA_CLASS2(ConnOpener); |
cfd66529 AJ |
92 | }; |
93 | ||
4accd6d8 AJ |
94 | }; // namespace Comm |
95 | ||
aed188fd | 96 | #endif /* _SQUID_SRC_COMM_CONNOPENER_H */ |