Skip to content

Commit 3c76412

Browse files
committed
xtd::net::sockets::network_stream implementztion
1 parent 80f944c commit 3c76412

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/xtd.core/include/xtd/net/sockets/network_stream.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ namespace xtd {
7979
/// @return `true` if the stream supports seeking; otherwise, `false`.
8080
bool can_seek() const noexcept override;
8181

82+
/// @brief Indicates whether timeout properties are usable for xtd::net::sockets::network_stream.
83+
/// @return `true` in all cases.
84+
bool can_timeout() const noexcept override;
85+
8286
/// @brief Gets a value indicating whether the current stream supports writing.
8387
/// @return `true` if the stream supports writing; otherwise, `false`.
8488
bool can_write() const noexcept override;
@@ -101,15 +105,33 @@ namespace xtd {
101105
/// @param value The current position within the stream.
102106
void position(xtd::size value) override;
103107

108+
/// @brief Gets the amount of time that a read operation blocks waiting for data.
109+
/// @return A xtd::int32 that specifies the amount of time, in milliseconds, that will elapse before a read operation fails. The default value, xtd::threading::timeout::infinite, specifies that the read operation does not time out.
110+
int32 read_timeout() const override;
111+
/// @brief Sets the amount of time that a read operation blocks waiting for data.
112+
/// @param value A xtd::int32 that specifies the amount of time, in milliseconds, that will elapse before a read operation fails. The default value, xtd::threading::timeout::infinite, specifies that the read operation does not time out.
113+
void read_timeout(int32 value) override;
114+
115+
/// @brief Gets the amount of time that a write operation blocks waiting for data.
116+
/// @return A xtd::int32 that specifies the amount of time, in milliseconds, that will elapse before a read operation fails. The default value, xtd::threading::timeout::infinite, specifies that the read operation does not time out.
117+
int32 write_timeout() const override;
118+
/// @brief Sets the amount of time that a write operation blocks waiting for data.
119+
/// @param value A xtd::int32 that specifies the amount of time, in milliseconds, that will elapse before a read operation fails. The default value, xtd::threading::timeout::infinite, specifies that the read operation does not time out.
120+
void write_timeout(int32 value) override;
121+
104122
/// @brief Gets the underlying xtd::net::sockets::socket.
105123
/// @return A xtd::net::sockets::socket that represents the underlying network connection.
106-
/// @remarks Classes deriving from xtd::net::sockets::network_stream can use this property to get the underlying xtd::net::sockets::socket. Use the underlying xtd::net::sockets::socket returned from the xtd::net::sockets::socketproperty if you require access beyond that which xtd::net::sockets::network_stream provides.
124+
/// @remarks Classes deriving from xtd::net::sockets::network_stream can use this property to get the underlying xtd::net::sockets::socket. Use the underlying xtd::net::sockets::socket returned from the xtd::net::sockets::socket property if you require access beyond that which xtd::net::sockets::network_stream provides.
107125
xtd::net::sockets::socket socket() const;
108126
/// @}
109127

110128
/// @name Public Methods
111129

112130
/// @{
131+
/// @brief Flushes data from the stream. This method is reserved for future use.
132+
/// @remarks The Flush method implements the xtd::io::stream::flush method; however, because xtd::net::sockets::network_stream is not buffered, it has no effect on network streams. Calling the xtd::net::sockets::network_stream::flush method does not throw an exception.
133+
void flush() override;
134+
113135
using xtd::io::stream::read;
114136
/// @brief Reads a block of bytes from the current stream and writes the data to a buffer.
115137
/// @param buffer When this method returns, contains the specified byte array with the values between `offset` and (`offset` + `count` - 1) replaced by the characters read from the current stream.

src/xtd.core/src/xtd/net/sockets/network_stream.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ bool network_stream::can_seek() const noexcept {
3232
return false;
3333
}
3434

35+
36+
bool network_stream::can_timeout() const noexcept {
37+
return true;
38+
}
39+
3540
bool network_stream::can_write() const noexcept {
3641
return (data_->access & file_access::write) == file_access::write;
3742
}
@@ -52,10 +57,29 @@ void network_stream::position(size value) {
5257
throw not_supported_exception {};
5358
}
5459

60+
int32 network_stream::read_timeout() const {
61+
return data_->socket.receive_timeout();
62+
}
63+
64+
void network_stream::read_timeout(int32 value) {
65+
data_->socket.receive_timeout(value);
66+
}
67+
68+
int32 network_stream::write_timeout() const {
69+
return data_->socket.send_timeout();
70+
}
71+
72+
void network_stream::write_timeout(int32 value) {
73+
data_->socket.send_timeout(value);
74+
}
75+
5576
xtd::net::sockets::socket network_stream::socket() const {
5677
return data_->socket;
5778
}
5879

80+
void network_stream::flush() {
81+
}
82+
5983
size network_stream::read(array<byte>& buffer, size offset, size count) {
6084
if (is_closed()) throw object_closed_exception {};
6185
if (!can_read()) throw not_supported_exception {};

0 commit comments

Comments
 (0)