~ubuntu-branches/ubuntu/saucy/zeromq3/saucy

« back to all changes in this revision

Viewing changes to src/tcp_connecter.hpp

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2012-06-04 21:21:09 UTC
  • Revision ID: package-import@ubuntu.com-20120604212109-b7b3m0rn21o8oo2q
Tags: upstream-3.1.0~beta+dfsg
ImportĀ upstreamĀ versionĀ 3.1.0~beta+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
5
 
 
6
    This file is part of 0MQ.
 
7
 
 
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.
 
12
 
 
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.
 
17
 
 
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/>.
 
20
*/
 
21
 
 
22
#ifndef __TCP_CONNECTER_HPP_INCLUDED__
 
23
#define __TCP_CONNECTER_HPP_INCLUDED__
 
24
 
 
25
#include "fd.hpp"
 
26
#include "own.hpp"
 
27
#include "stdint.hpp"
 
28
#include "io_object.hpp"
 
29
#include "tcp_address.hpp"
 
30
 
 
31
namespace zmq
 
32
{
 
33
 
 
34
    class io_thread_t;
 
35
    class session_base_t;
 
36
 
 
37
    class tcp_connecter_t : public own_t, public io_object_t
 
38
    {
 
39
    public:
 
40
 
 
41
        //  If 'delay' is true connecter first waits for a while, then starts
 
42
        //  connection process.
 
43
        tcp_connecter_t (zmq::io_thread_t *io_thread_,
 
44
            zmq::session_base_t *session_, const options_t &options_,
 
45
            const char *address_, bool delay_);
 
46
        ~tcp_connecter_t ();
 
47
 
 
48
    private:
 
49
 
 
50
        //  ID of the timer used to delay the reconnection.
 
51
        enum {reconnect_timer_id = 1};
 
52
 
 
53
        //  Handlers for incoming commands.
 
54
        void process_plug ();
 
55
 
 
56
        //  Handlers for I/O events.
 
57
        void in_event ();
 
58
        void out_event ();
 
59
        void timer_event (int id_);
 
60
 
 
61
        //  Internal function to start the actual connection establishment.
 
62
        void start_connecting ();
 
63
 
 
64
        //  Internal function to add a reconnect timer
 
65
        void add_reconnect_timer();
 
66
 
 
67
        //  Internal function to return a reconnect backoff delay.
 
68
        //  Will modify the current_reconnect_ivl used for next call
 
69
        //  Returns the currently used interval
 
70
        int get_new_reconnect_ivl ();
 
71
 
 
72
        //  Set address to connect to.
 
73
        int set_address (const char *addr_);
 
74
 
 
75
        //  Open TCP connecting socket. Returns -1 in case of error,
 
76
        //  0 if connect was successfull immediately and 1 if async connect
 
77
        //  was launched.
 
78
        int open ();
 
79
 
 
80
        //  Close the connecting socket.
 
81
        void close ();
 
82
 
 
83
        //  Get the file descriptor of newly created connection. Returns
 
84
        //  retired_fd if the connection was unsuccessfull.
 
85
        fd_t connect ();
 
86
 
 
87
        //  Address to connect to.
 
88
        tcp_address_t address;
 
89
 
 
90
        //  Underlying socket.
 
91
        fd_t s;
 
92
 
 
93
        //  Handle corresponding to the listening socket.
 
94
        handle_t handle;
 
95
 
 
96
        //  If true file descriptor is registered with the poller and 'handle'
 
97
        //  contains valid value.
 
98
        bool handle_valid;
 
99
 
 
100
        //  If true, connecter is waiting a while before trying to connect.
 
101
        bool wait;
 
102
 
 
103
        //  Reference to the session we belong to.
 
104
        zmq::session_base_t *session;
 
105
 
 
106
        //  Current reconnect ivl, updated for backoff strategy
 
107
        int current_reconnect_ivl;
 
108
 
 
109
        tcp_connecter_t (const tcp_connecter_t&);
 
110
        const tcp_connecter_t &operator = (const tcp_connecter_t&);
 
111
    };
 
112
 
 
113
}
 
114
 
 
115
#endif