Added TcpListener::GetLocalPort()
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1480 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
87f712e0c6
commit
507f467390
@ -99,6 +99,9 @@ public :
|
|||||||
/// Note that this function know nothing about the standard
|
/// Note that this function know nothing about the standard
|
||||||
/// fonts installed on the user's system, thus you can't
|
/// fonts installed on the user's system, thus you can't
|
||||||
/// load them directly.
|
/// load them directly.
|
||||||
|
/// Warning: SFML cannot preload all the font data in this
|
||||||
|
/// function, so the buffer pointed by \a data has to remain
|
||||||
|
/// valid as long as the font is used.
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the file data in memory
|
/// \param data Pointer to the file data in memory
|
||||||
/// \param sizeInBytes Size of the data to load, in bytes
|
/// \param sizeInBytes Size of the data to load, in bytes
|
||||||
|
@ -49,6 +49,19 @@ public :
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
TcpListener();
|
TcpListener();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get the port to which the socket is bound locally
|
||||||
|
///
|
||||||
|
/// If the socket is not listening to a port, this function
|
||||||
|
/// returns 0.
|
||||||
|
///
|
||||||
|
/// \return Port to which the socket is bound
|
||||||
|
///
|
||||||
|
/// \see Listen
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
unsigned short GetLocalPort() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Start listening for connections
|
/// \brief Start listening for connections
|
||||||
///
|
///
|
||||||
|
@ -159,7 +159,7 @@ IpAddress IpAddress::GetLocalAddress()
|
|||||||
priv::SocketImpl::Close(sock);
|
priv::SocketImpl::Close(sock);
|
||||||
|
|
||||||
// Finally build the IP address
|
// Finally build the IP address
|
||||||
localAddress.myAddress = address.sin_addr.s_addr;
|
localAddress = IpAddress(ntohl(address.sin_addr.s_addr));
|
||||||
|
|
||||||
return localAddress;
|
return localAddress;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,25 @@ Socket(Tcp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
unsigned short TcpListener::GetLocalPort() const
|
||||||
|
{
|
||||||
|
if (GetHandle() != priv::SocketImpl::InvalidSocket())
|
||||||
|
{
|
||||||
|
// Retrieve informations about the local end of the socket
|
||||||
|
sockaddr_in address;
|
||||||
|
priv::SocketImpl::AddrLength size = sizeof(address);
|
||||||
|
if (getsockname(GetHandle(), reinterpret_cast<sockaddr*>(&address), &size) != -1)
|
||||||
|
{
|
||||||
|
return ntohs(address.sin_port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We failed to retrieve the port
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status TcpListener::Listen(unsigned short port)
|
Socket::Status TcpListener::Listen(unsigned short port)
|
||||||
{
|
{
|
||||||
|
@ -30,8 +30,8 @@
|
|||||||
#include <SFML/Network/Packet.hpp>
|
#include <SFML/Network/Packet.hpp>
|
||||||
#include <SFML/Network/SocketImpl.hpp>
|
#include <SFML/Network/SocketImpl.hpp>
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(disable : 4127) // "conditional expression is constant" generated by the FD_SET macro
|
#pragma warning(disable : 4127) // "conditional expression is constant" generated by the FD_SET macro
|
||||||
|
Loading…
Reference in New Issue
Block a user