1 | /* |
2 | Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file |
3 | |
4 | This file is part of libzmq, the ZeroMQ core engine in C++. |
5 | |
6 | libzmq is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU Lesser General Public License (LGPL) as published |
8 | by the Free Software Foundation; either version 3 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | As a special exception, the Contributors give you permission to link |
12 | this library with independent modules to produce an executable, |
13 | regardless of the license terms of these independent modules, and to |
14 | copy and distribute the resulting executable under terms of your choice, |
15 | provided that you also meet, for each linked independent module, the |
16 | terms and conditions of the license of that module. An independent |
17 | module is a module which is not derived from or based on this library. |
18 | If you modify this library, you must extend this exception to your |
19 | version of the library. |
20 | |
21 | libzmq is distributed in the hope that it will be useful, but WITHOUT |
22 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
23 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
24 | License for more details. |
25 | |
26 | You should have received a copy of the GNU Lesser General Public License |
27 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
28 | */ |
29 | |
30 | #ifndef __ZMQ_FQ_HPP_INCLUDED__ |
31 | #define __ZMQ_FQ_HPP_INCLUDED__ |
32 | |
33 | #include "array.hpp" |
34 | #include "blob.hpp" |
35 | |
36 | namespace zmq |
37 | { |
38 | class msg_t; |
39 | class pipe_t; |
40 | |
41 | // Class manages a set of inbound pipes. On receive it performs fair |
42 | // queueing so that senders gone berserk won't cause denial of |
43 | // service for decent senders. |
44 | |
45 | class fq_t |
46 | { |
47 | public: |
48 | fq_t (); |
49 | ~fq_t (); |
50 | |
51 | void attach (pipe_t *pipe_); |
52 | void activated (pipe_t *pipe_); |
53 | void pipe_terminated (pipe_t *pipe_); |
54 | |
55 | int recv (msg_t *msg_); |
56 | int recvpipe (msg_t *msg_, pipe_t **pipe_); |
57 | bool has_in (); |
58 | |
59 | private: |
60 | // Inbound pipes. |
61 | typedef array_t<pipe_t, 1> pipes_t; |
62 | pipes_t _pipes; |
63 | |
64 | // Number of active pipes. All the active pipes are located at the |
65 | // beginning of the pipes array. |
66 | pipes_t::size_type _active; |
67 | |
68 | // Pointer to the last pipe we received message from. |
69 | // NULL when no message has been received or the pipe |
70 | // has terminated. |
71 | pipe_t *_last_in; |
72 | |
73 | // Index of the next bound pipe to read a message from. |
74 | pipes_t::size_type _current; |
75 | |
76 | // If true, part of a multipart message was already received, but |
77 | // there are following parts still waiting in the current pipe. |
78 | bool _more; |
79 | |
80 | ZMQ_NON_COPYABLE_NOR_MOVABLE (fq_t) |
81 | }; |
82 | } |
83 | |
84 | #endif |
85 | |