2
Copyright (c) 2009-2011 250bpm s.r.o.
3
Copyright (c) 2007-2009 iMatix Corporation
4
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
6
This file is part of 0MQ.
8
0MQ is free software; you can redistribute it and/or modify it under
9
the terms of the GNU Lesser General Public License as published by
10
the Free Software Foundation; either version 3 of the License, or
11
(at your option) any later version.
13
0MQ is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#ifndef __TCP_CONNECTER_HPP_INCLUDED__
23
#define __TCP_CONNECTER_HPP_INCLUDED__
28
#include "io_object.hpp"
29
#include "../include/zmq.h"
38
class tcp_connecter_t : public own_t, public io_object_t
42
// If 'delay' is true connecter first waits for a while, then starts
43
// connection process.
44
tcp_connecter_t (zmq::io_thread_t *io_thread_,
45
zmq::session_base_t *session_, const options_t &options_,
46
const address_t *addr_, bool delay_);
51
// ID of the timer used to delay the reconnection.
52
enum {reconnect_timer_id = 1};
54
// Handlers for incoming commands.
57
// Handlers for I/O events.
60
void timer_event (int id_);
62
// Internal function to start the actual connection establishment.
63
void start_connecting ();
65
// Internal function to add a reconnect timer
66
void add_reconnect_timer();
68
// Internal function to return a reconnect backoff delay.
69
// Will modify the current_reconnect_ivl used for next call
70
// Returns the currently used interval
71
int get_new_reconnect_ivl ();
73
// Open TCP connecting socket. Returns -1 in case of error,
74
// 0 if connect was successfull immediately. Returns -1 with
75
// EAGAIN errno if async connect was launched.
78
// Close the connecting socket.
81
// Get the file descriptor of newly created connection. Returns
82
// retired_fd if the connection was unsuccessfull.
85
// Address to connect to. Owned by session_base_t.
86
const address_t *addr;
91
// Handle corresponding to the listening socket.
94
// If true file descriptor is registered with the poller and 'handle'
95
// contains valid value.
98
// If true, connecter is waiting a while before trying to connect.
101
// Reference to the session we belong to.
102
zmq::session_base_t *session;
104
// Current reconnect ivl, updated for backoff strategy
105
int current_reconnect_ivl;
107
// String representation of endpoint to connect to
108
std::string endpoint;
110
tcp_connecter_t (const tcp_connecter_t&);
111
const tcp_connecter_t &operator = (const tcp_connecter_t&);