2
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
4
This file is part of 0MQ.
6
0MQ is free software; you can redistribute it and/or modify it under
7
the terms of the GNU Lesser General Public License as published by
8
the Free Software Foundation; either version 3 of the License, or
9
(at your option) any later version.
11
0MQ is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#ifndef __ZMQ_SESSION_BASE_HPP_INCLUDED__
21
#define __ZMQ_SESSION_BASE_HPP_INCLUDED__
27
#include "io_object.hpp"
29
#include "socket_base.hpp"
40
class session_base_t :
47
// Create a session of the particular type.
48
static session_base_t *create (zmq::io_thread_t *io_thread_,
49
bool connect_, zmq::socket_base_t *socket_,
50
const options_t &options_, const address_t *addr_);
52
// To be used once only, when creating the session.
53
void attach_pipe (zmq::pipe_t *pipe_);
55
// Following functions are the interface exposed towards the engine.
56
virtual void reset ();
60
// i_pipe_events interface implementation.
61
void read_activated (zmq::pipe_t *pipe_);
62
void write_activated (zmq::pipe_t *pipe_);
63
void hiccuped (zmq::pipe_t *pipe_);
64
void pipe_terminated (zmq::pipe_t *pipe_);
66
// Delivers a message. Returns 0 if successful; -1 otherwise.
67
// The function takes ownership of the message.
68
int push_msg (msg_t *msg_);
72
// Fetches a message. Returns 0 if successful; -1 otherwise.
73
// The caller is responsible for freeing the message when no
75
int pull_msg (msg_t *msg_);
77
// Receives message from ZAP socket.
78
// Returns 0 on success; -1 otherwise.
79
// The caller is responsible for freeing the message.
80
int read_zap_msg (msg_t *msg_);
82
// Sends message to ZAP socket.
83
// Returns 0 on success; -1 otherwise.
84
// The function takes ownership of the message.
85
int write_zap_msg (msg_t *msg_);
87
socket_base_t *get_socket ();
91
session_base_t (zmq::io_thread_t *io_thread_, bool connect_,
92
zmq::socket_base_t *socket_, const options_t &options_,
93
const address_t *addr_);
94
virtual ~session_base_t ();
98
void start_connecting (bool wait_);
102
// Handlers for incoming commands.
103
void process_plug ();
104
void process_attach (zmq::i_engine *engine_);
105
void process_term (int linger_);
107
// i_poll_events handlers.
108
void timer_event (int id_);
110
// Remove any half processed messages. Flush unflushed messages.
111
// Call this function when engine disconnect to get rid of leftovers.
114
// Call this function to move on with the delayed process_term.
115
void proceed_with_term ();
117
// If true, this session (re)connects to the peer. Otherwise, it's
118
// a transient session created by the listener.
121
// Pipe connecting the session to its socket.
124
// Pipe used to exchange messages with ZAP socket.
125
zmq::pipe_t *zap_pipe;
127
// This set is added to with pipes we are disconnecting, but haven't yet completed
128
std::set <pipe_t *> terminating_pipes;
130
// This flag is true if the remainder of the message being processed
131
// is still in the in pipe.
134
// True if termination have been suspended to push the pending
135
// messages to the network.
138
// The protocol I/O engine connected to the session.
139
zmq::i_engine *engine;
141
// The socket the session belongs to.
142
zmq::socket_base_t *socket;
144
// I/O thread the session is living in. It will be used to plug in
145
// the engines into the same thread.
146
zmq::io_thread_t *io_thread;
148
// ID of the linger timer
149
enum {linger_timer_id = 0x20};
151
// True is linger timer is running.
152
bool has_linger_timer;
154
// Protocol and address to use when connecting.
155
const address_t *addr;
157
session_base_t (const session_base_t&);
158
const session_base_t &operator = (const session_base_t&);