libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
ipc_listener.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4  This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6  libzmq is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License (LGPL) as published
8  by the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  As a special exception, the Contributors give you permission to link
12  this library with independent modules to produce an executable,
13  regardless of the license terms of these independent modules, and to
14  copy and distribute the resulting executable under terms of your choice,
15  provided that you also meet, for each linked independent module, the
16  terms and conditions of the license of that module. An independent
17  module is a module which is not derived from or based on this library.
18  If you modify this library, you must extend this exception to your
19  version of the library.
20 
21  libzmq is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public License
27  along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 
30 #ifndef __ZMQ_IPC_LISTENER_HPP_INCLUDED__
31 #define __ZMQ_IPC_LISTENER_HPP_INCLUDED__
32 
33 #include "platform.hpp"
34 
35 #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
36 
37 #include <string>
38 
39 #include "fd.hpp"
40 #include "own.hpp"
41 #include "stdint.hpp"
42 #include "io_object.hpp"
43 
44 namespace zmq
45 {
46 
47  class io_thread_t;
48  class socket_base_t;
49 
50  class ipc_listener_t : public own_t, public io_object_t
51  {
52  public:
53 
54  ipc_listener_t (zmq::io_thread_t *io_thread_,
55  zmq::socket_base_t *socket_, const options_t &options_);
56  ~ipc_listener_t ();
57 
58  // Set address to listen on.
59  int set_address (const char *addr_);
60 
61  // Get the bound address for use with wildcards
62  int get_address (std::string &addr_);
63 
64  private:
65 
66  // Handlers for incoming commands.
67  void process_plug ();
68  void process_term (int linger_);
69 
70  // Handlers for I/O events.
71  void in_event ();
72 
73  // Close the listening socket.
74  int close ();
75 
76  // Create wildcard path address
77  static int create_wildcard_address(std::string& path_,
78  std::string& file_);
79 
80  // Filter new connections if the OS provides a mechanism to get
81  // the credentials of the peer process. Called from accept().
82 # if defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED
83  bool filter (fd_t sock);
84 # endif
85 
86  // Accept the new connection. Returns the file descriptor of the
87  // newly created connection. The function may return retired_fd
88  // if the connection was dropped while waiting in the listen backlog.
89  fd_t accept ();
90 
91  // True, if the underlying file for UNIX domain socket exists.
92  bool has_file;
93 
94  // Name of the temporary directory (if any) that has the
95  // the UNIX domain socket
96  std::string tmp_socket_dirname;
97 
98  // Name of the file associated with the UNIX domain address.
99  std::string filename;
100 
101  // Underlying socket.
103 
104  // Handle corresponding to the listening socket.
106 
107  // Socket the listener belongs to.
109 
110  // String representation of endpoint to bind to
111  std::string endpoint;
112 
113  // Acceptable temporary directory environment variables
114  static const char *tmp_env_vars[];
115 
118  };
119 
120 }
121 
122 #endif
123 
124 #endif
125 
int get_address(std::string &addr_)
ipc_listener_t(zmq::io_thread_t *io_thread_, zmq::socket_base_t *socket_, const options_t &options_)
zmq::socket_base_t * socket
static const char * tmp_env_vars[]
static int create_wildcard_address(std::string &path_, std::string &file_)
int set_address(const char *addr_)
std::string filename
const ipc_listener_t & operator=(const ipc_listener_t &)
void process_term(int linger_)
std::string tmp_socket_dirname
Definition: address.hpp:35
poller_t::handle_t handle_t
Definition: io_object.hpp:62