CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
network_stream.h
1
2#pragma once
3
4#include <cstdint>
5#include <system/array.h>
6#include <system/async_callback.h>
7#include <system/iasyncresult.h>
8#include <system/io/file_access.h>
9#include <system/io/seekorigin.h>
10#include <system/io/stream.h>
11#include <system/object.h>
12#include <system/shared_ptr.h>
13
14#include <net/sockets/socket.h>
15
16namespace System { namespace Net { namespace Sockets {
17
22class ASPOSECPP_SHARED_CLASS NetworkStream : public System::IO::Stream
23{
25 typedef NetworkStream ThisType;
28
30 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
32 ASPOSECPP_SHARED_RTTI_INFO_DECL();
33
34public:
36 ASPOSECPP_SHARED_API bool get_CanRead() const override;
38 ASPOSECPP_SHARED_API bool get_CanSeek() const override;
40 ASPOSECPP_SHARED_API bool get_CanWrite() const override;
42 ASPOSECPP_SHARED_API bool get_CanTimeout() const override;
44 ASPOSECPP_SHARED_API int32_t get_ReadTimeout() const override;
46 ASPOSECPP_SHARED_API void set_ReadTimeout(int32_t value) override;
48 ASPOSECPP_SHARED_API int32_t get_WriteTimeout() const override;
50 ASPOSECPP_SHARED_API void set_WriteTimeout(int32_t value) override;
53 ASPOSECPP_SHARED_API bool get_DataAvailable() const;
55 ASPOSECPP_SHARED_API int64_t get_Length() const override;
57 ASPOSECPP_SHARED_API int64_t get_Position() const override;
59 ASPOSECPP_SHARED_API void set_Position(int64_t value) override;
60
64
74 System::IO::FileAccess access, bool ownsSocket);
79 ASPOSECPP_SHARED_API NetworkStream(System::SharedPtr<System::Net::Sockets::Socket> socket, bool ownsSocket);
80
82 ASPOSECPP_SHARED_API int64_t Seek(int64_t offset, IO::SeekOrigin origin) override;
88 ASPOSECPP_SHARED_API int32_t Read(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t size) override;
93 ASPOSECPP_SHARED_API void Write(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t size) override;
94
100 ASPOSECPP_SHARED_API int32_t Read(const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t size) override;
105 ASPOSECPP_SHARED_API void Write(const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t size) override;
106
109 ASPOSECPP_SHARED_API void Close(int timeout);
110
112 virtual ASPOSECPP_SHARED_API ~NetworkStream();
113
121 ASPOSECPP_SHARED_API System::SharedPtr<IAsyncResult> BeginRead(System::ArrayPtr<uint8_t> buffer, int32_t offset,
122 int32_t size, AsyncCallback callback,
123 System::SharedPtr<Object> state) override;
125 ASPOSECPP_SHARED_API int32_t EndRead(System::SharedPtr<IAsyncResult> asyncResult) override;
133 ASPOSECPP_SHARED_API System::SharedPtr<IAsyncResult> BeginWrite(System::ArrayPtr<uint8_t> buffer, int32_t offset,
134 int32_t size, AsyncCallback callback,
135 System::SharedPtr<Object> state) override;
137 ASPOSECPP_SHARED_API void EndWrite(System::SharedPtr<IAsyncResult> asyncResult) override;
139 ASPOSECPP_SHARED_API void Flush() override;
141 ASPOSECPP_SHARED_API void SetLength(int64_t value) override;
142
143private:
147 void InitNetworkStream(System::SharedPtr<System::Net::Sockets::Socket> socket, System::IO::FileAccess Access);
148
151
153 bool m_Readable;
155 bool m_Writeable;
157 bool m_OwnsSocket;
158};
159}}} // namespace System::Net::Sockets
A base class for a variety of stream implementations. Objects of this class should only be allocated ...
Definition: stream.h:24
Provides the underlying stream of the data for the network access. Objects of this class should only ...
Definition: network_stream.h:23
void Write(const ArrayPtr< uint8_t > &buffer, int32_t offset, int32_t size) override
Writes the specified subrange of bytes from the specified byte array to the stream.
NetworkStream(System::SharedPtr< System::Net::Sockets::Socket > socket, bool ownsSocket)
Constructs a new instance.
void SetLength(int64_t value) override
Sets the length of the stream represented by the current object.
bool get_CanWrite() const override
Determines if the stream is writable.
void EndWrite(System::SharedPtr< IAsyncResult > asyncResult) override
Ends an asynchronous write operation. Waits until the specified asynchronous write operation complete...
System::SharedPtr< IAsyncResult > BeginWrite(System::ArrayPtr< uint8_t > buffer, int32_t offset, int32_t size, AsyncCallback callback, System::SharedPtr< Object > state) override
Initiates an asynchronous write operation.
int32_t get_WriteTimeout() const override
Gets a value, in milliseconds, that determines how long the stream will attempt to write before timin...
int32_t get_ReadTimeout() const override
Gets a value, in milliseconds, that determines how long the stream will attempt to read before timing...
virtual ~NetworkStream()
Destructs the current instance.
void set_WriteTimeout(int32_t value) override
Sets a value, in milliseconds, that determines how long the stream will attempt to read before timing...
System::SharedPtr< IAsyncResult > BeginRead(System::ArrayPtr< uint8_t > buffer, int32_t offset, int32_t size, AsyncCallback callback, System::SharedPtr< Object > state) override
Initiates an asynchronous read operation.
int64_t get_Length() const override
Returns the length of the stream in bytes.
void Write(const System::Details::ArrayView< uint8_t > &buffer, int32_t offset, int32_t size) override
Writes the specified subrange of bytes from the specified byte array to the stream.
NetworkStream(System::SharedPtr< System::Net::Sockets::Socket > socket, System::IO::FileAccess access, bool ownsSocket)
Constructs a new instance.
int64_t Seek(int64_t offset, IO::SeekOrigin origin) override
Sets the position of the stream represented by the current object.
bool get_CanRead() const override
Determines if the stream is readable.
bool get_CanSeek() const override
Determines if the stream supports seeking.
int32_t Read(const System::Details::ArrayView< uint8_t > &buffer, int32_t offset, int32_t size) override
Reads the specified number of bytes from the stream and writes them to the specified byte array.
NetworkStream(System::SharedPtr< System::Net::Sockets::Socket > socket)
Constructs a new instance.
bool get_DataAvailable() const
Returns a value that indicates if the there is available data to read.
void set_Position(int64_t value) override
Sets the stream's position.
void set_ReadTimeout(int32_t value) override
Sets a value that determines whether the current stream can time out.
System::SharedPtr< System::Net::Sockets::Socket > get_Socket()
Gets the underlying Socket.
int32_t Read(const ArrayPtr< uint8_t > &buffer, int32_t offset, int32_t size) override
Reads the specified number of bytes from the stream and writes them to the specified byte array.
int64_t get_Position() const override
Returns the current position of the stream.
void Close(int timeout)
Closes the current instance after the specified time expires.
void Flush() override
Clears this stream's buffers and writes all buffered data to the underlying storage.
bool get_CanTimeout() const override
Gets a value that determines whether the current stream can time out.
int32_t EndRead(System::SharedPtr< IAsyncResult > asyncResult) override
Waits until the specified asynchronous read operation completes.
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
FileAccess
Specifies the type of access when opening the file.
Definition: file_access.h:11
SeekOrigin
Specifies the reference position in the stream relative to which the position to seek to is specified...
Definition: seekorigin.h:11
Definition: db_command.h:9
System::MulticastDelegate< void(SharedPtr< IAsyncResult >)> AsyncCallback
A delegate type that represents a method to be called when asynchronous operation completes.
Definition: async_callback.h:13