ConnOpener.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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 
9 #ifndef SQUID_SRC_COMM_CONNOPENER_H
10 #define SQUID_SRC_COMM_CONNOPENER_H
11 
12 #include "base/AsyncCall.h"
13 #include "base/AsyncJob.h"
14 #include "cbdata.h"
15 #include "comm/Flag.h"
16 #include "comm/forward.h"
17 #include "CommCalls.h"
18 
19 namespace Comm
20 {
21 
24 class ConnOpener : public AsyncJob
25 {
27 
28 public:
30 
31  bool doneAll() const override;
32 
34  ~ConnOpener() override;
35 
36  void setHost(const char *);
37  const char * getHost() const;
38 
39 protected:
40  void start() override;
41  void swanSong() override;
42 
43 private:
44  // Undefined because two openers cannot share a connection
45  ConnOpener(const ConnOpener &);
46  ConnOpener & operator =(const ConnOpener &c);
47 
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);
53  void doConnect();
54  void connected();
55  void lookupLocalAddress();
56 
57  void retrySleep();
58  void restart();
59 
60  bool createFd();
61  void closeFd();
62  void keepFd();
63  void cleanFd();
64 
65  void cancelSleep();
66 
67 private:
68  char *host_;
72 
75 
77  time_t deadline_;
78 
80  struct Calls {
85  bool sleep_;
86  } calls_;
87 };
88 
89 }; // namespace Comm
90 
91 #endif /* SQUID_SRC_COMM_CONNOPENER_H */
92 
void timeout(const CommTimeoutCbParams &)
Definition: ConnOpener.cc:461
void retrySleep()
Close and wait a little before trying to open and connect again.
Definition: ConnOpener.cc:397
void sendAnswer(Comm::Flag errFlag, int xerrno, const char *why)
Definition: ConnOpener.cc:122
char * host_
domain name we are trying to connect to.
Definition: ConnOpener.h:68
void lookupLocalAddress()
Definition: ConnOpener.cc:430
ConnOpener(const Comm::ConnectionPointer &, const AsyncCall::Pointer &handler, time_t connect_timeout)
Definition: ConnOpener.cc:32
handles to calls which we may need to cancel.
Definition: ConnOpener.h:80
void closeFd()
cleans I/O state and ends I/O for temporaryFd_
Definition: ConnOpener.cc:219
Comm::ConnectionPointer conn_
single connection currently to be opened.
Definition: ConnOpener.h:70
const char * getHost() const
get the hostname noted for this connection
Definition: ConnOpener.cc:112
Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.
Definition: AcceptLimiter.h:16
void start() override
called by AsyncStart; do not call directly
Definition: ConnOpener.cc:250
~ConnOpener() override
Definition: ConnOpener.cc:53
void setHost(const char *)
set the hostname note for this connection
Definition: ConnOpener.cc:100
bool doneAll() const override
whether positive goal has been reached
Definition: ConnOpener.cc:59
void cancelSleep()
cleans up this job sleep state
Definition: ConnOpener.cc:409
static void DelayedConnectRetry(void *data)
Definition: ConnOpener.cc:490
AsyncCall::Pointer timeout_
Definition: ConnOpener.h:82
int totalTries_
total number of connection attempts over all destinations so far.
Definition: ConnOpener.h:73
void swanSong() override
Definition: ConnOpener.cc:77
struct Comm::ConnOpener::Calls calls_
void doConnect()
Make an FD connection attempt.
Definition: ConnOpener.cc:356
int failRetries_
number of retries current destination has been tried.
Definition: ConnOpener.h:74
AsyncCall::Pointer callback_
handler to be called on connection completion.
Definition: ConnOpener.h:71
Flag
Definition: Flag.h:15
int temporaryFd_
the FD being opened. Do NOT set conn_->fd until it is fully open.
Definition: ConnOpener.h:69
void earlyAbort(const CommCloseCbParams &)
Definition: ConnOpener.cc:448
CbcPointer< ConnOpener > Pointer
Definition: ConnOpener.h:29
ConnOpener & operator=(const ConnOpener &c)
void restart()
called at the end of Comm::ConnOpener::DelayedConnectRetry event
Definition: ConnOpener.cc:266
CBDATA_CHILD(ConnOpener)
static int connect_timeout
time_t deadline_
if we are not done by then, we will call back with Comm::TIMEOUT
Definition: ConnOpener.h:77
static void InProgressConnectRetry(int fd, void *data)
Definition: ConnOpener.cc:472
void keepFd()
cleans I/O state and moves temporaryFd_ to the conn_ for long-term use
Definition: ConnOpener.cc:238
AsyncCall::Pointer earlyAbort_
Definition: ConnOpener.h:81

 

Introduction

Documentation

Support

Miscellaneous