mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 07:41:05 +08:00
Fix conversion warnings for the Network module
This commit is contained in:
parent
e0f2356102
commit
0468612ac0
@ -549,7 +549,7 @@ Ftp::Response Ftp::DataChannel::open(Ftp::TransferMode mode)
|
|||||||
// Extract the current number
|
// Extract the current number
|
||||||
while (isdigit(str[index]))
|
while (isdigit(str[index]))
|
||||||
{
|
{
|
||||||
data[i] = data[i] * 10 + (str[index] - '0');
|
data[i] = static_cast<Uint8>(data[i] * 10) + static_cast<Uint8>(str[index] - '0');
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,11 +558,11 @@ Ftp::Response Ftp::DataChannel::open(Ftp::TransferMode mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reconstruct connection port and address
|
// Reconstruct connection port and address
|
||||||
unsigned short port = data[4] * 256 + data[5];
|
unsigned short port = static_cast<Uint8>(data[4] * 256) + data[5];
|
||||||
IpAddress address(static_cast<Uint8>(data[0]),
|
IpAddress address(data[0],
|
||||||
static_cast<Uint8>(data[1]),
|
data[1],
|
||||||
static_cast<Uint8>(data[2]),
|
data[2],
|
||||||
static_cast<Uint8>(data[3]));
|
data[3]);
|
||||||
|
|
||||||
// Connect the data channel to the server
|
// Connect the data channel to the server
|
||||||
if (m_dataSocket.connect(address, port) == Socket::Done)
|
if (m_dataSocket.connect(address, port) == Socket::Done)
|
||||||
|
@ -208,8 +208,8 @@ void Http::Response::parse(const std::string& data)
|
|||||||
(toLower(version.substr(0, 5)) == "http/") &&
|
(toLower(version.substr(0, 5)) == "http/") &&
|
||||||
isdigit(version[5]) && isdigit(version[7]))
|
isdigit(version[5]) && isdigit(version[7]))
|
||||||
{
|
{
|
||||||
m_majorVersion = version[5] - '0';
|
m_majorVersion = static_cast<unsigned int>(version[5] - '0');
|
||||||
m_minorVersion = version[7] - '0';
|
m_minorVersion = static_cast<unsigned int>(version[7] - '0');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -69,7 +69,7 @@ m_valid (false)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IpAddress::IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) :
|
IpAddress::IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) :
|
||||||
m_address(htonl((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3)),
|
m_address(htonl(static_cast<uint32_t>((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3))),
|
||||||
m_valid (true)
|
m_valid (true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ Packet& Packet::operator >>(Int16& data)
|
|||||||
if (checkSize(sizeof(data)))
|
if (checkSize(sizeof(data)))
|
||||||
{
|
{
|
||||||
std::memcpy(&data, &m_data[m_readPos], sizeof(data));
|
std::memcpy(&data, &m_data[m_readPos], sizeof(data));
|
||||||
data = ntohs(data);
|
data = static_cast<Int16>(ntohs(static_cast<uint16_t>(data)));
|
||||||
m_readPos += sizeof(data);
|
m_readPos += sizeof(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ Packet& Packet::operator >>(Int32& data)
|
|||||||
if (checkSize(sizeof(data)))
|
if (checkSize(sizeof(data)))
|
||||||
{
|
{
|
||||||
std::memcpy(&data, &m_data[m_readPos], sizeof(data));
|
std::memcpy(&data, &m_data[m_readPos], sizeof(data));
|
||||||
data = ntohl(data);
|
data = static_cast<Int16>(ntohl(static_cast<uint32_t>(data)));
|
||||||
m_readPos += sizeof(data);
|
m_readPos += sizeof(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,7 +412,7 @@ Packet& Packet::operator <<(Uint8 data)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Packet& Packet::operator <<(Int16 data)
|
Packet& Packet::operator <<(Int16 data)
|
||||||
{
|
{
|
||||||
Int16 toWrite = htons(data);
|
Int16 toWrite = static_cast<Int16>(htons(static_cast<uint16_t>(data)));
|
||||||
append(&toWrite, sizeof(toWrite));
|
append(&toWrite, sizeof(toWrite));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -430,7 +430,7 @@ Packet& Packet::operator <<(Uint16 data)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Packet& Packet::operator <<(Int32 data)
|
Packet& Packet::operator <<(Int32 data)
|
||||||
{
|
{
|
||||||
Int32 toWrite = htonl(data);
|
Int32 toWrite = static_cast<Int16>(htonl(static_cast<uint32_t>(data)));
|
||||||
append(&toWrite, sizeof(toWrite));
|
append(&toWrite, sizeof(toWrite));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ Socket::Status TcpSocket::connect(const IpAddress& remoteAddress, unsigned short
|
|||||||
time.tv_usec = static_cast<long>(timeout.asMicroseconds() % 1000000);
|
time.tv_usec = static_cast<long>(timeout.asMicroseconds() % 1000000);
|
||||||
|
|
||||||
// Wait for something to write on our socket (which means that the connection request has returned)
|
// Wait for something to write on our socket (which means that the connection request has returned)
|
||||||
if (select(static_cast<int>(getHandle() + 1), NULL, &selector, NULL, &time) > 0)
|
if (select(getHandle() + 1, NULL, &selector, NULL, &time) > 0)
|
||||||
{
|
{
|
||||||
// At this point the connection may have been either accepted or refused.
|
// At this point the connection may have been either accepted or refused.
|
||||||
// To know whether it's a success or a failure, we must check the address of the connected peer
|
// To know whether it's a success or a failure, we must check the address of the connected peer
|
||||||
@ -242,11 +242,14 @@ Socket::Status TcpSocket::send(const void* data, std::size_t size, std::size_t&
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Loop until every byte has been sent
|
// Loop until every byte has been sent
|
||||||
int result = 0;
|
ssize_t result = 0;
|
||||||
for (sent = 0; sent < size; sent += 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 = ::send(getHandle(), static_cast<const char*>(data) + sent, static_cast<int>(size - sent), flags);
|
result = ::send(getHandle(), static_cast<const char*>(data) + sent, static_cast<priv::SocketImpl::Size>(size - sent), flags);
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
@ -277,8 +280,11 @@ Socket::Status TcpSocket::receive(void* data, std::size_t size, std::size_t& rec
|
|||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wuseless-cast"
|
||||||
// Receive a chunk of bytes
|
// Receive a chunk of bytes
|
||||||
int sizeReceived = recv(getHandle(), static_cast<char*>(data), static_cast<int>(size), flags);
|
int sizeReceived = static_cast<int>(recv(getHandle(), static_cast<char*>(data), static_cast<priv::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)
|
||||||
@ -324,9 +330,12 @@ Socket::Status TcpSocket::send(Packet& packet)
|
|||||||
if (size > 0)
|
if (size > 0)
|
||||||
std::memcpy(&blockToSend[0] + sizeof(packetSize), data, size);
|
std::memcpy(&blockToSend[0] + sizeof(packetSize), data, size);
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wuseless-cast"
|
||||||
// Send the data block
|
// Send the data block
|
||||||
std::size_t sent;
|
std::size_t sent;
|
||||||
Status status = send(&blockToSend[0] + packet.m_sendPos, blockToSend.size() - packet.m_sendPos, sent);
|
Status status = send(&blockToSend[0] + packet.m_sendPos, static_cast<priv::SocketImpl::Size>(blockToSend.size() - packet.m_sendPos), sent);
|
||||||
|
#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 == Partial)
|
if (status == Partial)
|
||||||
@ -379,7 +388,7 @@ Socket::Status TcpSocket::receive(Packet& packet)
|
|||||||
while (m_pendingPacket.Data.size() < packetSize)
|
while (m_pendingPacket.Data.size() < packetSize)
|
||||||
{
|
{
|
||||||
// Receive a chunk of data
|
// Receive a chunk of data
|
||||||
std::size_t sizeToGet = std::min(static_cast<std::size_t>(packetSize - m_pendingPacket.Data.size()), sizeof(buffer));
|
std::size_t sizeToGet = std::min(packetSize - m_pendingPacket.Data.size(), sizeof(buffer));
|
||||||
Status status = receive(buffer, sizeToGet, received);
|
Status status = receive(buffer, sizeToGet, received);
|
||||||
if (status != Done)
|
if (status != Done)
|
||||||
return status;
|
return status;
|
||||||
|
@ -113,8 +113,11 @@ Socket::Status UdpSocket::send(const void* data, std::size_t size, const IpAddre
|
|||||||
// Build the target address
|
// Build the target address
|
||||||
sockaddr_in address = priv::SocketImpl::createAddress(remoteAddress.toInteger(), remotePort);
|
sockaddr_in address = priv::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)
|
||||||
int sent = sendto(getHandle(), static_cast<const char*>(data), static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), sizeof(address));
|
int sent = static_cast<int>(sendto(getHandle(), static_cast<const char*>(data), static_cast<priv::SocketImpl::Size>(size), 0, reinterpret_cast<sockaddr*>(&address), sizeof(address)));
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if (sent < 0)
|
if (sent < 0)
|
||||||
@ -142,9 +145,12 @@ Socket::Status UdpSocket::receive(void* data, std::size_t size, std::size_t& rec
|
|||||||
// 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 = priv::SocketImpl::createAddress(INADDR_ANY, 0);
|
sockaddr_in address = priv::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
|
||||||
priv::SocketImpl::AddrLength addressSize = sizeof(address);
|
priv::SocketImpl::AddrLength addressSize = sizeof(address);
|
||||||
int sizeReceived = recvfrom(getHandle(), static_cast<char*>(data), static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), &addressSize);
|
int sizeReceived = static_cast<int>(recvfrom(getHandle(), static_cast<char*>(data), static_cast<priv::SocketImpl::Size>(size), 0, reinterpret_cast<sockaddr*>(&address), &addressSize));
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if (sizeReceived < 0)
|
if (sizeReceived < 0)
|
||||||
|
@ -55,6 +55,7 @@ public:
|
|||||||
// Types
|
// Types
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
typedef socklen_t AddrLength;
|
typedef socklen_t AddrLength;
|
||||||
|
typedef size_t Size;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create an internal sockaddr_in address
|
/// \brief Create an internal sockaddr_in address
|
||||||
|
@ -58,6 +58,7 @@ public:
|
|||||||
// Types
|
// Types
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
typedef int AddrLength;
|
typedef int AddrLength;
|
||||||
|
typedef int Size;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create an internal sockaddr_in address
|
/// \brief Create an internal sockaddr_in address
|
||||||
|
Loading…
Reference in New Issue
Block a user