SFML 2.5.1

- Main Page
- Related Pages
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

Socket.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages 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 freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef SFML_SOCKET_HPP
26#define SFML_SOCKET_HPP
27
29// Headers
31#include <SFML/Network/Export.hpp>
32#include <SFML/Network/SocketHandle.hpp>
33#include <SFML/System/NonCopyable.hpp>
34#include <vector>
35
36
37 namespace sf
38{
39 class SocketSelector;
40
45 class SFML_NETWORK_API Socket : NonCopyable
46{
47 public:
48
53 enum Status
54 {
55 Done,
56 NotReady,
57 Partial,
58 Disconnected,
59 Error
60 };
61
66 enum
67 {
68 AnyPort = 0
69 };
70
71 public:
72
77 virtual ~Socket();
78
96 void setBlocking(bool blocking);
97
106 bool isBlocking() const;
107
108 protected:
109
114 enum Type
115 {
116 Tcp,
117 Udp
118 };
119
128 Socket(Type type);
129
140 SocketHandle getHandle() const;
141
148 void create();
149
159 void create(SocketHandle handle);
160
167 void close();
168
169 private:
170
171 friend class SocketSelector;
172
174 // Member data
176 Type m_type;
177 SocketHandle m_socket;
178 bool m_isBlocking;
179};
180
181} // namespace sf
182
183
184#endif // SFML_SOCKET_HPP
185
186
sf::NonCopyable
Utility class that makes any derived class non-copyable.
Definition NonCopyable.hpp:42
sf::SocketSelector
Multiplexer that allows to read from multiple sockets.
Definition SocketSelector.hpp:44
sf::Socket
Base class for all the socket types.
Definition Socket.hpp:46
sf::Socket::setBlocking
void setBlocking(bool blocking)
Set the blocking state of the socket.
sf::Socket::Status
Status
Status codes that may be returned by socket functions.
Definition Socket.hpp:54
sf::Socket::Partial
@ Partial
The socket sent a part of the data.
Definition Socket.hpp:57
sf::Socket::Done
@ Done
The socket has sent / received the data.
Definition Socket.hpp:55
sf::Socket::NotReady
@ NotReady
The socket is not ready to send / receive data yet.
Definition Socket.hpp:56
sf::Socket::Disconnected
@ Disconnected
The TCP socket has been disconnected.
Definition Socket.hpp:58
sf::Socket::Type
Type
Types of protocols that the socket can use.
Definition Socket.hpp:115
sf::Socket::Tcp
@ Tcp
TCP protocol.
Definition Socket.hpp:116
sf::Socket::getHandle
SocketHandle getHandle() const
Return the internal handle of the socket.
sf::Socket::close
void close()
Close the socket gracefully.
sf::Socket::~Socket
virtual ~Socket()
Destructor.
sf::Socket::Socket
Socket(Type type)
Default constructor.
sf::Socket::create
void create()
Create the internal representation of the socket.
sf::Socket::isBlocking
bool isBlocking() const
Tell whether the socket is in blocking or non-blocking mode.
sf::Socket::create
void create(SocketHandle handle)
Create the internal representation of the socket from a socket handle.