]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
bbc27441 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
aed188fd AJ |
9 | #ifndef _SQUID_SRC_COMM_OPENERSTATEDATA_H |
10 | #define _SQUID_SRC_COMM_OPENERSTATEDATA_H | |
cfd66529 | 11 | |
cfd66529 | 12 | #include "base/AsyncCall.h" |
aed188fd | 13 | #include "base/AsyncJob.h" |
cfd66529 | 14 | #include "cbdata.h" |
c8407295 | 15 | #include "comm/Flag.h" |
f9b72e0c | 16 | #include "comm/forward.h" |
602d9612 | 17 | #include "CommCalls.h" |
cfd66529 | 18 | |
dc49061a A |
19 | namespace Comm |
20 | { | |
4accd6d8 | 21 | |
cfd66529 | 22 | /** |
aed188fd | 23 | * Async-opener of a Comm connection. |
cfd66529 | 24 | */ |
aed188fd | 25 | class ConnOpener : public AsyncJob |
cfd66529 | 26 | { |
5c2f68b7 AJ |
27 | CBDATA_CLASS(ConnOpener); |
28 | ||
40d9f0fc | 29 | public: |
d471b08a AK |
30 | void noteAbort() { mustStop("externally aborted"); } |
31 | ||
9e64d84e AR |
32 | typedef CbcPointer<ConnOpener> Pointer; |
33 | ||
5229395c | 34 | virtual bool doneAll() const; |
e52e78c4 | 35 | |
9b7992d9 | 36 | ConnOpener(const Comm::ConnectionPointer &, const AsyncCall::Pointer &handler, time_t connect_timeout); |
e52e78c4 AJ |
37 | ~ConnOpener(); |
38 | ||
39 | void setHost(const char *); ///< set the hostname note for this connection | |
40 | const char * getHost() const; ///< get the hostname noted for this connection | |
41 | ||
81da7e70 AR |
42 | protected: |
43 | virtual void start(); | |
44 | virtual void swanSong(); | |
45 | ||
739b352a | 46 | private: |
5b67dfa4 | 47 | // Undefined because two openers cannot share a connection |
aed188fd | 48 | ConnOpener(const ConnOpener &); |
5229395c | 49 | ConnOpener & operator =(const ConnOpener &c); |
cfd66529 | 50 | |
2832d7c0 | 51 | void earlyAbort(const CommCloseCbParams &); |
418b3087 | 52 | void timeout(const CommTimeoutCbParams &); |
c8407295 | 53 | void sendAnswer(Comm::Flag errFlag, int xerrno, const char *why); |
418b3087 AJ |
54 | static void InProgressConnectRetry(int fd, void *data); |
55 | static void DelayedConnectRetry(void *data); | |
3d7ecaff | 56 | void doConnect(); |
418b3087 | 57 | void connected(); |
dd829807 | 58 | void lookupLocalAddress(); |
e52e78c4 | 59 | |
f6c0d1ab | 60 | void retrySleep(); |
923b75ce AR |
61 | void restart(); |
62 | ||
63 | bool createFd(); | |
64 | void closeFd(); | |
65 | void keepFd(); | |
66 | void cleanFd(); | |
67 | ||
68 | void cancelSleep(); | |
69 | ||
40d9f0fc | 70 | private: |
5229395c | 71 | char *host_; ///< domain name we are trying to connect to. |
a95ff429 AJ |
72 | int temporaryFd_; ///< the FD being opened. Do NOT set conn_->fd until it is fully open. |
73 | Comm::ConnectionPointer conn_; ///< single connection currently to be opened. | |
5229395c AJ |
74 | AsyncCall::Pointer callback_; ///< handler to be called on connection completion. |
75 | ||
76 | int totalTries_; ///< total number of connection attempts over all destinations so far. | |
77 | int failRetries_; ///< number of retries current destination has been tried. | |
78 | ||
c8407295 | 79 | /// if we are not done by then, we will call back with Comm::TIMEOUT |
923b75ce | 80 | time_t deadline_; |
cfd66529 | 81 | |
e52e78c4 | 82 | /// handles to calls which we may need to cancel. |
5229395c AJ |
83 | struct Calls { |
84 | AsyncCall::Pointer earlyAbort_; | |
85 | AsyncCall::Pointer timeout_; | |
923b75ce AR |
86 | /// Whether we are idling before retrying to connect; not yet a call |
87 | /// [that we can cancel], but it will probably become one eventually. | |
88 | bool sleep_; | |
5229395c | 89 | } calls_; |
cfd66529 AJ |
90 | }; |
91 | ||
4accd6d8 AJ |
92 | }; // namespace Comm |
93 | ||
aed188fd | 94 | #endif /* _SQUID_SRC_COMM_CONNOPENER_H */ |
f53969cc | 95 |