Warning
This page refers to an old version of SFML. Click here to switch to the latest version.
Warning
This page refers to an old version of SFML. Click here to switch to the latest version.
Base class for all the socket types. More...
#include <SFML/Network/Socket.hpp>
Public Types | |
enum class | Status { Done , NotReady , Partial , Disconnected , Error } |
Status codes that may be returned by socket functions. More... |
Public Member Functions | |
virtual | ~Socket () |
Destructor. | |
Socket (const Socket &)=delete | |
Deleted copy constructor. | |
Socket & | operator= (const Socket &)=delete |
Deleted copy assignment. | |
Socket (Socket &&socket) noexcept | |
Move constructor. | |
Socket & | operator= (Socket &&socket) noexcept |
Move assignment. | |
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. |
Static Public Attributes | |
static constexpr unsigned short | AnyPort {0} |
Some special values used by sockets. |
Protected Types | |
enum class | Type { Tcp , Udp } |
Types of protocols that the socket can use. More... |
Protected Member Functions | |
Socket (Type type) | |
Default constructor. | |
SocketHandle | getNativeHandle () const |
Return the internal handle of the socket. | |
void | create () |
Create the internal representation of the socket. | |
void | create (SocketHandle handle) |
Create the internal representation of the socket from a socket handle. | |
void | close () |
Close the socket gracefully. |
Friends | |
class | SocketSelector |
Base class for all the socket types.
This class mainly defines internal stuff to be used by derived classes.
The only public features that it defines, and which is therefore common to all the socket classes, is the blocking state. All sockets can be set as blocking or non-blocking.
In blocking mode, socket functions will hang until the operation completes, which means that the entire program (well, in fact the current thread if you use multiple ones) will be stuck waiting for your socket operation to complete.
In non-blocking mode, all the socket functions will return immediately. If the socket is not ready to complete the requested operation, the function simply returns the proper status code (Socket::Status::NotReady).
The default mode, which is blocking, is the one that is generally used, in combination with threads or selectors. The non-blocking mode is rather used in real-time applications that run an endless loop that can poll the socket often enough, and cannot afford blocking this loop.
Definition at line 41 of file Socket.hpp.
|
strong |
Status codes that may be returned by socket functions.
Definition at line 48 of file Socket.hpp.
|
strongprotected |
Types of protocols that the socket can use.
Enumerator | |
---|---|
Tcp | TCP protocol. |
Udp | UDP protocol. |
Definition at line 128 of file Socket.hpp.
|
virtual |
Destructor.
|
delete |
Deleted copy constructor.
|
noexcept |
Move constructor.
|
explicitprotected |
Default constructor.
This constructor can only be accessed by derived classes.
type | Type of the socket (TCP or UDP) |
|
protected |
Close the socket gracefully.
This function can only be accessed by derived classes.
|
protected |
Create the internal representation of the socket.
This function can only be accessed by derived classes.
|
protected |
Create the internal representation of the socket from a socket handle.
This function can only be accessed by derived classes.
handle | OS-specific handle of the socket to wrap |
|
nodiscardprotected |
Return the internal handle of the socket.
The returned handle may be invalid if the socket was not created yet (or already destroyed). This function can only be accessed by derived classes.
|
nodiscard |
Tell whether the socket is in blocking or non-blocking mode.
void sf::Socket::setBlocking | ( | bool | blocking | ) |
Set the blocking state of the socket.
In blocking mode, calls will not return until they have completed their task. For example, a call to Receive in blocking mode won't return until some data was actually received. In non-blocking mode, calls will always return immediately, using the return code to signal whether there was data available or not. By default, all sockets are blocking.
blocking | true to set the socket as blocking, false for non-blocking |
|
friend |
Definition at line 184 of file Socket.hpp.
|
staticconstexpr |
Some special values used by sockets.
Special value that tells the system to pick any available port
Definition at line 62 of file Socket.hpp.