xtd - Reference Guide 0.2.0
tcp_listener.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include "tcp_client.h"
7 
9 namespace xtd {
11  namespace net {
13  namespace sockets {
35  class core_export_ tcp_listener : public xtd::object {
36  class async_result_socket : public xtd::object, public xtd::iasync_result {
37  public:
38  explicit async_result_socket(std::any async_state) : async_state_(async_state) {}
39  std::any async_state() const noexcept override {return async_state_;}
40  std::shared_mutex& async_mutex() override {return async_mutex_;}
41  bool completed_synchronously() const noexcept override {return false;}
42  bool is_completed() const noexcept override {return is_completed_;};
43 
44  std::any async_state_;
45  bool is_completed_ = false;
46  std::shared_mutex async_mutex_;
48  std::exception_ptr exception_;
49  };
50 
51  class async_result_accept_socket : public async_result_socket {
52  public:
53  explicit async_result_accept_socket(std::any async_state) : async_result_socket(async_state) {}
55  };
56 
57  class async_result_accept_tcp_client : public async_result_socket {
58  public:
59  explicit async_result_accept_tcp_client(std::any async_state) : async_result_socket(async_state) {}
61  };
62 
63  public:
65 
74  explicit tcp_listener(const xtd::net::ip_end_point& local_end_point);
75 
86 
88  tcp_listener(tcp_listener&&) = default;
89  tcp_listener(const tcp_listener&) = default;
90  ~tcp_listener();
91  tcp_listener& operator=(const tcp_listener&) = default;
92  friend std::ostream& operator <<(std::ostream& os, const tcp_listener& tl) noexcept {return os << tl.to_string();}
93  bool operator==(const tcp_listener& s) const {return data_ == s.data_;};
94  bool operator!=(const tcp_listener& s) const {return !operator==(s);};
96 
98 
110  bool exclusive_address_use() const;
122  tcp_listener& exclusive_address_use(bool value);
123 
127  const xtd::net::end_point& local_end_point() const noexcept;
128 
134  xtd::net::sockets::socket server() const noexcept;
136 
138 
149  xtd::net::sockets::socket accept_socket();
150 
158  xtd::net::sockets::tcp_client accept_tcp_client();
159 
170  std::shared_ptr<xtd::iasync_result> begin_accept_socket(xtd::async_callback callback, const std::any& state);
171 
181  std::shared_ptr<xtd::iasync_result> begin_accept_tcp_client(xtd::async_callback callback, const std::any& state);
182 
186  static tcp_listener create(uint16_t port);
187 
197  xtd::net::sockets::socket end_accept_socket(std::shared_ptr<xtd::iasync_result> async_result);
198 
209  xtd::net::sockets::tcp_client end_accept_tcp_client(std::shared_ptr<xtd::iasync_result> async_result);
210 
217  bool pending();
218 
225  void start();
226 
236  void start(size_t backlog);
237 
243  void stop();
245 
246  protected:
248 
254  bool active() const noexcept;
256 
257  private:
258  struct data;
259  std::shared_ptr<data> data_;
260  };
261  }
262  }
263 }
Implements the Berkeley sockets interface.
Definition: socket.h:68
virtual xtd::ustring to_string() const noexcept
Returns a sxd::ustring that represents the current object.
Provides an Internet Protocol (IP) address.
Definition: ip_address.h:34
Represents the status of an asynchronous operation.
Definition: iasync_result.h:21
Identifies a network address. This is an abstract class.
Definition: end_point.h:24
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Enables a socket to be bound for exclusive access.
Represents a network endpoint as an IP address and a port number.
Definition: ip_end_point.h:20
delegate< void(std::shared_ptr< xtd::iasync_result > ar)> async_callback
References a method to be called when a corresponding asynchronous operation completes.
Definition: async_callback.h:18
socket_error
Defines error codes for the xtd::net::sockets::socket class.
Definition: socket_error.h:27
Provides client connections for TCP network services.
Definition: tcp_client.h:44
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:30
Contains xtd::net::sockets::tcp_client class.
Listens for connections from TCP network clients.
Definition: tcp_listener.h:35