Fix SFML deprecations and fix SFML warnings
Fix SFML deprecations and fix SFML warnings
This commit is contained in:
commit
ed013bd22c
|
@ -65,9 +65,10 @@ nonstd::optional<IpAddress> IpAddress::resolve(std::string address)
|
||||||
return Any;
|
return Any;
|
||||||
|
|
||||||
// Try to convert the address as a byte representation ("xxx.xxx.xxx.xxx")
|
// Try to convert the address as a byte representation ("xxx.xxx.xxx.xxx")
|
||||||
const std::uint32_t ip = inet_addr(address.data());
|
std::uint32_t ipaddr = 0;
|
||||||
if (ip != INADDR_NONE)
|
inet_pton(AF_INET, address.data(), &ipaddr);
|
||||||
return IpAddress(ntohl(ip));
|
if (ipaddr != INADDR_NONE)
|
||||||
|
return IpAddress(ntohl(ipaddr));
|
||||||
|
|
||||||
// Not a valid address, try to convert it as a host name
|
// Not a valid address, try to convert it as a host name
|
||||||
addrinfo hints{}; // Zero-initialize
|
addrinfo hints{}; // Zero-initialize
|
||||||
|
@ -106,10 +107,11 @@ IpAddress::IpAddress(std::uint32_t address) : m_address(address)
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::string IpAddress::toString() const
|
std::string IpAddress::toString() const
|
||||||
{
|
{
|
||||||
|
char address_str[INET_ADDRSTRLEN];
|
||||||
in_addr address{};
|
in_addr address{};
|
||||||
address.s_addr = htonl(m_address);
|
address.s_addr = htonl(m_address);
|
||||||
|
inet_ntop(AF_INET, &address, address_str, INET_ADDRSTRLEN);
|
||||||
return inet_ntoa(address);
|
return address_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// Low-level send/receive flags (OS-dependent)
|
// Low-level send/receive flags (OS-dependent)
|
||||||
|
@ -246,14 +245,11 @@ Socket::Status TcpSocket::send(const void* data, std::size_t size, std::size_t&
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (sent = 0; sent < size; sent += static_cast<std::size_t>(result))
|
for (sent = 0; sent < size; sent += static_cast<std::size_t>(result))
|
||||||
{
|
{
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wuseless-cast"
|
|
||||||
// Send a chunk of data
|
// Send a chunk of data
|
||||||
result = static_cast<int>(::send(getNativeHandle(),
|
result = static_cast<int>(::send(getNativeHandle(),
|
||||||
static_cast<const char*>(data) + sent,
|
static_cast<const char*>(data) + sent,
|
||||||
static_cast<SocketImpl::Size>(size - sent),
|
static_cast<SocketImpl::Size>(size - sent),
|
||||||
flags));
|
flags));
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
|
@ -283,14 +279,9 @@ Socket::Status TcpSocket::receive(void* data, std::size_t size, std::size_t& rec
|
||||||
err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl;
|
err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl;
|
||||||
return Status::Error;
|
return Status::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wuseless-cast"
|
|
||||||
// Receive a chunk of bytes
|
// Receive a chunk of bytes
|
||||||
const int sizeReceived = static_cast<int>(
|
const int sizeReceived = static_cast<int>(
|
||||||
recv(getNativeHandle(), static_cast<char*>(data), static_cast<SocketImpl::Size>(size), flags));
|
recv(getNativeHandle(), static_cast<char*>(data), static_cast<SocketImpl::Size>(size), flags));
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
|
|
||||||
// Check the number of bytes received
|
// Check the number of bytes received
|
||||||
if (sizeReceived > 0)
|
if (sizeReceived > 0)
|
||||||
{
|
{
|
||||||
|
@ -329,28 +320,15 @@ Socket::Status TcpSocket::send(Packet& packet)
|
||||||
m_blockToSendBuffer.resize(sizeof(packetSize) + size);
|
m_blockToSendBuffer.resize(sizeof(packetSize) + size);
|
||||||
|
|
||||||
// Copy the packet size and data into the block to send
|
// Copy the packet size and data into the block to send
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wnull-dereference" // False positive.
|
|
||||||
std::memcpy(m_blockToSendBuffer.data(), &packetSize, sizeof(packetSize));
|
std::memcpy(m_blockToSendBuffer.data(), &packetSize, sizeof(packetSize));
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
std::memcpy(m_blockToSendBuffer.data() + sizeof(packetSize), data, size);
|
std::memcpy(m_blockToSendBuffer.data() + sizeof(packetSize), data, size);
|
||||||
|
|
||||||
// These warnings are ignored here for portability, as even on Windows the
|
|
||||||
// signature of `send` might change depending on whether Win32 or MinGW is
|
|
||||||
// being used.
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wuseless-cast"
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
|
||||||
// Send the data block
|
// Send the data block
|
||||||
std::size_t sent = 0;
|
std::size_t sent = 0;
|
||||||
const Status status = send(m_blockToSendBuffer.data() + packet.m_sendPos,
|
const Status status = send(m_blockToSendBuffer.data() + packet.m_sendPos,
|
||||||
static_cast<SocketImpl::Size>(m_blockToSendBuffer.size() - packet.m_sendPos),
|
static_cast<SocketImpl::Size>(m_blockToSendBuffer.size() - packet.m_sendPos),
|
||||||
sent);
|
sent);
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
|
|
||||||
// In the case of a partial send, record the location to resume from
|
// In the case of a partial send, record the location to resume from
|
||||||
if (status == Status::Partial)
|
if (status == Status::Partial)
|
||||||
{
|
{
|
||||||
|
|
|
@ -114,9 +114,6 @@ Socket::Status UdpSocket::send(const void* data, std::size_t size, IpAddress rem
|
||||||
|
|
||||||
// Build the target address
|
// Build the target address
|
||||||
sockaddr_in address = SocketImpl::createAddress(remoteAddress.toInteger(), remotePort);
|
sockaddr_in address = SocketImpl::createAddress(remoteAddress.toInteger(), remotePort);
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wuseless-cast"
|
|
||||||
// Send the data (unlike TCP, all the data is always sent in one call)
|
// Send the data (unlike TCP, all the data is always sent in one call)
|
||||||
const int sent = static_cast<int>(
|
const int sent = static_cast<int>(
|
||||||
sendto(getNativeHandle(),
|
sendto(getNativeHandle(),
|
||||||
|
@ -125,7 +122,6 @@ Socket::Status UdpSocket::send(const void* data, std::size_t size, IpAddress rem
|
||||||
0,
|
0,
|
||||||
reinterpret_cast<sockaddr*>(&address),
|
reinterpret_cast<sockaddr*>(&address),
|
||||||
sizeof(address)));
|
sizeof(address)));
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if (sent < 0)
|
if (sent < 0)
|
||||||
|
@ -157,8 +153,6 @@ Socket::Status UdpSocket::receive(void* data,
|
||||||
// Data that will be filled with the other computer's address
|
// Data that will be filled with the other computer's address
|
||||||
sockaddr_in address = SocketImpl::createAddress(INADDR_ANY, 0);
|
sockaddr_in address = SocketImpl::createAddress(INADDR_ANY, 0);
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wuseless-cast"
|
|
||||||
// Receive a chunk of bytes
|
// Receive a chunk of bytes
|
||||||
SocketImpl::AddrLength addressSize = sizeof(address);
|
SocketImpl::AddrLength addressSize = sizeof(address);
|
||||||
const int sizeReceived = static_cast<int>(
|
const int sizeReceived = static_cast<int>(
|
||||||
|
@ -168,7 +162,6 @@ Socket::Status UdpSocket::receive(void* data,
|
||||||
0,
|
0,
|
||||||
reinterpret_cast<sockaddr*>(&address),
|
reinterpret_cast<sockaddr*>(&address),
|
||||||
&addressSize));
|
&addressSize));
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if (sizeReceived < 0)
|
if (sizeReceived < 0)
|
||||||
|
|
|
@ -47,14 +47,14 @@ namespace sf
|
||||||
template <typename IntegerType>
|
template <typename IntegerType>
|
||||||
[[nodiscard]] constexpr IntegerType toInteger(std::array<unsigned char,8> bytes)
|
[[nodiscard]] constexpr IntegerType toInteger(std::array<unsigned char,8> bytes)
|
||||||
{
|
{
|
||||||
return ((IntegerType)(bytes[0] << 0)+
|
return (((IntegerType)bytes[0] << 0)+
|
||||||
(IntegerType)(bytes[1] << 8)+
|
((IntegerType)bytes[1] << 8)+
|
||||||
(IntegerType)(bytes[2] << 16)+
|
((IntegerType)bytes[2] << 16)+
|
||||||
(IntegerType)(bytes[3] << 24)+
|
((IntegerType)bytes[3] << 24)+
|
||||||
(IntegerType)(bytes[4] << 32)+
|
((IntegerType)bytes[4] << 32)+
|
||||||
(IntegerType)(bytes[5] << 40)+
|
((IntegerType)bytes[5] << 40)+
|
||||||
(IntegerType)(bytes[6] << 48)+
|
((IntegerType)bytes[6] << 48)+
|
||||||
(IntegerType)(bytes[7] << 56));
|
((IntegerType)bytes[7] << 56));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] SFML_SYSTEM_API std::FILE* openFile(const ghc::filesystem::path& filename, std::string mode);
|
[[nodiscard]] SFML_SYSTEM_API std::FILE* openFile(const ghc::filesystem::path& filename, std::string mode);
|
||||||
|
|
Loading…
Reference in New Issue