libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
socks_connecter.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4  This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6  libzmq is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License (LGPL) as published
8  by the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  As a special exception, the Contributors give you permission to link
12  this library with independent modules to produce an executable,
13  regardless of the license terms of these independent modules, and to
14  copy and distribute the resulting executable under terms of your choice,
15  provided that you also meet, for each linked independent module, the
16  terms and conditions of the license of that module. An independent
17  module is a module which is not derived from or based on this library.
18  If you modify this library, you must extend this exception to your
19  version of the library.
20 
21  libzmq is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public License
27  along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 
30 #ifndef __SOCKS_CONNECTER_HPP_INCLUDED__
31 #define __SOCKS_CONNECTER_HPP_INCLUDED__
32 
33 #include "fd.hpp"
34 #include "io_object.hpp"
35 #include "own.hpp"
36 #include "stdint.hpp"
37 #include "../include/zmq.h"
38 #include "socks.hpp"
39 
40 namespace zmq
41 {
42 
43  class io_thread_t;
44  class session_base_t;
45  struct address_t;
46 
47  class socks_connecter_t : public own_t, public io_object_t
48  {
49  public:
50 
51  // If 'delayed_start' is true connecter first waits for a while,
52  // then starts connection process.
54  zmq::session_base_t *session_, const options_t &options_,
55  address_t *addr_, address_t *proxy_addr_, bool delayed_start_);
57 
58  private:
59  enum {
67  };
68 
69  // ID of the timer used to delay the reconnection.
70  enum { reconnect_timer_id = 1 };
71 
72  // Method ID
73  enum { socks_no_auth_required = 0 };
74 
75  // Handlers for incoming commands.
76  virtual void process_plug ();
77  virtual void process_term (int linger_);
78 
79  // Handlers for I/O events.
80  virtual void in_event ();
81  virtual void out_event ();
82  virtual void timer_event (int id_);
83 
84  // Internal function to start the actual connection establishment.
85  void initiate_connect ();
86 
87  int process_server_response (const socks_choice_t &response);
88  int process_server_response (const socks_response_t &response);
89 
90  int parse_address (const std::string &address_,
91  std::string &hostname_, uint16_t &port_);
92 
93  int connect_to_proxy ();
94 
95  void error ();
96 
97  // Internal function to start reconnect timer
98  void start_timer ();
99 
100  // Internal function to return a reconnect backoff delay.
101  // Will modify the current_reconnect_ivl used for next call
102  // Returns the currently used interval
103  int get_new_reconnect_ivl ();
104 
105  // Open TCP connecting socket. Returns -1 in case of error,
106  // 0 if connect was successful immediately. Returns -1 with
107  // EAGAIN errno if async connect was launched.
108  int open ();
109 
110  // Close the connecting socket.
111  void close ();
112 
113  // Get the file descriptor of newly created connection. Returns
114  // retired_fd if the connection was unsuccessful.
116 
121 
122  // Address to connect to. Owned by session_base_t.
124 
125  // SOCKS address; owned by this connecter.
127 
128  int status;
129 
130  // Underlying socket.
132 
133  // Handle corresponding to the listening socket.
135 
136  // If true file descriptor is registered with the poller and 'handle'
137  // contains valid value.
139 
140  // If true, connecter is waiting a while before trying to connect.
141  const bool delayed_start;
142 
143  // True iff a timer has been started.
145 
146  // Reference to the session we belong to.
148 
149  // Current reconnect ivl, updated for backoff strategy
151 
152  // String representation of endpoint to connect to
153  std::string endpoint;
154 
155  // Socket
157 
160  };
161 
162 }
163 
164 #endif
zmq::socket_base_t * socket
socks_choice_decoder_t choice_decoder
socks_greeting_encoder_t greeting_encoder
int parse_address(const std::string &address_, std::string &hostname_, uint16_t &port_)
int process_server_response(const socks_choice_t &response)
zmq::fd_t check_proxy_connection()
zmq::session_base_t * session
socks_response_decoder_t response_decoder
socks_connecter_t(zmq::io_thread_t *io_thread_, zmq::session_base_t *session_, const options_t &options_, address_t *addr_, address_t *proxy_addr_, bool delayed_start_)
socks_request_encoder_t request_encoder
virtual void process_plug()
const socks_connecter_t & operator=(const socks_connecter_t &)
Definition: address.hpp:35
poller_t::handle_t handle_t
Definition: io_object.hpp:62
virtual void timer_event(int id_)
virtual void process_term(int linger_)