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

4
    This file is part of libzmq, the ZeroMQ core engine in C++.
Martin Sustrik's avatar
Martin Sustrik committed
5

6 7 8
    libzmq is free software; you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License (LGPL) as published
    by the Free Software Foundation; either version 3 of the License, or
Martin Sustrik's avatar
Martin Sustrik committed
9 10
    (at your option) any later version.

11 12 13 14 15 16 17 18 19 20 21 22 23 24
    As a special exception, the Contributors give you permission to link
    this library with independent modules to produce an executable,
    regardless of the license terms of these independent modules, and to
    copy and distribute the resulting executable under terms of your choice,
    provided that you also meet, for each linked independent module, the
    terms and conditions of the license of that module. An independent
    module is a module which is not derived from or based on this library.
    If you modify this library, you must extend this exception to your
    version of the library.

    libzmq 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 GNU Lesser General Public
    License for more details.
Martin Sustrik's avatar
Martin Sustrik committed
25

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

Martin Sustrik's avatar
Martin Sustrik committed
30 31
#ifndef __ZMQ_TCP_LISTENER_HPP_INCLUDED__
#define __ZMQ_TCP_LISTENER_HPP_INCLUDED__
Martin Sustrik's avatar
Martin Sustrik committed
32 33

#include "fd.hpp"
34 35
#include "own.hpp"
#include "stdint.hpp"
36 37
#include "io_object.hpp"
#include "tcp_address.hpp"
38
#include "../include/zmq.h"
Martin Sustrik's avatar
Martin Sustrik committed
39

Martin Sustrik's avatar
Martin Sustrik committed
40
namespace zmq
Martin Sustrik's avatar
Martin Sustrik committed
41 42
{

43 44 45
    class io_thread_t;
    class socket_base_t;

46
    class tcp_listener_t : public own_t, public io_object_t
Martin Sustrik's avatar
Martin Sustrik committed
47 48 49
    {
    public:

50 51
        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
52 53
        ~tcp_listener_t ();

54
        //  Set address to listen on.
55
        int set_address (const char *addr_);
56

57
        // Get the bound address for use with wildcard
58
        int get_address (std::string &addr_);
59 60 61 62 63 64 65 66 67

    private:

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

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

Martin Sustrik's avatar
Martin Sustrik committed
69
        //  Close the listening socket.
70
        void close ();
Martin Sustrik's avatar
Martin Sustrik committed
71 72 73

        //  Accept the new connection. Returns the file descriptor of the
        //  newly created connection. The function may return retired_fd
74 75
        //  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
76 77
        fd_t accept ();

78
        //  Address to listen on.
79
        tcp_address_t address;
80

Martin Sustrik's avatar
Martin Sustrik committed
81 82 83
        //  Underlying socket.
        fd_t s;

84 85 86
        //  Handle corresponding to the listening socket.
        handle_t handle;

87
        //  Socket the listener belongs to.
88
        zmq::socket_base_t *socket;
89

90 91 92
       // String representation of endpoint to bind to
        std::string endpoint;

Martin Sustrik's avatar
Martin Sustrik committed
93
        tcp_listener_t (const tcp_listener_t&);
94
        const tcp_listener_t &operator = (const tcp_listener_t&);
Martin Sustrik's avatar
Martin Sustrik committed
95 96 97 98 99
    };

}

#endif