dealer.hpp 2.46 KB
Newer Older
1
/*
Martin Sustrik's avatar
Martin Sustrik committed
2
    Copyright (c) 2009-2011 250bpm s.r.o.
3 4
    Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file

5 6 7
    This file is part of 0MQ.

    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 10 11 12 13 14
    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
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 19 20
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

21 22
#ifndef __ZMQ_DEALER_HPP_INCLUDED__
#define __ZMQ_DEALER_HPP_INCLUDED__
23 24

#include "socket_base.hpp"
25
#include "session_base.hpp"
26 27
#include "fq.hpp"
#include "lb.hpp"
28 29 30 31

namespace zmq
{

32 33 34 35 36 37
    class ctx_t;
    class msg_t;
    class pipe_t;
    class io_thread_t;
    class socket_base_t;

38
    class dealer_t :
39
        public socket_base_t
40 41 42
    {
    public:

43 44
        dealer_t (zmq::ctx_t *parent_, uint32_t tid_, int sid);
        ~dealer_t ();
45

46 47
    protected:

48
        //  Overloads of functions from socket_base_t.
49
        void xattach_pipe (zmq::pipe_t *pipe_, bool icanhasall_);
50 51
        int xsend (zmq::msg_t *msg_, int flags_);
        int xrecv (zmq::msg_t *msg_, int flags_);
52 53
        bool xhas_in ();
        bool xhas_out ();
54 55 56
        void xread_activated (zmq::pipe_t *pipe_);
        void xwrite_activated (zmq::pipe_t *pipe_);
        void xterminated (zmq::pipe_t *pipe_);
57 58 59

    private:

60 61 62 63 64
        //  Messages are fair-queued from inbound pipes. And load-balanced to
        //  the outbound pipes.
        fq_t fq;
        lb_t lb;

65 66 67 68 69 70
        //  Have we prefetched a message.
        bool prefetched;

        //  Holds the prefetched message.
        msg_t prefetched_msg;

71 72
        dealer_t (const dealer_t&);
        const dealer_t &operator = (const dealer_t&);
73 74
    };

75
    class dealer_session_t : public session_base_t
76 77 78
    {
    public:

79
        dealer_session_t (zmq::io_thread_t *io_thread_, bool connect_,
80
            zmq::socket_base_t *socket_, const options_t &options_,
81
            const address_t *addr_);
82
        ~dealer_session_t ();
83 84 85

    private:

86 87
        dealer_session_t (const dealer_session_t&);
        const dealer_session_t &operator = (const dealer_session_t&);
88 89
    };

90 91 92
}

#endif