libzmq master
The Intelligent Transport Layer

mailbox.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2009-2011 250bpm s.r.o.
00003     Copyright (c) 2007-2009 iMatix Corporation
00004     Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
00005 
00006     This file is part of 0MQ.
00007 
00008     0MQ is free software; you can redistribute it and/or modify it under
00009     the terms of the GNU Lesser General Public License as published by
00010     the Free Software Foundation; either version 3 of the License, or
00011     (at your option) any later version.
00012 
00013     0MQ is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public License
00019     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #ifndef __ZMQ_MAILBOX_HPP_INCLUDED__
00023 #define __ZMQ_MAILBOX_HPP_INCLUDED__
00024 
00025 #include <stddef.h>
00026 
00027 #include "platform.hpp"
00028 #include "signaler.hpp"
00029 #include "fd.hpp"
00030 #include "config.hpp"
00031 #include "command.hpp"
00032 #include "ypipe.hpp"
00033 #include "mutex.hpp"
00034 
00035 namespace zmq
00036 {
00037 
00038     class mailbox_t
00039     {
00040     public:
00041 
00042         mailbox_t ();
00043         ~mailbox_t ();
00044 
00045         fd_t get_fd ();
00046         void send (const command_t &cmd_);
00047         int recv (command_t *cmd_, int timeout_);
00048         
00049     private:
00050 
00051         //  The pipe to store actual commands.
00052         typedef ypipe_t <command_t, command_pipe_granularity> cpipe_t;
00053         cpipe_t cpipe;
00054 
00055         //  Signaler to pass signals from writer thread to reader thread.
00056         signaler_t signaler;
00057 
00058         //  There's only one thread receiving from the mailbox, but there
00059         //  is arbitrary number of threads sending. Given that ypipe requires
00060         //  synchronised access on both of its endpoints, we have to synchronise
00061         //  the sending side.
00062         mutex_t sync;
00063 
00064         //  True if the underlying pipe is active, ie. when we are allowed to
00065         //  read commands from it.
00066         bool active;
00067 
00068         //  Disable copying of mailbox_t object.
00069         mailbox_t (const mailbox_t&);
00070         const mailbox_t &operator = (const mailbox_t&);
00071     };
00072 
00073 }
00074 
00075 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines