libzmq master
The Intelligent Transport Layer

ipc_connecter.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2011 250bpm s.r.o.
00003     Copyright (c) 2011 Other contributors as noted in the AUTHORS file
00004 
00005     This file is part of 0MQ.
00006 
00007     0MQ is free software; you can redistribute it and/or modify it under
00008     the terms of the GNU Lesser General Public License as published by
00009     the Free Software Foundation; either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     0MQ is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #ifndef __IPC_CONNECTER_HPP_INCLUDED__
00022 #define __IPC_CONNECTER_HPP_INCLUDED__
00023 
00024 #include "platform.hpp"
00025 
00026 #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
00027 
00028 #include "fd.hpp"
00029 #include "own.hpp"
00030 #include "stdint.hpp"
00031 #include "io_object.hpp"
00032 #include "ipc_address.hpp"
00033 
00034 namespace zmq
00035 {
00036 
00037     class ipc_connecter_t : public own_t, public io_object_t
00038     {
00039     public:
00040 
00041         //  If 'delay' is true connecter first waits for a while, then starts
00042         //  connection process.
00043         ipc_connecter_t (class io_thread_t *io_thread_,
00044             class session_base_t *session_, const options_t &options_,
00045             const char *address_, bool delay_);
00046         ~ipc_connecter_t ();
00047 
00048     private:
00049 
00050         //  ID of the timer used to delay the reconnection.
00051         enum {reconnect_timer_id = 1};
00052 
00053         //  Handlers for incoming commands.
00054         void process_plug ();
00055 
00056         //  Handlers for I/O events.
00057         void in_event ();
00058         void out_event ();
00059         void timer_event (int id_);
00060 
00061         //  Internal function to start the actual connection establishment.
00062         void start_connecting ();
00063 
00064         //  Internal function to add a reconnect timer
00065         void add_reconnect_timer();
00066 
00067         //  Internal function to return a reconnect backoff delay.
00068         //  Will modify the current_reconnect_ivl used for next call
00069         //  Returns the currently used interval
00070         int get_new_reconnect_ivl ();
00071 
00072         //  Set address to connect to.
00073         int set_address (const char *addr_);
00074 
00075         //  Open TCP connecting socket. Returns -1 in case of error,
00076         //  0 if connect was successfull immediately and 1 if async connect
00077         //  was launched.
00078         int open ();
00079 
00080         //  Close the connecting socket.
00081         int close ();
00082 
00083         //  Get the file descriptor of newly created connection. Returns
00084         //  retired_fd if the connection was unsuccessfull.
00085         fd_t connect ();
00086 
00087         //  Address to connect to.
00088         ipc_address_t address;
00089 
00090         //  Underlying socket.
00091         fd_t s;
00092 
00093         //  Handle corresponding to the listening socket.
00094         handle_t handle;
00095 
00096         //  If true file descriptor is registered with the poller and 'handle'
00097         //  contains valid value.
00098         bool handle_valid;
00099 
00100         //  If true, connecter is waiting a while before trying to connect.
00101         bool wait;
00102 
00103         //  Reference to the session we belong to.
00104         class session_base_t *session;
00105 
00106         //  Current reconnect ivl, updated for backoff strategy
00107         int current_reconnect_ivl;
00108 
00109         ipc_connecter_t (const ipc_connecter_t&);
00110         const ipc_connecter_t &operator = (const ipc_connecter_t&);
00111     };
00112 
00113 }
00114 
00115 #endif
00116 
00117 #endif
00118 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines