xtd 0.2.0
Loading...
Searching...
No Matches
tcp_listener.h
Go to the documentation of this file.
1
4#pragma once
5#include "tcp_client.h"
6#include "../../threading/manual_reset_event.h"
7#include "../../iequatable.h"
8
10namespace 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;
96 tcp_listener& operator =(const tcp_listener&) = default;
98
100
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
194 xtd::net::sockets::socket end_accept_socket(std::shared_ptr<xtd::iasync_result> async_result);
195
206 xtd::net::sockets::tcp_client end_accept_tcp_client(std::shared_ptr<xtd::iasync_result> async_result);
207
208 bool equals(const tcp_listener& s) const noexcept override;
209
216 bool pending();
217
224 void start();
225
235 void start(size_t backlog);
236
242 void stop();
244
246
251 static tcp_listener create(uint16 port);
253
254 protected:
256
262 bool active() const noexcept;
264
265 private:
266 std::shared_ptr<data> data_;
267 };
268 }
269 }
270}
Represents the status of an asynchronous operation.
Definition iasync_result.h:22
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:18
Identifies a network address. This is an abstract class.
Definition end_point.h:25
Provides an Internet Protocol (IP) address.
Definition ip_address.h:35
Represents a network endpoint as an IP address and a port number.
Definition ip_end_point.h:21
Implements the Berkeley sockets interface.
Definition socket.h:71
Provides client connections for TCP network services.
Definition tcp_client.h:46
Listens for connections from TCP network clients.
Definition tcp_listener.h:38
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.h:32
Represents a thread synchronization event that, when signaled, must be reset manually....
Definition manual_reset_event.h:33
Encapsulates operating system specific objects that wait for exclusive access to shared resources.
Definition wait_handle.h:50
#define core_export_
Define shared library export.
Definition core_export.h:13
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition types.h:230
socket_error
Defines error codes for the xtd::net::sockets::socket class.
Definition socket_error.h:28
std::shared_ptr< xtd::iasync_result > async_result
Represents the status of an asynchronous operation.
Definition async_result.h:16
delegate< void(async_result ar)> async_callback
References a method to be called when a corresponding asynchronous operation completes.
Definition delegate.h:34
@ success
Operation successful.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::net::sockets::tcp_client class.