tcp_listener.hpp 2.47 KB
Newer Older
Martin Sustrik's avatar
Martin Sustrik committed
1
/*
2
    Copyright (c) 2007-2014 Contributors as noted in the AUTHORS file
Martin Sustrik's avatar
Martin Sustrik committed
3 4 5 6

    This file is part of 0MQ.

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

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

Martin Sustrik's avatar
Martin Sustrik committed
20 21
#ifndef __ZMQ_TCP_LISTENER_HPP_INCLUDED__
#define __ZMQ_TCP_LISTENER_HPP_INCLUDED__
Martin Sustrik's avatar
Martin Sustrik committed
22 23

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

Martin Sustrik's avatar
Martin Sustrik committed
30
namespace zmq
Martin Sustrik's avatar
Martin Sustrik committed
31 32
{

33 34 35
    class io_thread_t;
    class socket_base_t;

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

40 41
        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
42 43
        ~tcp_listener_t ();

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

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

    private:

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

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

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

        //  Accept the new connection. Returns the file descriptor of the
        //  newly created connection. The function may return retired_fd
64 65
        //  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
66 67
        fd_t accept ();

68
        //  Address to listen on.
69
        tcp_address_t address;
70

Martin Sustrik's avatar
Martin Sustrik committed
71 72 73
        //  Underlying socket.
        fd_t s;

74 75 76 77
        //  Handle corresponding to the listening socket.
        handle_t handle;

        //  Socket the listerner belongs to.
78
        zmq::socket_base_t *socket;
79

80 81 82
       // String representation of endpoint to bind to
        std::string endpoint;

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

}

#endif