tcp_listener.hpp 2.56 KB
Newer Older
Martin Sustrik's avatar
Martin Sustrik committed
1
/*
Martin Sustrik's avatar
Martin Sustrik committed
2
    Copyright (c) 2009-2011 250bpm s.r.o.
3
    Copyright (c) 2007-2010 iMatix Corporation
4
    Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
Martin Sustrik's avatar
Martin Sustrik committed
5 6 7 8

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
9
    the terms of the GNU Lesser General Public License as published by
Martin Sustrik's avatar
Martin Sustrik committed
10 11 12 13 14 15
    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
16
    GNU Lesser General Public License for more details.
Martin Sustrik's avatar
Martin Sustrik committed
17

18
    You should have received a copy of the GNU Lesser General Public License
Martin Sustrik's avatar
Martin Sustrik committed
19 20 21
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

Martin Sustrik's avatar
Martin Sustrik committed
22 23
#ifndef __ZMQ_TCP_LISTENER_HPP_INCLUDED__
#define __ZMQ_TCP_LISTENER_HPP_INCLUDED__
Martin Sustrik's avatar
Martin Sustrik committed
24 25

#include "fd.hpp"
26 27
#include "own.hpp"
#include "stdint.hpp"
28 29
#include "io_object.hpp"
#include "tcp_address.hpp"
30
#include "../include/zmq.h"
Martin Sustrik's avatar
Martin Sustrik committed
31

Martin Sustrik's avatar
Martin Sustrik committed
32
namespace zmq
Martin Sustrik's avatar
Martin Sustrik committed
33 34
{

35 36 37
    class io_thread_t;
    class socket_base_t;

38
    class tcp_listener_t : public own_t, public io_object_t
Martin Sustrik's avatar
Martin Sustrik committed
39 40 41
    {
    public:

42 43
        tcp_listener_t (zmq::io_thread_t *io_thread_,
            zmq::socket_base_t *socket_, const options_t &options_);
Martin Sustrik's avatar
Martin Sustrik committed
44 45
        ~tcp_listener_t ();

46
        //  Set address to listen on.
47
        int set_address (const char *addr_);
48

49
        // Get the bound address for use with wildcard
50
        int get_address (std::string &addr_);
51 52 53 54 55 56 57 58 59

    private:

        //  Handlers for incoming commands.
        void process_plug ();
        void process_term (int linger_);

        //  Handlers for I/O events.
        void in_event ();
60

Martin Sustrik's avatar
Martin Sustrik committed
61
        //  Close the listening socket.
62
        void close ();
Martin Sustrik's avatar
Martin Sustrik committed
63 64 65

        //  Accept the new connection. Returns the file descriptor of the
        //  newly created connection. The function may return retired_fd
66 67
        //  if the connection was dropped while waiting in the listen backlog
        //  or was denied because of accept filters.
Martin Sustrik's avatar
Martin Sustrik committed
68 69
        fd_t accept ();

70
        //  Address to listen on.
71
        tcp_address_t address;
72

Martin Sustrik's avatar
Martin Sustrik committed
73 74 75
        //  Underlying socket.
        fd_t s;

76 77 78 79
        //  Handle corresponding to the listening socket.
        handle_t handle;

        //  Socket the listerner belongs to.
80
        zmq::socket_base_t *socket;
81

82 83 84
       // String representation of endpoint to bind to
        std::string endpoint;

Martin Sustrik's avatar
Martin Sustrik committed
85
        tcp_listener_t (const tcp_listener_t&);
86
        const tcp_listener_t &operator = (const tcp_listener_t&);
Martin Sustrik's avatar
Martin Sustrik committed
87 88 89 90 91
    };

}

#endif