]> git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/ConnOpener.h
Merged from trunk
[thirdparty/squid.git] / src / comm / ConnOpener.h
1 #ifndef _SQUID_SRC_COMM_OPENERSTATEDATA_H
2 #define _SQUID_SRC_COMM_OPENERSTATEDATA_H
3
4 #include "base/AsyncCall.h"
5 #include "base/AsyncJob.h"
6 #include "cbdata.h"
7 #include "CommCalls.h"
8 #include "comm/comm_err_t.h"
9 #include "comm/forward.h"
10
11 namespace Comm {
12
13 /**
14 * Async-opener of a Comm connection.
15 */
16 class ConnOpener : public AsyncJob
17 {
18 protected:
19 virtual void start();
20 virtual void swanSong();
21
22 public:
23 virtual bool doneAll() const;
24
25 ConnOpener(Comm::ConnectionPointer &, AsyncCall::Pointer &handler, time_t connect_timeout);
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
31 private:
32 // Undefined because two openers cannot share a connection
33 ConnOpener(const ConnOpener &);
34 ConnOpener & operator =(const ConnOpener &c);
35
36 void earlyAbort(const CommConnectCbParams &);
37 void timeout(const CommTimeoutCbParams &);
38 void doneConnecting(comm_err_t status, int xerrno);
39 static void InProgressConnectRetry(int fd, void *data);
40 static void DelayedConnectRetry(void *data);
41 void connect();
42 void connected();
43 void lookupLocalAddress();
44
45 private:
46 char *host_; ///< domain name we are trying to connect to.
47 Comm::ConnectionPointer conn_; ///< single connection currently being opened.
48 AsyncCall::Pointer callback_; ///< handler to be called on connection completion.
49
50 int totalTries_; ///< total number of connection attempts over all destinations so far.
51 int failRetries_; ///< number of retries current destination has been tried.
52
53 /**
54 * time at which to abandon the connection.
55 * the connection-done callback will be passed COMM_TIMEOUT
56 */
57 time_t connectTimeout_;
58
59 /// time at which this series of connection attempts was started.
60 time_t connectStart_;
61
62 /// handles to calls which we may need to cancel.
63 struct Calls {
64 AsyncCall::Pointer earlyAbort_;
65 AsyncCall::Pointer timeout_;
66 } calls_;
67
68 CBDATA_CLASS2(ConnOpener);
69 };
70
71 }; // namespace Comm
72
73 #endif /* _SQUID_SRC_COMM_CONNOPENER_H */