Socket.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2015 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 CPP3DS_SOCKET_HPP
26 #define CPP3DS_SOCKET_HPP
27 
29 // Headers
31 #include <cpp3ds/Network/SocketHandle.hpp>
32 #include <cpp3ds/System/NonCopyable.hpp>
33 #include <vector>
34 
35 
36 namespace cpp3ds
37 {
38 class SocketSelector;
39 
45 {
46 public:
47 
52  enum Status
53  {
54  Done,
59  };
60 
65  enum
66  {
67  AnyPort = 0
68  };
69 
70 public:
71 
76  virtual ~Socket();
77 
95  void setBlocking(bool blocking);
96 
105  bool isBlocking() const;
106 
107 protected:
108 
113  enum Type
114  {
115  Tcp,
117  };
118 
127  Socket(Type type);
128 
139  SocketHandle getHandle() const;
140 
147  void create();
148 
158  void create(SocketHandle handle);
159 
166  void close();
167 
168 private:
169 
170  friend class SocketSelector;
171 
173  // Member data
175  Type m_type;
176  SocketHandle m_socket;
177  bool m_isBlocking;
178 };
179 
180 } // namespace cpp3ds
181 
182 
183 #endif // CPP3DS_SOCKET_HPP
184 
185 
void close()
Close the socket gracefully.
Socket(Type type)
Default constructor.
The socket sent a part of the data.
Definition: Socket.hpp:56
Base class for all the socket types.
Definition: Socket.hpp:44
The socket is not ready to send / receive data yet.
Definition: Socket.hpp:55
void setBlocking(bool blocking)
Set the blocking state of the socket.
bool isBlocking() const
Tell whether the socket is in blocking or non-blocking mode.
The TCP socket has been disconnected.
Definition: Socket.hpp:57
SocketHandle getHandle() const
Return the internal handle of the socket.
Utility class that makes any derived class non-copyable.
Definition: NonCopyable.hpp:35
UDP protocol.
Definition: Socket.hpp:116
virtual ~Socket()
Destructor.
Special value that tells the system to pick any available port.
Definition: Socket.hpp:67
The socket has sent / received the data.
Definition: Socket.hpp:54
An unexpected error happened.
Definition: Socket.hpp:58
Status
Status codes that may be returned by socket functions.
Definition: Socket.hpp:52
Multiplexer that allows to read from multiple sockets.
Type
Types of protocols that the socket can use.
Definition: Socket.hpp:113
TCP protocol.
Definition: Socket.hpp:115
void create()
Create the internal representation of the socket.