]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/ConnOpener.h
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 #ifndef _SQUID_SRC_COMM_OPENERSTATEDATA_H
10 #define _SQUID_SRC_COMM_OPENERSTATEDATA_H
12 #include "base/AsyncCall.h"
13 #include "base/AsyncJob.h"
15 #include "comm/Flag.h"
16 #include "comm/forward.h"
17 #include "CommCalls.h"
22 /// Asynchronously opens a TCP connection. Returns CommConnectCbParams: either
23 /// Comm::OK with an open connection or another Comm::Flag with a closed one.
24 class ConnOpener
: public AsyncJob
26 CBDATA_CHILD(ConnOpener
);
29 typedef CbcPointer
<ConnOpener
> Pointer
;
31 bool doneAll() const override
;
33 ConnOpener(const Comm::ConnectionPointer
&, const AsyncCall::Pointer
&handler
, time_t connect_timeout
);
34 ~ConnOpener() override
;
36 void setHost(const char *); ///< set the hostname note for this connection
37 const char * getHost() const; ///< get the hostname noted for this connection
40 void start() override
;
41 void swanSong() override
;
44 // Undefined because two openers cannot share a connection
45 ConnOpener(const ConnOpener
&);
46 ConnOpener
& operator =(const ConnOpener
&c
);
48 void earlyAbort(const CommCloseCbParams
&);
49 void timeout(const CommTimeoutCbParams
&);
50 void sendAnswer(Comm::Flag errFlag
, int xerrno
, const char *why
);
51 static void InProgressConnectRetry(int fd
, void *data
);
52 static void DelayedConnectRetry(void *data
);
55 void lookupLocalAddress();
68 char *host_
; ///< domain name we are trying to connect to.
69 int temporaryFd_
; ///< the FD being opened. Do NOT set conn_->fd until it is fully open.
70 Comm::ConnectionPointer conn_
; ///< single connection currently to be opened.
71 AsyncCall::Pointer callback_
; ///< handler to be called on connection completion.
73 int totalTries_
; ///< total number of connection attempts over all destinations so far.
74 int failRetries_
; ///< number of retries current destination has been tried.
76 /// if we are not done by then, we will call back with Comm::TIMEOUT
79 /// handles to calls which we may need to cancel.
81 AsyncCall::Pointer earlyAbort_
;
82 AsyncCall::Pointer timeout_
;
83 /// Whether we are idling before retrying to connect; not yet a call
84 /// [that we can cancel], but it will probably become one eventually.
91 #endif /* _SQUID_SRC_COMM_CONNOPENER_H */