xtd 0.2.0
tcp_listener.h
Go to the documentation of this file.
1 #pragma once
5 #include "tcp_client.h"
6 #include "../../threading/manual_reset_event.h"
7 #include "../../iequatable.h"
8 
10 namespace xtd {
12  namespace net {
14  namespace sockets {
38  class core_export_ tcp_listener : public xtd::object, public xtd::iequatable<tcp_listener> {
39  class async_result_socket : public xtd::object, public xtd::iasync_result {
40  public:
41  explicit async_result_socket(std::any async_state) : async_state_(async_state) {}
42  std::any async_state() const noexcept override {return async_state_;}
43  xtd::threading::wait_handle& async_wait_handle() noexcept override {return async_event_;}
44  bool completed_synchronously() const noexcept override {return false;}
45  bool is_completed() const noexcept override {return is_completed_;};
46 
47  std::any async_state_;
48  bool is_completed_ = false;
51  std::exception_ptr exception_;
52  };
53 
54  class async_result_accept_socket : public async_result_socket {
55  public:
56  explicit async_result_accept_socket(std::any async_state) : async_result_socket(async_state) {}
58  };
59 
60  class async_result_accept_tcp_client : public async_result_socket {
61  public:
62  explicit async_result_accept_tcp_client(std::any async_state) : async_result_socket(async_state) {}
64  };
65 
66  struct data;
67 
68  public:
70 
79  explicit tcp_listener(const xtd::net::ip_end_point& local_end_point);
80 
91 
93  tcp_listener(tcp_listener&&) = default;
94  tcp_listener(const tcp_listener&) = default;
95  ~tcp_listener();
96  tcp_listener& operator =(const tcp_listener&) = default;
98 
100 
112  bool exclusive_address_use() const;
124  tcp_listener& exclusive_address_use(bool value);
125 
129  const xtd::net::end_point& local_end_point() const noexcept;
130 
136  xtd::net::sockets::socket server() const noexcept;
138 
140 
151  xtd::net::sockets::socket accept_socket();
152 
160  xtd::net::sockets::tcp_client accept_tcp_client();
161 
172  std::shared_ptr<xtd::iasync_result> begin_accept_socket(xtd::async_callback callback, const std::any& state);
173 
183  std::shared_ptr<xtd::iasync_result> begin_accept_tcp_client(xtd::async_callback callback, const std::any& state);
184 
188  static tcp_listener create(uint16 port);
189 
199  xtd::net::sockets::socket end_accept_socket(std::shared_ptr<xtd::iasync_result> async_result);
200 
211  xtd::net::sockets::tcp_client end_accept_tcp_client(std::shared_ptr<xtd::iasync_result> async_result);
212 
213  bool equals(const tcp_listener& s) const noexcept override;
214 
221  bool pending();
222 
229  void start();
230 
240  void start(size_t backlog);
241 
247  void stop();
249 
250  protected:
252 
258  bool active() const noexcept;
260 
261  private:
262  std::shared_ptr<data> data_;
263  };
264  }
265  }
266 }
Implements the Berkeley sockets interface.
Definition: socket.h:71
Provides an Internet Protocol (IP) address.
Definition: ip_address.h:35
delegate< void(async_result ar)> async_callback
References a method to be called when a corresponding asynchronous operation completes.
Definition: delegate.h:34
Represents the status of an asynchronous operation.
Definition: iasync_result.h:22
Identifies a network address. This is an abstract class.
Definition: end_point.h:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
std::shared_ptr< xtd::iasync_result > async_result
Represents the status of an asynchronous operation.
Definition: async_result.h:16
Enables a socket to be bound for exclusive access.
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition: types.h:228
Represents a network endpoint as an IP address and a port number.
Definition: ip_end_point.h:21
socket_error
Defines error codes for the xtd::net::sockets::socket class.
Definition: socket_error.h:28
Provides client connections for TCP network services.
Definition: tcp_client.h:46
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
The xtd::uri::port data.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
Contains xtd::net::sockets::tcp_client class.
Listens for connections from TCP network clients.
Definition: tcp_listener.h:38
Represents a thread synchronization event that, when signaled, must be reset manually. This class cannot be inherited.
Definition: manual_reset_event.h:33
Encapsulates operating system specific objects that wait for exclusive access to shared resources...
Definition: wait_handle.h:48