Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Socket.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21#ifndef GF_SOCKET_H
22#define GF_SOCKET_H
23
24#include "NetApi.h"
25#include "SocketAddress.h"
26#include "SocketGuard.h"
27#include "SocketTypes.h"
28
29namespace gf {
30#ifndef DOXYGEN_SHOULD_SKIP_THIS
31inline namespace v1 {
32#endif
33
41 class GF_NET_API Socket : private SocketGuard {
42 public:
49
53 Socket(const Socket&) = delete;
54
58 Socket& operator=(const Socket&) = delete;
59
65 Socket(Socket&& other) noexcept;
66
73 Socket& operator=(Socket&& other) noexcept;
74
80 operator bool () const noexcept {
81 return m_handle != InvalidSocketHandle;
82 }
83
90
97
104
105 protected:
106#ifndef DOXYGEN_SHOULD_SKIP_THIS
107 Socket()
108 : m_handle(InvalidSocketHandle)
109 {
110
111 }
112
113 void setHandle(SocketHandle handle) {
114 m_handle = handle;
115 }
116
117 SocketHandle getHandle() const {
118 return m_handle;
119 }
120#endif
121
122 private:
123 friend class SocketSelector;
124 SocketHandle m_handle;
125 };
126
127#ifndef DOXYGEN_SHOULD_SKIP_THIS
128}
129#endif
130}
131
132#endif // GF_SOCKET_H
A socket address.
Definition: SocketAddress.h:78
A guard to handle library initialization.
Definition: SocketGuard.h:42
A network socket.
Definition: Socket.h:41
void setNonBlocking()
Set the socket in non-blocking mode.
void setBlocking()
Set the socket in blocking mode.
SocketAddress getLocalAddress() const
Get the local address of the socket.
~Socket()
Destructor.
Socket & operator=(Socket &&other) noexcept
Move assignment.
Socket(Socket &&other) noexcept
Move constructor.
Socket & operator=(const Socket &)=delete
Deleted copy assignment.
Socket(const Socket &)=delete
Deleted copy constructor.
A socket selector.
Definition: SocketSelector.h:50
constexpr SocketHandle InvalidSocketHandle
An invalid socket handle.
Definition: SocketTypes.h:67
implementation-defined SocketHandle
A native socket handle.
Definition: SocketTypes.h:55
The namespace for gf classes.