DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
Socket.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "Common.h"
9#include "System/Object.h"
10#include "System/String.h"
11#include "System/SmartPointer.h"
12
13namespace DotNetDupe {
14 namespace System {
15 namespace Net {
16 namespace Sockets {
17
20 enum class AddressFamily {
21 Unknown = -1,
25 };
26
29 enum class SocketType {
30 Unknown = -1,
31 Stream = 1,
32 Dgram = 2,
33 Raw = 3
34 };
35
38 enum class ProtocolType {
39 Unknown = -1,
40 Tcp = 6,
41 Udp = 17
42 };
43
46 enum class SocketShutdown {
48 Send = 1,
49 Both = 2
50 };
51
54 enum class SelectMode {
58 };
59
60 class SocketImpl;
61
69 class Socket : public Object {
70 public:
76 DOTNETDUPE_API Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType);
77
80
81 Socket(const Socket&) = delete;
82 Socket& operator=(const Socket&) = delete;
83 DOTNETDUPE_API Socket(Socket&& other) noexcept;
84 DOTNETDUPE_API Socket& operator=(Socket&& other) noexcept;
85
90 DOTNETDUPE_API void Bind(const String& ip, int port);
91
95 DOTNETDUPE_API void Listen(int backlog);
96
101
106 DOTNETDUPE_API void Connect(const String& ip, int port);
107
114 DOTNETDUPE_API int Send(const char* buffer, int offset, int size);
115
122 DOTNETDUPE_API int Receive(char* buffer, int offset, int size);
123
132 DOTNETDUPE_API int SendTo(const char* buffer, int offset, int size, const String& ip, int port);
133
142 DOTNETDUPE_API int ReceiveFrom(char* buffer, int offset, int size, String& ip, int& port);
143
145 DOTNETDUPE_API void Close();
146
150
155 DOTNETDUPE_API bool Poll(int microSeconds, SelectMode mode);
156
159 DOTNETDUPE_API bool Connected() const;
160
163 DOTNETDUPE_API explicit Socket(void* pNativeHandle);
164
167 DOTNETDUPE_API void* GetNativeHandle() const;
168
169 private:
171 };
172
173 }
174 }
175 }
176}
Defines common cross-platform macros, export decorators, and fundamental types.
#define DOTNETDUPE_API
Platform-specific linkage decoration for exporting or importing library symbols.
Definition Common.h:20
Base object class for DotNetDupe mirroring .NET System.Object.
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
int Receive(char *buffer, int offset, int size)
Receives data from a bound Socket into a receive buffer.
Definition Socket.cpp:222
bool Connected() const
Gets a value that indicates whether a Socket is connected to a remote host as of the last Send or Rec...
Definition Socket.cpp:320
bool Poll(int microSeconds, SelectMode mode)
Determines the status of the Socket.
Definition Socket.cpp:296
SmartPointer< Socket > Accept()
Creates a new Socket for a newly created connection.
Definition Socket.cpp:179
int SendTo(const char *buffer, int offset, int size, const String &ip, int port)
Sends data to the specified endpoint.
Definition Socket.cpp:232
Socket & operator=(const Socket &)=delete
int Send(const char *buffer, int offset, int size)
Sends data to a connected Socket.
Definition Socket.cpp:212
void Bind(const String &ip, int port)
Associates a Socket with a local endpoint.
Definition Socket.cpp:147
void Shutdown(SocketShutdown how)
Disables sends and receives on a Socket.
Definition Socket.cpp:272
void * GetNativeHandle() const
Retrieves the underlying native socket descriptor.
Definition Socket.cpp:328
int ReceiveFrom(char *buffer, int offset, int size, String &ip, int &port)
Receives a datagram into the data buffer and stores the endpoint.
Definition Socket.cpp:252
void Listen(int backlog)
Places a Socket in a listening state.
Definition Socket.cpp:167
Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
Initializes a new instance of the Socket class using the specified address family,...
Definition Socket.cpp:113
void Close()
Closes the Socket connection and releases all associated resources.
Definition Socket.cpp:267
void Connect(const String &ip, int port)
Establishes a connection to a remote host.
Definition Socket.cpp:200
Supports all classes in the DotNetDupe class hierarchy.
Definition Object.h:18
A unified smart pointer that supports both unique and shared ownership semantics.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
SelectMode
Defines the polling modes for the Socket.Poll method.
Definition Socket.h:54
AddressFamily
Specifies the addressing scheme that an instance of the Socket class can use.
Definition Socket.h:20
SocketShutdown
Defines constants that are used by the Socket.Shutdown method.
Definition Socket.h:46
ProtocolType
Specifies the protocols that the Socket class supports.
Definition Socket.h:38
SocketType
Specifies the type of socket that an instance of the Socket class represents.
Definition Socket.h:29
@ Unspecified
The time represented is not specified as either local time or UTC.
Definition DateTime.h:20