35 #include "BufferRef.h" 36 #include "Portability.h" 37 #include "SocketAddress.h" 38 #include "SocketGuard.h" 41 #ifndef DOXYGEN_SHOULD_SKIP_THIS 45 #ifndef DOXYGEN_SHOULD_SKIP_THIS 75 constexpr
SocketHandle InvalidSocketHandle = implemetation-defined;
148 operator bool () const noexcept {
171 void setNonBlocking();
174 #ifndef DOXYGEN_SHOULD_SKIP_THIS 176 : m_handle(InvalidSocketHandle)
190 static bool nativeSetBlockMode(
SocketHandle handle,
bool blocking);
191 static bool nativeWouldBlock(
int err);
194 using SendLengthType = int;
195 using SendPointerType =
const char *;
196 using RecvLengthType = int;
197 using RecvPointerType =
char *;
199 using SendLengthType = std::size_t;
200 using SendPointerType =
const void *;
201 using RecvLengthType = std::size_t;
202 using RecvPointerType =
void *;
211 static int getErrorCode();
212 static std::string getErrorString();
215 static constexpr
int InvalidCommunication = SOCKET_ERROR;
217 static constexpr ssize_t InvalidCommunication = -1;
221 enum SocketType :
int {
226 struct SocketAddressInfo {
232 static constexpr
int NoFlag = 0;
234 static std::vector<SocketAddressInfo> getRemoteAddressInfo(
const std::string& hostname,
const std::string& service, SocketType type,
SocketFamily family =
SocketFamily::Unspec);
239 static std::vector<SocketAddressInfo> getAddressInfoEx(
const char *hostname,
const char *service,
int flags, SocketType type,
SocketFamily family);
242 #ifndef DOXYGEN_SHOULD_SKIP_THIS 247 static constexpr Header encodeHeader(uint64_t size) {
248 Header header = {{ 0, 0, 0, 0, 0, 0, 0, 0 }};
250 for (
int i = 0; i < 8; ++i) {
251 header.data[8 - i - 1] =
static_cast<uint8_t
>(size % 0x100);
258 static constexpr uint64_t decodeHeader(
const Header& header) {
261 for (uint64_t x : header.data) {
262 size = (size << 8) + x;
273 #ifndef DOXYGEN_SHOULD_SKIP_THIS 278 #endif // GF_SOCKET_H Some data has been sent or received.
SocketFamily
A socket family.
Definition: SocketAddress.h:50
The result of a socket operation.
Definition: Socket.h:97
Unspecified (either IPv4 or IPv6)
The connection is closed.
constexpr BufferRef< T > buffer(T *data, std::size_t size)
Create a reference to a buffer.
Definition: BufferRef.h:211
An error occurred.
Definition: SocketSelector.h:49
The namespace for gf classes.
Definition: Action.h:35
SocketStatus status
The status of the operation.
Definition: Socket.h:98
constexpr SocketHandle InvalidSocketHandle
An invalid socket handle.
Definition: Socket.h:75
A socket selector.
Definition: SocketSelector.h:59
A guard to handle library initialization.
Definition: SocketGuard.h:42
std::size_t length
The length of sent or received data.
Definition: Socket.h:99
SocketStatus
The status of a socket operation.
Definition: Socket.h:84
The socket would have blocked.
implementation-defined SocketHandle
A native socket handle.
Definition: Socket.h:63
A network socket.
Definition: Socket.h:109
A socket address.
Definition: SocketAddress.h:78