ConnOpener.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 
25 class ConnOpener : public AsyncJob
26 {
28 
29 public:
30  void noteAbort() { mustStop("externally aborted"); }
31 
33 
34  virtual bool doneAll() const;
35 
37  ~ConnOpener();
38 
39  void setHost(const char *);
40  const char * getHost() const;
41 
42 protected:
43  virtual void start();
44  virtual void swanSong();
45 
46 private:
47  // Undefined because two openers cannot share a connection
48  ConnOpener(const ConnOpener &);
49  ConnOpener & operator =(const ConnOpener &c);
50 
51  void earlyAbort(const CommCloseCbParams &);
52  void timeout(const CommTimeoutCbParams &);
53  void sendAnswer(Comm::Flag errFlag, int xerrno, const char *why);
54  static void InProgressConnectRetry(int fd, void *data);
55  static void DelayedConnectRetry(void *data);
56  void doConnect();
57  void connected();
58  void lookupLocalAddress();
59 
60  void retrySleep();
61  void restart();
62 
63  bool createFd();
64  void closeFd();
65  void keepFd();
66  void cleanFd();
67 
68  void cancelSleep();
69 
70 private:
71  char *host_;
75 
78 
80  time_t deadline_;
81 
83  struct Calls {
88  bool sleep_;
89  } calls_;
90 };
91 
92 }; // namespace Comm
93 
94 #endif /* _SQUID_SRC_COMM_CONNOPENER_H */
95 
AsyncCall::Pointer callback_
handler to be called on connection completion.
Definition: ConnOpener.h:74
Comm::ConnectionPointer conn_
single connection currently to be opened.
Definition: ConnOpener.h:73
struct Comm::ConnOpener::Calls calls_
virtual void start()
called by AsyncStart; do not call directly
Definition: ConnOpener.cc:230
CbcPointer< ConnOpener > Pointer
Definition: ConnOpener.h:32
AsyncCall::Pointer timeout_
Definition: ConnOpener.h:85
handles to calls which we may need to cancel.
Definition: ConnOpener.h:83
AsyncCall::Pointer earlyAbort_
Definition: ConnOpener.h:84
void mustStop(const char *aReason)
Definition: AsyncJob.cc:69
void setHost(const char *)
set the hostname note for this connection
Definition: ConnOpener.cc:89
static int connect_timeout
void restart()
called at the end of Comm::ConnOpener::DelayedConnectRetry event
Definition: ConnOpener.cc:246
void earlyAbort(const CommCloseCbParams &)
Definition: ConnOpener.cc:430
void doConnect()
Make an FD connection attempt.
Definition: ConnOpener.cc:335
void cancelSleep()
cleans up this job sleep state
Definition: ConnOpener.cc:388
void const char HLPCB void * data
Definition: stub_helper.cc:16
ConnOpener & operator=(const ConnOpener &c)
CBDATA_CLASS(ConnOpener)
void sendAnswer(Comm::Flag errFlag, int xerrno, const char *why)
Definition: ConnOpener.cc:111
static void InProgressConnectRetry(int fd, void *data)
Definition: ConnOpener.cc:454
void retrySleep()
Close and wait a little before trying to open and connect again.
Definition: ConnOpener.cc:376
void keepFd()
cleans I/O state and moves temporaryFd_ to the conn_ for long-term use
Definition: ConnOpener.cc:218
void closeFd()
cleans I/O state and ends I/O for temporaryFd_
Definition: ConnOpener.cc:199
static void handler(int signo)
Definition: purge.cc:860
const char * getHost() const
get the hostname noted for this connection
Definition: ConnOpener.cc:101
static void DelayedConnectRetry(void *data)
Definition: ConnOpener.cc:472
Flag
Definition: Flag.h:15
time_t deadline_
if we are not done by then, we will call back with Comm::TIMEOUT
Definition: ConnOpener.h:80
void timeout(const CommTimeoutCbParams &)
Definition: ConnOpener.cc:443
virtual void swanSong()
Definition: ConnOpener.cc:70
int totalTries_
total number of connection attempts over all destinations so far.
Definition: ConnOpener.h:76
int temporaryFd_
the FD being opened. Do NOT set conn_->fd until it is fully open.
Definition: ConnOpener.h:72
ConnOpener(Comm::ConnectionPointer &, AsyncCall::Pointer &handler, time_t connect_timeout)
Definition: ConnOpener.cc:33
void lookupLocalAddress()
Definition: ConnOpener.cc:409
char * host_
domain name we are trying to connect to.
Definition: ConnOpener.h:71
virtual bool doneAll() const
whether positive goal has been reached
Definition: ConnOpener.cc:52
void noteAbort()
Definition: ConnOpener.h:30
int failRetries_
number of retries current destination has been tried.
Definition: ConnOpener.h:77

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors