ConnOpener.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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_OPENERSTATEDATA_H
10 #define _SQUID_SRC_COMM_OPENERSTATEDATA_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  virtual bool doneAll() const;
32 
34  ~ConnOpener();
35 
36  void setHost(const char *);
37  const char * getHost() const;
38 
39 protected:
40  virtual void start();
41  virtual void swanSong();
42 
43 private:
44  // Undefined because two openers cannot share a connection
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:465
void retrySleep()
Close and wait a little before trying to open and connect again.
Definition: ConnOpener.cc:398
CBDATA_CLASS(ConnOpener)
void sendAnswer(Comm::Flag errFlag, int xerrno, const char *why)
Definition: ConnOpener.cc:123
char * host_
domain name we are trying to connect to.
Definition: ConnOpener.h:68
void lookupLocalAddress()
Definition: ConnOpener.cc:431
ConnOpener(const Comm::ConnectionPointer &, const AsyncCall::Pointer &handler, time_t connect_timeout)
Definition: ConnOpener.cc:33
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:220
static void handler(int signo)
Definition: purge.cc:854
Comm::ConnectionPointer conn_
single connection currently to be opened.
Definition: ConnOpener.h:70
virtual void start()
called by AsyncStart; do not call directly
Definition: ConnOpener.cc:251
const char * getHost() const
get the hostname noted for this connection
Definition: ConnOpener.cc:113
Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.
Definition: AcceptLimiter.h:17
virtual bool doneAll() const
whether positive goal has been reached
Definition: ConnOpener.cc:60
void setHost(const char *)
set the hostname note for this connection
Definition: ConnOpener.cc:101
void cancelSleep()
cleans up this job sleep state
Definition: ConnOpener.cc:410
static void DelayedConnectRetry(void *data)
Definition: ConnOpener.cc:494
AsyncCall::Pointer timeout_
Definition: ConnOpener.h:82
virtual void swanSong()
Definition: ConnOpener.cc:78
int totalTries_
total number of connection attempts over all destinations so far.
Definition: ConnOpener.h:73
struct Comm::ConnOpener::Calls calls_
void doConnect()
Make an FD connection attempt.
Definition: ConnOpener.cc:357
ConnOpener(const ConnOpener &)
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:452
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:267
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:476
void keepFd()
cleans I/O state and moves temporaryFd_ to the conn_ for long-term use
Definition: ConnOpener.cc:239
AsyncCall::Pointer earlyAbort_
Definition: ConnOpener.h:81

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors