LIBWIRE
Next-generation C++17 networking library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
listener.hpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2018 Max Mazurov (fox.cpp) <fox.cpp [at] disroot [dot] org>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 
23 #pragma once
24 
25 #include <libwire/tcp/socket.hpp>
26 
27 /*
28  * If you had to open this file to find answer for your question - we are so
29  * sorry. Please open issue with your question so we can update documentation
30  * to answer it.
31  */
32 
33 namespace libwire::tcp {
51  class listener {
52  public:
58  listener() noexcept = default;
59 
60  listener(const listener&) = delete;
61  listener(listener&&) noexcept = default;
62 
63  listener& operator=(const listener&) = delete;
64  listener& operator=(listener&&) noexcept = default;
65 
66  ~listener() = default;
67 
72  inline listener(endpoint target, std::error_code& ec,
73  unsigned backlog = internal_::socket::max_pending_connections) noexcept {
74  listen(target, ec, backlog);
75  }
76 
77  inline listener(endpoint target, unsigned backlog = internal_::socket::max_pending_connections) {
78  listen(target, backlog);
79  }
80 
94  void listen(endpoint target, std::error_code& ec,
95  unsigned max_backlog = internal_::socket::max_pending_connections) noexcept;
96 
104  socket accept(std::error_code& ec) noexcept;
105 
106 #ifdef __cpp_exceptions
107 
111  socket accept();
112 
117  void listen(endpoint target, unsigned max_backlog = internal_::socket::max_pending_connections);
118 #endif // ifdef __cpp_exceptions
119 
120  private:
121  internal_::socket implementation;
122  };
123 } // namespace libwire::tcp
Restricted wrapper for TCP listening socket.
Definition: listener.hpp:51
listener(endpoint target, std::error_code &ec, unsigned backlog=internal_::socket::max_pending_connections) noexcept
Construct listener and start accepting connections.
Definition: listener.hpp:72
listener() noexcept=default
Construct listener object.
listener(endpoint target, unsigned backlog=internal_::socket::max_pending_connections)
Definition: listener.hpp:77
socket accept(std::error_code &ec) noexcept
Accept first connection from listener queue and create socket for it.
This file defines tcp::socket type, base class for outgoing TCP connections.
Descriptor wrapper for TCP socket.
Definition: socket.hpp:59
void listen(endpoint target, std::error_code &ec, unsigned max_backlog=internal_::socket::max_pending_connections) noexcept
Start listening for incoming connections on specified endpoint.
listener & operator=(const listener &)=delete