1 /* 2 Copyright (c) 2007-2011 iMatix Corporation 3 Copyright (c) 2007-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 __ZMQ_FQ_HPP_INCLUDED__ 22 #define __ZMQ_FQ_HPP_INCLUDED__ 23 24 #include "array.hpp" 25 #include "pipe.hpp" 26 27 namespace zmq 28 { 29 30 // Class manages a set of inbound pipes. On receive it performs fair 31 // queueing (RFC970) so that senders gone berserk won't cause denial of 32 // service for decent senders. 33 class fq_t : public i_reader_events 34 { 35 public: 36 37 fq_t (class own_t *sink_); 38 ~fq_t (); 39 40 void attach (reader_t *pipe_); 41 void terminate (); 42 43 int recv (zmq_msg_t *msg_, int flags_); 44 bool has_in (); 45 46 // i_reader_events implementation. 47 void activated (reader_t *pipe_); 48 void terminated (reader_t *pipe_); 49 void delimited (reader_t *pipe_); 50 51 private: 52 53 // Inbound pipes. 54 typedef array_t <reader_t> pipes_t; 55 pipes_t pipes; 56 57 // Number of active pipes. All the active pipes are located at the 58 // beginning of the pipes array. 59 pipes_t::size_type active; 60 61 // Index of the next bound pipe to read a message from. 62 pipes_t::size_type current; 63 64 // If true, part of a multipart message was already received, but 65 // there are following parts still waiting in the current pipe. 66 bool more; 67 68 // Object to send events to. 69 class own_t *sink; 70 71 // If true, termination process is already underway. 72 bool terminating; 73 74 fq_t (const fq_t&); 75 const fq_t &operator = (const fq_t&); 76 }; 77 78 } 79 80 #endif 81