xtd 0.2.0
Loading...
Searching...
No Matches
tcp_listener.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "tcp_client.hpp"
6#include "../../threading/manual_reset_event.hpp"
7#include "../../iequatable.hpp"
8
10namespace xtd {
12 namespace net {
14 namespace sockets {
40 class core_export_ tcp_listener : public xtd::object, public xtd::iequatable<tcp_listener> {
41 class async_result_socket : public xtd::object, public xtd::iasync_result {
42 public:
43 explicit async_result_socket(std::any async_state) : async_state_(async_state) {}
44 std::any async_state() const noexcept override {return async_state_;}
45 xtd::threading::wait_handle& async_wait_handle() noexcept override {return async_event_;}
46 bool completed_synchronously() const noexcept override {return false;}
47 bool is_completed() const noexcept override {return is_completed_;};
48
49 std::any async_state_;
50 bool is_completed_ = false;
53 std::exception_ptr exception_;
54 };
55
56 class async_result_accept_socket : public async_result_socket {
57 public:
58 explicit async_result_accept_socket(std::any async_state) : async_result_socket(async_state) {}
60 };
61
62 class async_result_accept_tcp_client : public async_result_socket {
63 public:
64 explicit async_result_accept_tcp_client(std::any async_state) : async_result_socket(async_state) {}
66 };
67
68 struct data;
69
70 public:
72
81 explicit tcp_listener(const xtd::net::ip_end_point& local_end_point);
82
93
95 tcp_listener(tcp_listener&&) = default;
96 tcp_listener(const tcp_listener&) = default;
98 tcp_listener& operator =(const tcp_listener&) = default;
100
102
127
131 const xtd::net::end_point& local_end_point() const noexcept;
132
138 xtd::net::sockets::socket server() const noexcept;
140
142
153 xtd::net::sockets::socket accept_socket();
154
162 xtd::net::sockets::tcp_client accept_tcp_client();
163
174 xtd::sptr<xtd::iasync_result> begin_accept_socket(xtd::async_callback callback, const std::any& state);
175
185 xtd::sptr<xtd::iasync_result> begin_accept_tcp_client(xtd::async_callback callback, const std::any& state);
186
196 xtd::net::sockets::socket end_accept_socket(xtd::sptr<xtd::iasync_result> async_result);
197
208 xtd::net::sockets::tcp_client end_accept_tcp_client(xtd::sptr<xtd::iasync_result> async_result);
209
210 using object::equals;
211 bool equals(const tcp_listener& s) const noexcept override;
212
219 bool pending();
220
227 void start();
228
238 void start(size_t backlog);
239
245 void stop();
247
249
254 static tcp_listener create(uint16 port);
256
257 protected:
259
265 bool active() const noexcept;
267
268 private:
269 xtd::sptr<data> data_;
270 };
271 }
272 }
273}
Represents the status of an asynchronous operation.
Definition iasync_result.hpp:25
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Identifies a network address. This is an abstract class.
Definition end_point.hpp:27
Provides an Internet Protocol (IP) address.
Definition ip_address.hpp:37
Represents a network endpoint as an IP address and a port number.
Definition ip_end_point.hpp:23
Implements the Berkeley sockets interface.
Definition socket.hpp:74
Provides client connections for TCP network services.
Definition tcp_client.hpp:48
Listens for connections from TCP network clients.
Definition tcp_listener.hpp:40
bool exclusive_address_use() const
Gets a bool value that specifies whether the xtd::net::sockets::tcp_listener allows only one underlyi...
tcp_listener & exclusive_address_use(bool value)
Sets a bool value that specifies whether the xtd::net::sockets::tcp_listener allows only one underlyi...
const xtd::net::end_point & local_end_point() const noexcept
Gets the underlying xtd::net::end_point of the current xtd::net::sockets::tcp_listener.
tcp_listener(const xtd::net::ip_address &ip_address, uint16 port)
Initializes a new instance of the xtd::net::sockets::tcp_listener class that listens for incoming con...
tcp_listener(const xtd::net::ip_end_point &local_end_point)
Initializes a new instance of the xtd::net::sockets::tcp_listener class with the specified local endp...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
Represents a thread synchronization event that, when signaled, must be reset manually....
Definition manual_reset_event.hpp:35
Encapsulates operating system specific objects that wait for exclusive access to shared resources.
Definition wait_handle.hpp:52
#define core_export_
Define shared library export.
Definition core_export.hpp:13
std::shared_ptr< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
socket_error
Defines error codes for the xtd::net::sockets::socket class.
Definition socket_error.hpp:30
xtd::sptr< xtd::iasync_result > async_result
Represents the status of an asynchronous operation.
Definition async_result.hpp:19
delegate< void(async_result ar)> async_callback
References a method to be called when a corresponding asynchronous operation completes.
Definition delegate.hpp:36
@ success
Operation successful.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::net::sockets::tcp_client class.