DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
NetworkStream.cpp
Go to the documentation of this file.
1
#include "
pch.h
"
2
#include "
System/Net/Sockets/NetworkStream.h
"
3
#include "
System/ArgumentNullException.h
"
4
#include "
System/IOException.h
"
5
6
namespace
DotNetDupe
{
7
namespace
System
{
8
namespace
Net
{
9
namespace
Sockets
{
10
11
NetworkStream::NetworkStream
(
const
SmartPointer<Socket>
& socket)
12
: m_pSocket(socket), m_bOwnsSocket(false), m_bDisposed(false) {
14
if
(socket.
IsNull
()) {
15
throw ArgumentNullException(
"Socket cannot be null."
);
16
}
17
}
18
19
NetworkStream::NetworkStream
(
const
SmartPointer<Socket>
& socket,
bool
bOwnsSocket)
20
: m_pSocket(socket), m_bOwnsSocket(bOwnsSocket), m_bDisposed(false) {
22
if
(socket.
IsNull
()) {
23
throw ArgumentNullException(
"Socket cannot be null."
);
24
}
25
}
26
27
NetworkStream::~NetworkStream
() {
29
Dispose
();
30
}
31
32
bool
NetworkStream::CanRead
()
const
{
33
return
!m_bDisposed;
34
}
35
36
bool
NetworkStream::CanSeek
()
const
{
37
return
false
;
38
}
39
40
bool
NetworkStream::CanWrite
()
const
{
41
return
!m_bDisposed;
42
}
43
44
long
NetworkStream::GetLength
()
const
{
45
throw
IO::IOException
(
"NetworkStream does not support seeking."
);
46
}
47
48
long
NetworkStream::GetPosition
()
const
{
49
throw
IO::IOException
(
"NetworkStream does not support seeking."
);
50
}
51
52
void
NetworkStream::SetPosition
(
long
value) {
53
throw
IO::IOException
(
"NetworkStream does not support seeking."
);
54
}
55
56
void
NetworkStream::Flush
() {
58
}
59
60
int
NetworkStream::Read
(
char
* buffer,
int
offset,
int
count) {
62
if
(m_bDisposed)
throw
IO::IOException
(
"Stream is disposed."
);
63
65
return
m_pSocket->Receive(buffer, offset, count);
66
}
67
68
long
NetworkStream::Seek
(
long
offset,
int
origin) {
69
throw
IO::IOException
(
"NetworkStream does not support seeking."
);
70
}
71
72
void
NetworkStream::SetLength
(
long
value) {
73
throw
IO::IOException
(
"NetworkStream does not support seeking."
);
74
}
75
76
void
NetworkStream::Write
(
const
char
* buffer,
int
offset,
int
count) {
78
if
(m_bDisposed)
throw
IO::IOException
(
"Stream is disposed."
);
79
81
m_pSocket->Send(buffer, offset, count);
82
}
83
84
void
NetworkStream::Dispose
() {
86
if
(!m_bDisposed) {
87
m_bDisposed =
true
;
88
if
(m_bOwnsSocket && !m_pSocket.IsNull()) {
89
m_pSocket->Close();
90
}
91
}
92
}
93
94
void
NetworkStream::Close
() {
95
Dispose
();
96
}
97
98
}
99
}
100
}
101
}
ArgumentNullException.h
Defines the exception thrown when a null reference is passed to a method that does not accept it.
IOException.h
The exception that is thrown when an I/O error occurs.
NetworkStream.h
Provides the underlying stream of data for network access.
DotNetDupe::System::IO::IOException
The exception that is thrown when an I/O error occurs.
Definition
IOException.h:17
DotNetDupe::System::Net::Sockets::NetworkStream::CanWrite
bool CanWrite() const override
Gets a value that indicates whether the NetworkStream supports writing.
Definition
NetworkStream.cpp:40
DotNetDupe::System::Net::Sockets::NetworkStream::~NetworkStream
~NetworkStream()
Destructor closing stream and owned socket.
Definition
NetworkStream.cpp:27
DotNetDupe::System::Net::Sockets::NetworkStream::Write
void Write(const char *buffer, int offset, int count) override
Writes data to the NetworkStream.
Definition
NetworkStream.cpp:76
DotNetDupe::System::Net::Sockets::NetworkStream::SetPosition
void SetPosition(long value) override
Sets the current position of the stream. Not supported.
Definition
NetworkStream.cpp:52
DotNetDupe::System::Net::Sockets::NetworkStream::CanSeek
bool CanSeek() const override
Gets a value that indicates whether the stream supports seeking. Always returns false.
Definition
NetworkStream.cpp:36
DotNetDupe::System::Net::Sockets::NetworkStream::Read
int Read(char *buffer, int offset, int count) override
Reads data from the NetworkStream and stores it in the buffer.
Definition
NetworkStream.cpp:60
DotNetDupe::System::Net::Sockets::NetworkStream::Dispose
void Dispose() override
Releases the unmanaged resources used by the NetworkStream.
Definition
NetworkStream.cpp:84
DotNetDupe::System::Net::Sockets::NetworkStream::NetworkStream
NetworkStream(const SmartPointer< Socket > &socket)
Creates a new instance of the NetworkStream class for the specified Socket.
Definition
NetworkStream.cpp:11
DotNetDupe::System::Net::Sockets::NetworkStream::SetLength
void SetLength(long value) override
Sets the length of the stream. Not supported.
Definition
NetworkStream.cpp:72
DotNetDupe::System::Net::Sockets::NetworkStream::CanRead
bool CanRead() const override
Gets a value that indicates whether the NetworkStream supports reading.
Definition
NetworkStream.cpp:32
DotNetDupe::System::Net::Sockets::NetworkStream::GetPosition
long GetPosition() const override
Gets the current position within the stream. Not supported.
Definition
NetworkStream.cpp:48
DotNetDupe::System::Net::Sockets::NetworkStream::Flush
void Flush() override
Flushes data from the stream.
Definition
NetworkStream.cpp:56
DotNetDupe::System::Net::Sockets::NetworkStream::Close
void Close()
Closes the NetworkStream and releases all resources.
Definition
NetworkStream.cpp:94
DotNetDupe::System::Net::Sockets::NetworkStream::GetLength
long GetLength() const override
Gets the length of the data available on the stream. Not supported.
Definition
NetworkStream.cpp:44
DotNetDupe::System::Net::Sockets::NetworkStream::Seek
long Seek(long offset, int origin) override
Sets the current position of the stream to the given value. Not supported.
Definition
NetworkStream.cpp:68
DotNetDupe::System::SmartPointer
A unified smart pointer that supports both unique and shared ownership semantics.
Definition
SmartPointer.h:72
DotNetDupe::System::SmartPointer::IsNull
bool IsNull() const noexcept
Checks if the SmartPointer is null.
Definition
SmartPointer.h:393
DotNetDupe::System::Net::Sockets
Definition
HttpClient.h:20
DotNetDupe::System::Net
Definition
Dns.h:13
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
pch.h
DotNetDupe
NetworkStream.cpp
Generated by
1.18.0