2009-09-21 14:39:59 +02:00
|
|
|
/*
|
2010-01-05 08:29:35 +01:00
|
|
|
Copyright (c) 2007-2010 iMatix Corporation
|
2009-09-21 14:39:59 +02:00
|
|
|
|
|
|
|
This file is part of 0MQ.
|
|
|
|
|
|
|
|
0MQ is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the Lesser GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
0MQ is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
Lesser GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the Lesser GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-11-24 11:23:10 +01:00
|
|
|
#ifndef __ZMQ_REQ_HPP_INCLUDED__
|
|
|
|
#define __ZMQ_REQ_HPP_INCLUDED__
|
2009-09-21 14:39:59 +02:00
|
|
|
|
|
|
|
#include "socket_base.hpp"
|
|
|
|
#include "yarray.hpp"
|
2010-08-06 17:49:37 +02:00
|
|
|
#include "pipe.hpp"
|
2009-09-21 14:39:59 +02:00
|
|
|
|
|
|
|
namespace zmq
|
|
|
|
{
|
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
class req_t :
|
|
|
|
public socket_base_t,
|
|
|
|
public i_reader_events,
|
|
|
|
public i_writer_events
|
2009-09-21 14:39:59 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
req_t (class ctx_t *parent_, uint32_t slot_);
|
2009-09-21 14:39:59 +02:00
|
|
|
~req_t ();
|
|
|
|
|
|
|
|
// Overloads of functions from socket_base_t.
|
2010-08-06 17:49:37 +02:00
|
|
|
void xattach_pipes (reader_t *inpipe_, writer_t *outpipe_,
|
2010-02-16 18:30:38 +01:00
|
|
|
const blob_t &peer_identity_);
|
2010-08-06 17:49:37 +02:00
|
|
|
void xterm_pipes ();
|
|
|
|
bool xhas_pipes ();
|
2009-09-23 10:22:54 +02:00
|
|
|
int xsend (zmq_msg_t *msg_, int flags_);
|
|
|
|
int xrecv (zmq_msg_t *msg_, int flags_);
|
2009-10-01 10:56:17 +02:00
|
|
|
bool xhas_in ();
|
|
|
|
bool xhas_out ();
|
2009-09-21 14:39:59 +02:00
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
// i_reader_events interface implementation.
|
|
|
|
void activated (reader_t *pipe_);
|
|
|
|
void terminated (reader_t *pipe_);
|
|
|
|
|
|
|
|
// i_writer_events interface implementation.
|
|
|
|
void activated (writer_t *pipe_);
|
|
|
|
void terminated (writer_t *pipe_);
|
|
|
|
|
2009-09-21 14:39:59 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
// List in outbound and inbound pipes. Note that the two lists are
|
|
|
|
// always in sync. I.e. outpipe with index N communicates with the
|
|
|
|
// same session as inpipe with index N.
|
|
|
|
//
|
|
|
|
// TODO: Once we have queue limits in place, list of active outpipes
|
|
|
|
// is to be held (presumably by stacking active outpipes at
|
|
|
|
// the beginning of the array). We don't have to do the same thing for
|
|
|
|
// inpipes, because we know which pipe we want to read the
|
|
|
|
// reply from.
|
2010-08-06 17:49:37 +02:00
|
|
|
typedef yarray_t <writer_t> out_pipes_t;
|
2009-09-21 14:39:59 +02:00
|
|
|
out_pipes_t out_pipes;
|
2010-08-06 17:49:37 +02:00
|
|
|
typedef yarray_t <reader_t> in_pipes_t;
|
2009-09-21 14:39:59 +02:00
|
|
|
in_pipes_t in_pipes;
|
|
|
|
|
2010-03-02 22:23:34 +01:00
|
|
|
// Number of active pipes.
|
|
|
|
size_t active;
|
|
|
|
|
2009-09-21 14:39:59 +02:00
|
|
|
// Req_t load-balances the requests - 'current' points to the session
|
|
|
|
// that's processing the request at the moment.
|
|
|
|
out_pipes_t::size_type current;
|
|
|
|
|
2010-03-27 14:24:57 +01:00
|
|
|
// If true, request was already sent and reply wasn't received yet or
|
|
|
|
// was raceived partially.
|
|
|
|
bool receiving_reply;
|
2009-09-21 14:39:59 +02:00
|
|
|
|
|
|
|
// True, if read can be attempted from the reply pipe.
|
|
|
|
bool reply_pipe_active;
|
|
|
|
|
2010-03-27 14:24:57 +01:00
|
|
|
// True, if message processed at the moment (either sent or received)
|
|
|
|
// is processed only partially.
|
2010-03-27 21:25:40 +01:00
|
|
|
bool more;
|
2010-03-27 14:24:57 +01:00
|
|
|
|
2009-09-21 14:39:59 +02:00
|
|
|
// Pipe we are awaiting the reply from.
|
2010-08-06 17:49:37 +02:00
|
|
|
reader_t *reply_pipe;
|
2009-09-21 14:39:59 +02:00
|
|
|
|
|
|
|
req_t (const req_t&);
|
|
|
|
void operator = (const req_t&);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|