mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-27 21:36:13 +01:00
Added address arg to listen/bind on (sockets)
This commit is contained in:
1 parent
3c70f99028
commit
41fa94478a
6 files changed
+27
-8
No files matched your search
@@ -48,6 +48,12 @@ typedef struct
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_NETWORK_API const sfIpAddress sfIpAddress_None;
|
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")
|
/// \brief Local host IP address (127.0.0.1, or "localhost")
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Export.h>
|
#include <SFML/Network/Export.h>
|
||||||
#include <SFML/Network/SocketStatus.h>
|
#include <SFML/Network/SocketStatus.h>
|
||||||
|
#include <SFML/Network/IpAddress.h>
|
||||||
#include <SFML/Network/Types.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,
|
/// If the socket was previously listening to another port,
|
||||||
/// it will be stopped first and bound to the new 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 listener TCP listener object
|
||||||
/// \param port Port to listen for new connections
|
/// \param port Port to listen for new connections
|
||||||
|
/// \param address Address of the interface to listen on
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \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
|
/// \brief Accept a new connection
|
||||||
|
|||||||
@@ -101,13 +101,16 @@ CSFML_NETWORK_API unsigned short sfUdpSocket_getLocalPort(const sfUdpSocket* soc
|
|||||||
/// system to automatically pick an available port, and then
|
/// system to automatically pick an available port, and then
|
||||||
/// call sfUdpSocket_getLocalPort to retrieve the chosen port.
|
/// call sfUdpSocket_getLocalPort to retrieve the chosen port.
|
||||||
///
|
///
|
||||||
/// \param socket UDP socket object
|
/// If there is no specific address to listen to, pass sfIpAddress_Any
|
||||||
/// \param port Port to bind the socket to
|
///
|
||||||
|
/// \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
|
/// \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
|
/// \brief Unbind a UDP socket from the local port to which it is bound
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ namespace
|
|||||||
const sfIpAddress sfIpAddress_None = sfIpAddress_fromBytes(0, 0, 0, 0);
|
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);
|
const sfIpAddress sfIpAddress_LocalHost = sfIpAddress_fromBytes(127, 0, 0, 1);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user