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

« back to all changes in this revision

Viewing changes to src/ipc_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) 2011 250bpm s.r.o.
 
3
    Copyright (c) 2011 Other contributors as noted in the AUTHORS file
 
4
 
 
5
    This file is part of 0MQ.
 
6
 
 
7
    0MQ is free software; you can redistribute it and/or modify it under
 
8
    the terms of the GNU Lesser General Public License as published by
 
9
    the Free Software Foundation; either version 3 of the License, or
 
10
    (at your option) any later version.
 
11
 
 
12
    0MQ is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
    GNU Lesser General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU Lesser General Public License
 
18
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
#ifndef __IPC_CONNECTER_HPP_INCLUDED__
 
22
#define __IPC_CONNECTER_HPP_INCLUDED__
 
23
 
 
24
#include "platform.hpp"
 
25
 
 
26
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
 
27
 
 
28
#include "fd.hpp"
 
29
#include "own.hpp"
 
30
#include "stdint.hpp"
 
31
#include "io_object.hpp"
 
32
#include "ipc_address.hpp"
 
33
 
 
34
namespace zmq
 
35
{
 
36
 
 
37
    class io_thread_t;
 
38
    class session_base_t;
 
39
 
 
40
    class ipc_connecter_t : public own_t, public io_object_t
 
41
    {
 
42
    public:
 
43
 
 
44
        //  If 'delay' is true connecter first waits for a while, then starts
 
45
        //  connection process.
 
46
        ipc_connecter_t (zmq::io_thread_t *io_thread_,
 
47
            zmq::session_base_t *session_, const options_t &options_,
 
48
            const char *address_, bool delay_);
 
49
        ~ipc_connecter_t ();
 
50
 
 
51
    private:
 
52
 
 
53
        //  ID of the timer used to delay the reconnection.
 
54
        enum {reconnect_timer_id = 1};
 
55
 
 
56
        //  Handlers for incoming commands.
 
57
        void process_plug ();
 
58
 
 
59
        //  Handlers for I/O events.
 
60
        void in_event ();
 
61
        void out_event ();
 
62
        void timer_event (int id_);
 
63
 
 
64
        //  Internal function to start the actual connection establishment.
 
65
        void start_connecting ();
 
66
 
 
67
        //  Internal function to add a reconnect timer
 
68
        void add_reconnect_timer();
 
69
 
 
70
        //  Internal function to return a reconnect backoff delay.
 
71
        //  Will modify the current_reconnect_ivl used for next call
 
72
        //  Returns the currently used interval
 
73
        int get_new_reconnect_ivl ();
 
74
 
 
75
        //  Set address to connect to.
 
76
        int set_address (const char *addr_);
 
77
 
 
78
        //  Open TCP connecting socket. Returns -1 in case of error,
 
79
        //  0 if connect was successfull immediately and 1 if async connect
 
80
        //  was launched.
 
81
        int open ();
 
82
 
 
83
        //  Close the connecting socket.
 
84
        int close ();
 
85
 
 
86
        //  Get the file descriptor of newly created connection. Returns
 
87
        //  retired_fd if the connection was unsuccessfull.
 
88
        fd_t connect ();
 
89
 
 
90
        //  Address to connect to.
 
91
        ipc_address_t address;
 
92
 
 
93
        //  Underlying socket.
 
94
        fd_t s;
 
95
 
 
96
        //  Handle corresponding to the listening socket.
 
97
        handle_t handle;
 
98
 
 
99
        //  If true file descriptor is registered with the poller and 'handle'
 
100
        //  contains valid value.
 
101
        bool handle_valid;
 
102
 
 
103
        //  If true, connecter is waiting a while before trying to connect.
 
104
        bool wait;
 
105
 
 
106
        //  Reference to the session we belong to.
 
107
        zmq::session_base_t *session;
 
108
 
 
109
        //  Current reconnect ivl, updated for backoff strategy
 
110
        int current_reconnect_ivl;
 
111
 
 
112
        ipc_connecter_t (const ipc_connecter_t&);
 
113
        const ipc_connecter_t &operator = (const ipc_connecter_t&);
 
114
    };
 
115
 
 
116
}
 
117
 
 
118
#endif
 
119
 
 
120
#endif
 
121