Added address arg to listen/bind on (sockets)

This commit is contained in:
Alec Iverson committed 2016-08-12 16:29:42 -07:00
1 parent 3c70f99028
commit 41fa94478a
6 files changed
+27 -8

No files matched your search

+6
View File
@@ -48,6 +48,12 @@ typedef struct
////////////////////////////////////////////////////////////
CSFML_NETWORK_API const sfIpAddress sfIpAddress_None;
////////////////////////////////////////////////////////////
/// \brief Value representing any address (0.0.0.0)
///
////////////////////////////////////////////////////////////
CSFML_NETWORK_API const sfIpAddress sfIpAddress_Any;
////////////////////////////////////////////////////////////
/// \brief Local host IP address (127.0.0.1, or "localhost")
///
+5 -1
View File
@@ -30,6 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Network/Export.h>
#include <SFML/Network/SocketStatus.h>
#include <SFML/Network/IpAddress.h>
#include <SFML/Network/Types.h>
@@ -98,13 +99,16 @@ CSFML_NETWORK_API unsigned short sfTcpListener_getLocalPort(const sfTcpListener*
/// If the socket was previously listening to another port,
/// it will be stopped first and bound to the new port.
///
/// If there is no specific address to listen to, pass sfIpAddress_Any
///
/// \param listener TCP listener object
/// \param port Port to listen for new connections
/// \param address Address of the interface to listen on
///
/// \return Status code
///
////////////////////////////////////////////////////////////
CSFML_NETWORK_API sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port);
CSFML_NETWORK_API sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port, sfIpAddress address);
////////////////////////////////////////////////////////////
/// \brief Accept a new connection
+6 -3
View File
@@ -101,13 +101,16 @@ CSFML_NETWORK_API unsigned short sfUdpSocket_getLocalPort(const sfUdpSocket* soc
/// system to automatically pick an available port, and then
/// call sfUdpSocket_getLocalPort to retrieve the chosen port.
///
/// \param socket UDP socket object
/// \param port Port to bind the socket to
/// If there is no specific address to listen to, pass sfIpAddress_Any
///
/// \param socket UDP socket object
/// \param port Port to bind the socket to
/// \param address Address of the interface to bind to
///
/// \return Status code
///
////////////////////////////////////////////////////////////
CSFML_NETWORK_API sfSocketStatus sfUdpSocket_bind(sfUdpSocket* socket, unsigned short port);
CSFML_NETWORK_API sfSocketStatus sfUdpSocket_bind(sfUdpSocket* socket, unsigned short port, sfIpAddress address);
////////////////////////////////////////////////////////////
/// \brief Unbind a UDP socket from the local port to which it is bound
+4
View File
@@ -53,6 +53,10 @@ namespace
const sfIpAddress sfIpAddress_None = sfIpAddress_fromBytes(0, 0, 0, 0);
////////////////////////////////////////////////////////////
const sfIpAddress sfIpAddress_Any = sfIpAddress_fromBytes(0, 0, 0, 0);
////////////////////////////////////////////////////////////
const sfIpAddress sfIpAddress_LocalHost = sfIpAddress_fromBytes(127, 0, 0, 1);
+3 -2
View File
@@ -67,11 +67,12 @@ unsigned short sfTcpListener_getLocalPort(const sfTcpListener* listener)
////////////////////////////////////////////////////////////
sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port)
sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port, sfIpAddress address)
{
CSFML_CHECK_RETURN(listener, sfSocketError);
return static_cast<sfSocketStatus>(listener->This.listen(port));
sf::IpAddress sfmlAddress(address.address);
return static_cast<sfSocketStatus>(listener->This.listen(port, sfmlAddress));
}
+3 -2
View File
@@ -68,11 +68,12 @@ unsigned short sfUdpSocket_getLocalPort(const sfUdpSocket* socket)
////////////////////////////////////////////////////////////
sfSocketStatus sfUdpSocket_bind(sfUdpSocket* socket, unsigned short port)
sfSocketStatus sfUdpSocket_bind(sfUdpSocket* socket, unsigned short port, sfIpAddress address)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
return static_cast<sfSocketStatus>(socket->This.bind(port));
sf::IpAddress sfmlAddress(address.address);
return static_cast<sfSocketStatus>(socket->This.bind(port, sfmlAddress));
}