diff options
author | Martin Sustrik <sustrik@fastmq.commkdir> | 2009-07-29 12:07:54 +0200 |
---|---|---|
committer | Martin Sustrik <sustrik@fastmq.commkdir> | 2009-07-29 12:07:54 +0200 |
commit | 4ed70a930202b103e7e80b8dc925e0aaa4622595 (patch) | |
tree | aeed881ce17629f81b7c90f7d675aac8ecf69d4f /src/pipe_reader.hpp |
initial commit
Diffstat (limited to 'src/pipe_reader.hpp')
-rw-r--r-- | src/pipe_reader.hpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/pipe_reader.hpp b/src/pipe_reader.hpp new file mode 100644 index 0000000..bc3fd2e --- /dev/null +++ b/src/pipe_reader.hpp @@ -0,0 +1,89 @@ +/* + Copyright (c) 2007-2009 FastMQ Inc. + + 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/>. +*/ + +#ifndef __ZS_PIPE_READER_HPP_INCLUDED__ +#define __ZS_PIPE_READER_HPP_INCLUDED__ + +#include "object.hpp" +#include "stdint.hpp" + +namespace zs +{ + + class pipe_reader_t : public object_t + { + // Dispatcher is a friend so that it can create & destroy the reader. + // By making constructor & destructor private we are sure that nobody + // except dispatcher messes with readers. + friend class dispatcher_t; + + public: + + // Set & get index in the associated mux object. + void set_mux (struct i_mux *mux_); + void set_index (int index_); + int get_index (); + + // Reads a message to the underlying pipe. + bool read (struct zs_msg *msg_); + + // Asks pipe to destroy itself. + void terminate (); + + private: + + pipe_reader_t (class object_t *parent_, class pipe_t *pipe_, + uint64_t hwm_, uint64_t lwm_); + ~pipe_reader_t (); + + // Second step of reader construction. The parameter cannot be passed + // in constructor as peer object doesn't yet exist at the time. + void set_peer (class object_t *peer_); + + void process_tail (uint64_t bytes_); + void process_terminate_ack (); + + // The underlying pipe. + class pipe_t *pipe; + + // Pipe writer associated with the other side of the pipe. + class object_t *peer; + + // Associated mux object. + struct i_mux *mux; + + // Index in the associated mux object. + int index; + + // High and low watermarks for in-memory storage (in bytes). + uint64_t hwm; + uint64_t lwm; + + // Positions of head and tail of the pipe (in bytes). + uint64_t head; + uint64_t tail; + uint64_t last_sent_head; + + pipe_reader_t (const pipe_reader_t&); + void operator = (const pipe_reader_t&); + }; + +} + +#endif |