![]() |
libzmq master
The Intelligent Transport Layer
|
00001 /* 00002 Copyright (c) 2011 250bpm s.r.o. 00003 Copyright (c) 2011 Other contributors as noted in the AUTHORS file 00004 00005 This file is part of 0MQ. 00006 00007 0MQ is free software; you can redistribute it and/or modify it under 00008 the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 0MQ is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #ifndef __ZMQ_DIST_HPP_INCLUDED__ 00022 #define __ZMQ_DIST_HPP_INCLUDED__ 00023 00024 #include <vector> 00025 00026 #include "array.hpp" 00027 #include "pipe.hpp" 00028 00029 namespace zmq 00030 { 00031 00032 // Class manages a set of outbound pipes. It sends each messages to 00033 // each of them. 00034 class dist_t 00035 { 00036 public: 00037 00038 dist_t (); 00039 ~dist_t (); 00040 00041 // Adds the pipe to the distributor object. 00042 void attach (class pipe_t *pipe_); 00043 00044 // Activates pipe that have previously reached high watermark. 00045 void activated (class pipe_t *pipe_); 00046 00047 // Mark the pipe as matching. Subsequent call to send_to_matching 00048 // will send message also to this pipe. 00049 void match (class pipe_t *pipe_); 00050 00051 // Mark all pipes as non-matching. 00052 void unmatch (); 00053 00054 // Removes the pipe from the distributor object. 00055 void terminated (class pipe_t *pipe_); 00056 00057 // Send the message to the matching outbound pipes. 00058 int send_to_matching (class msg_t *msg_, int flags_); 00059 00060 // Send the message to all the outbound pipes. 00061 int send_to_all (class msg_t *msg_, int flags_); 00062 00063 bool has_out (); 00064 00065 private: 00066 00067 // Write the message to the pipe. Make the pipe inactive if writing 00068 // fails. In such a case false is returned. 00069 bool write (class pipe_t *pipe_, class msg_t *msg_); 00070 00071 // Put the message to all active pipes. 00072 void distribute (class msg_t *msg_, int flags_); 00073 00074 // List of outbound pipes. 00075 typedef array_t <class pipe_t, 2> pipes_t; 00076 pipes_t pipes; 00077 00078 // Number of all the pipes to send the next message to. 00079 pipes_t::size_type matching; 00080 00081 // Number of active pipes. All the active pipes are located at the 00082 // beginning of the pipes array. These are the pipes the messages 00083 // can be sent to at the moment. 00084 pipes_t::size_type active; 00085 00086 // Number of pipes eligible for sending messages to. This includes all 00087 // the active pipes plus all the pipes that we can in theory send 00088 // messages to (the HWM is not yet reached), but sending a message 00089 // to them would result in partial message being delivered, ie. message 00090 // with initial parts missing. 00091 pipes_t::size_type eligible; 00092 00093 // True if last we are in the middle of a multipart message. 00094 bool more; 00095 00096 dist_t (const dist_t&); 00097 const dist_t &operator = (const dist_t&); 00098 }; 00099 00100 } 00101 00102 #endif