7 #include "../../core_export.h" 8 #include "../../argument_exception.h" 9 #include "../../async_callback.h" 10 #include "../../iasync_result.h" 11 #include "../../iequatable.h" 12 #include "../../not_implemented_exception.h" 13 #include "../../not_supported_exception.h" 14 #include "../../object.h" 15 #include "../../types.h" 16 #include "../../ustring.h" 17 #include "../end_point.h" 18 #include "../ip_address.h" 43 class socket_async_event_args;
73 explicit async_result_socket(
std::any async_state) : async_state_(async_state) {}
74 std::any async_state()
const noexcept
override {
return async_state_;}
75 std::shared_mutex& async_mutex()
override {
return async_mutex_;}
76 bool completed_synchronously()
const noexcept
override {
return false;}
77 bool is_completed()
const noexcept
override {
return is_completed_;};
80 bool is_completed_ =
false;
81 std::shared_mutex async_mutex_;
83 std::exception_ptr exception_;
87 class async_result_accept :
public async_result_socket {
89 explicit async_result_accept(
std::any async_state) : async_result_socket(async_state) {}
94 class async_result_connect :
public async_result_socket {
96 explicit async_result_connect(
std::any async_state) : async_result_socket(async_state) {}
100 class async_result_disconnect :
public async_result_socket {
102 explicit async_result_disconnect(
std::any async_state) : async_result_socket(async_state) {}
106 class async_result_receive :
public async_result_socket {
108 explicit async_result_receive(
std::any async_state) : async_result_socket(async_state) {}
109 size_t number_of_bytes_received_ = 0;
113 class async_result_receive_from :
public async_result_socket {
115 explicit async_result_receive_from(
std::any async_state) : async_result_socket(async_state) {}
116 std::shared_ptr<xtd::net::end_point> end_point_;
117 size_t number_of_bytes_received_ = 0;
121 class async_result_receive_message_from :
public async_result_socket {
123 explicit async_result_receive_message_from(
std::any async_state) : async_result_socket(async_state) {}
124 std::shared_ptr<xtd::net::end_point> end_point_;
126 size_t number_of_bytes_received_ = 0;
131 class async_result_send :
public async_result_socket {
133 explicit async_result_send(
std::any async_state) : async_result_socket(async_state) {}
134 size_t number_of_bytes_sent_ = 0;
138 class async_result_send_to :
public async_result_socket {
140 explicit async_result_send_to(
std::any async_state) : async_result_socket(async_state) {}
141 size_t number_of_bytes_sent_ = 0;
198 size_t available()
const;
207 bool blocking()
const;
216 socket& blocking(
bool value);
247 bool dual_mode()
const;
255 socket& dual_mode(
bool value);
264 bool enable_broadcast()
const;
273 socket& enable_broadcast(
bool value);
298 intptr handle()
const noexcept;
303 bool is_bound()
const noexcept;
348 std::shared_ptr<xtd::net::end_point> local_end_point()
const;
393 static bool os_supports_ip_v4() noexcept;
398 static bool os_supports_ip_v6() noexcept;
411 size_t receive_buffer_size()
const;
419 socket& receive_buffer_size(
size_t value);
443 std::shared_ptr<xtd::net::end_point> remote_end_point()
const;
451 size_t send_buffer_size()
const;
459 socket& send_buffer_size(
size_t value);
571 template<
typename end_po
int_t>
573 return begin_connect_(std::make_shared<end_point_t>(remote_end_point), callback, state);
602 std::shared_ptr<xtd::iasync_result> begin_connect(
const std::vector<xtd::net::ip_address>& addresses,
uint16 port,
xtd::async_callback callback,
const std::any& state);
788 template<
typename end_po
int_t>
789 void bind(
const end_point_t& local_end_point) {
790 bind_(std::make_shared<end_point_t>(local_end_point));
809 template<
typename end_po
int_t>
810 void connect(
const end_point_t& remote_end_point) {
811 connect_(std::make_shared<end_point_t>(remote_end_point));
837 void connect(
const std::vector<xtd::net::ip_address>& addresses,
uint16 port);
870 socket end_accept(std::shared_ptr<xtd::iasync_result> async_result);
881 void end_connect(std::shared_ptr<xtd::iasync_result> async_result);
890 void end_disconnect(std::shared_ptr<xtd::iasync_result> async_result);
906 size_t end_receive(std::shared_ptr<xtd::iasync_result> async_result);
934 size_t end_receive_from(std::shared_ptr<xtd::iasync_result> async_result, std::shared_ptr<xtd::net::end_point>&
end_point);
965 size_t end_send(std::shared_ptr<xtd::iasync_result> async_result);
994 size_t end_send_to(std::shared_ptr<xtd::iasync_result> async_result);
996 bool equals(
const socket&
s)
const noexcept
override;
1049 size_t io_control(
int32 io_control_code, std::vector<xtd::byte>& option_in_value, std::vector<xtd::byte>& option_out_value);
1067 void listen(
size_t backlog);
1106 size_t receive(std::vector<xtd::byte>& buffer);
1266 static size_t select(std::vector<socket>& check_read, std::vector<socket>& check_write, std::vector<socket>& check_error,
int32 microseconds);
1280 size_t send(
const std::vector<xtd::byte>& buffer);
1526 void set_raw_socket_option(
int32 socket_option_level,
int32 socket_option_name,
intptr option_value,
size_t option_value_size);
1552 std::shared_ptr<xtd::iasync_result> begin_connect_(std::shared_ptr<xtd::net::end_point> remote_end_point,
xtd::async_callback callback,
const std::any& state);
1553 void bind_(std::shared_ptr<xtd::net::end_point> local_end_point);
1554 void connect_(std::shared_ptr<xtd::net::end_point> remote_end_point);
1556 std::shared_ptr<data> data_;
Implements the Berkeley sockets interface.
Definition: socket.h:69
protocol_type
Specifies the protocols that the xtd::net::sockets::socket class supports.
Definition: protocol_type.h:27
Contains xtd::net::sockets::socket_option_name enum.
ip_protection_level
A value that enables restriction of an IPv6 socket to a specified scope, such as addresses with the s...
Definition: ip_protection_level.h:28
Provides an Internet Protocol (IP) address.
Definition: ip_address.h:34
Contains xtd::net::sockets::multicast_option class.
Contains xtd::net::sockets::io_control_code enum.
intmax_t intptr
Represent a pointer or a handle.
Definition: types.h:86
Gets the error status and clear.
io_control_code
Specifies the IO control codes supported by the xtd::net::sockets::socket::io_control method...
Definition: io_control_code.h:27
Specifies whether a xtd::net::sockets::socket will remain connected after a call to the xtd::net::soc...
Definition: linger_option.h:31
Represents the status of an asynchronous operation.
Definition: iasync_result.h:21
An IP multicast loopback.
Use no flags for this call.
Receive a time-out. This option applies only to synchronous methods; it has no effect on asynchronous...
std::shared_ptr< xtd::iasync_result > begin_connect(const end_point_t &remote_end_point, xtd::async_callback callback, const std::any &state)
Begins an asynchronous request for a remote host connection.
Definition: socket.h:572
socket_option_name
Defines configuration option names.
Definition: socket_option_name.h:28
A request to send or receive data was disallowed because the socket is closed.
Contains xtd::net::sockets::socket_flags enum.
Identifies a network address. This is an abstract class.
Definition: end_point.h:24
Contains xtd::net::sockets::ip_v6_multicast_option class.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Contains xtd::net::sockets::socket_type enum.
A socket receive_message_from operation.
Contains xtd::net::sockets::select_mode enum.
Enables a socket to be bound for exclusive access.
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition: types.h:144
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
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains IPAddress values used to join and drop multicast groups.
Definition: multicast_option.h:36
A socket accept operation.
socket_error
Defines error codes for the xtd::net::sockets::socket class.
Definition: socket_error.h:27
Send a time-out. This option applies only to synchronous methods; it has no effect on asynchronous me...
void bind(const end_point_t &local_end_point)
Associates a xtd::net::sockets::socket with a local endpoint.
Definition: socket.h:789
select_mode
Defines the polling modes for the xtd::net::sockets::socket::poll method.
Definition: select_mode.h:28
Do not fragment IP datagrams.
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
A socket connect operation.
Contains xtd::net::sockets::socket_shutdown enum.
The protocol type is incorrect.
Socket options apply to all sockets.
Contains xtd::net::sockets::socket_error enum.
socket_flags
Specifies socket send and receive behaviors. This enumeration has a flags attribute that allows a bit...
Definition: socket_flags.h:27
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
Contains xtd::net::sockets::ip_protection_level enum.
Disables the Nagle algorithm for send coalescing.
A socket receive operation.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:31
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:74
Contains xtd::net::sockets::address_family enum.
A socket receive_from operation.
socket_shutdown
Defines constants that are used by the xtd::net::sockets::socket::shutdown method.
Definition: socket_shutdown.h:28
socket_type
Specifies the type of socket that an instance of the xtd::net::sockets::socket class represents...
Definition: socket_type.h:29
Contains option values for joining an IPv6 multicast group.
Definition: ip_v6_multicast_option.h:29
socket_option_level
Defines socket option levels for the xtd::net::sockets::socket::set_socket_option and xtd::net::socke...
Definition: socket_option_level.h:28
A socket send_to operation.
A socket disconnect operation.
Contains xtd::net::sockets::linger_option class.
void connect(const end_point_t &remote_end_point)
Establishes a connection to a remote host.
Definition: socket.h:810
The socket handle may be reused when the request completes. This flag is valid only if xtd::net::sock...
uint_least8_t byte
Represents a 8-bit unsigned integer.
Definition: types.h:26
Represents an asynchronous socket operation.
Definition: socket_async_event_args.h:51
Contains xtd::net::sockets::socket_option_level enum.
size_t size
Represents a size of any object in bytes.
Definition: types.h:120
Contains xtd::net::sockets::protocol_type enum.
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use...
Definition: address_family.h:27