Replaced char* arguments with void* for raw data
This commit is contained in:
parent
69f387de22
commit
8d0da1d9d6
8 changed files with 37 additions and 37 deletions
|
@ -71,7 +71,7 @@ void Packet::clear()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* Packet::getData() const
|
||||
const void* Packet::getData() const
|
||||
{
|
||||
return !m_data.empty() ? &m_data[0] : NULL;
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ Packet& Packet::operator >>(Int8& data)
|
|||
{
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = *reinterpret_cast<const Int8*>(getData() + m_readPos);
|
||||
data = *reinterpret_cast<const Int8*>(&m_data[m_readPos]);
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ Packet& Packet::operator >>(Uint8& data)
|
|||
{
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = *reinterpret_cast<const Uint8*>(getData() + m_readPos);
|
||||
data = *reinterpret_cast<const Uint8*>(&m_data[m_readPos]);
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ Packet& Packet::operator >>(Int16& data)
|
|||
{
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = ntohs(*reinterpret_cast<const Int16*>(getData() + m_readPos));
|
||||
data = ntohs(*reinterpret_cast<const Int16*>(&m_data[m_readPos]));
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ Packet& Packet::operator >>(Uint16& data)
|
|||
{
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = ntohs(*reinterpret_cast<const Uint16*>(getData() + m_readPos));
|
||||
data = ntohs(*reinterpret_cast<const Uint16*>(&m_data[m_readPos]));
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ Packet& Packet::operator >>(Int32& data)
|
|||
{
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = ntohl(*reinterpret_cast<const Int32*>(getData() + m_readPos));
|
||||
data = ntohl(*reinterpret_cast<const Int32*>(&m_data[m_readPos]));
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ Packet& Packet::operator >>(Uint32& data)
|
|||
{
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = ntohl(*reinterpret_cast<const Uint32*>(getData() + m_readPos));
|
||||
data = ntohl(*reinterpret_cast<const Uint32*>(&m_data[m_readPos]));
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ Packet& Packet::operator >>(float& data)
|
|||
{
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = *reinterpret_cast<const float*>(getData() + m_readPos);
|
||||
data = *reinterpret_cast<const float*>(&m_data[m_readPos]);
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ Packet& Packet::operator >>(double& data)
|
|||
{
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
data = *reinterpret_cast<const double*>(getData() + m_readPos);
|
||||
data = *reinterpret_cast<const double*>(&m_data[m_readPos]);
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ Packet& Packet::operator >>(char* data)
|
|||
if ((length > 0) && checkSize(length))
|
||||
{
|
||||
// Then extract characters
|
||||
std::memcpy(data, getData() + m_readPos, length);
|
||||
std::memcpy(data, &m_data[m_readPos], length);
|
||||
data[length] = '\0';
|
||||
|
||||
// Update reading position
|
||||
|
@ -245,7 +245,7 @@ Packet& Packet::operator >>(std::string& data)
|
|||
if ((length > 0) && checkSize(length))
|
||||
{
|
||||
// Then extract characters
|
||||
data.assign(getData() + m_readPos, length);
|
||||
data.assign(&m_data[m_readPos], length);
|
||||
|
||||
// Update reading position
|
||||
m_readPos += length;
|
||||
|
@ -496,7 +496,7 @@ bool Packet::checkSize(std::size_t size)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* Packet::onSend(std::size_t& size)
|
||||
const void* Packet::onSend(std::size_t& size)
|
||||
{
|
||||
size = getDataSize();
|
||||
return getData();
|
||||
|
@ -504,7 +504,7 @@ const char* Packet::onSend(std::size_t& size)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Packet::onReceive(const char* data, std::size_t size)
|
||||
void Packet::onReceive(const void* data, std::size_t size)
|
||||
{
|
||||
append(data, size);
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ void TcpSocket::disconnect()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status TcpSocket::send(const char* data, std::size_t size)
|
||||
Socket::Status TcpSocket::send(const void* data, std::size_t size)
|
||||
{
|
||||
// Check the parameters
|
||||
if (!data || (size == 0))
|
||||
|
@ -221,7 +221,7 @@ Socket::Status TcpSocket::send(const char* data, std::size_t size)
|
|||
for (int length = 0; length < sizeToSend; length += sent)
|
||||
{
|
||||
// Send a chunk of data
|
||||
sent = ::send(getHandle(), data + length, sizeToSend - length, 0);
|
||||
sent = ::send(getHandle(), static_cast<const char*>(data) + length, sizeToSend - length, 0);
|
||||
|
||||
// Check for errors
|
||||
if (sent < 0)
|
||||
|
@ -233,7 +233,7 @@ Socket::Status TcpSocket::send(const char* data, std::size_t size)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status TcpSocket::receive(char* data, std::size_t size, std::size_t& received)
|
||||
Socket::Status TcpSocket::receive(void* data, std::size_t size, std::size_t& received)
|
||||
{
|
||||
// First clear the variables to fill
|
||||
received = 0;
|
||||
|
@ -246,7 +246,7 @@ Socket::Status TcpSocket::receive(char* data, std::size_t size, std::size_t& rec
|
|||
}
|
||||
|
||||
// Receive a chunk of bytes
|
||||
int sizeReceived = recv(getHandle(), data, static_cast<int>(size), 0);
|
||||
int sizeReceived = recv(getHandle(), static_cast<char*>(data), static_cast<int>(size), 0);
|
||||
|
||||
// Check the number of bytes received
|
||||
if (sizeReceived > 0)
|
||||
|
@ -274,7 +274,7 @@ Socket::Status TcpSocket::send(Packet& packet)
|
|||
|
||||
// Get the data to send from the packet
|
||||
std::size_t size = 0;
|
||||
const char* data = packet.onSend(size);
|
||||
const void* data = packet.onSend(size);
|
||||
|
||||
// First send the packet size
|
||||
Uint32 packetSize = htonl(static_cast<Uint32>(size));
|
||||
|
|
|
@ -90,7 +90,7 @@ void UdpSocket::unbind()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status UdpSocket::send(const char* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort)
|
||||
Socket::Status UdpSocket::send(const void* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort)
|
||||
{
|
||||
// Create the internal socket if it doesn't exist
|
||||
create();
|
||||
|
@ -107,7 +107,7 @@ Socket::Status UdpSocket::send(const char* data, std::size_t size, const IpAddre
|
|||
sockaddr_in address = priv::SocketImpl::createAddress(remoteAddress.toInteger(), remotePort);
|
||||
|
||||
// Send the data (unlike TCP, all the data is always sent in one call)
|
||||
int sent = sendto(getHandle(), data, static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), sizeof(address));
|
||||
int sent = sendto(getHandle(), static_cast<const char*>(data), static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), sizeof(address));
|
||||
|
||||
// Check for errors
|
||||
if (sent < 0)
|
||||
|
@ -118,7 +118,7 @@ Socket::Status UdpSocket::send(const char* data, std::size_t size, const IpAddre
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket::Status UdpSocket::receive(char* data, std::size_t size, std::size_t& received, IpAddress& remoteAddress, unsigned short& remotePort)
|
||||
Socket::Status UdpSocket::receive(void* data, std::size_t size, std::size_t& received, IpAddress& remoteAddress, unsigned short& remotePort)
|
||||
{
|
||||
// First clear the variables to fill
|
||||
received = 0;
|
||||
|
@ -137,7 +137,7 @@ Socket::Status UdpSocket::receive(char* data, std::size_t size, std::size_t& rec
|
|||
|
||||
// Receive a chunk of bytes
|
||||
priv::SocketImpl::AddrLength addressSize = sizeof(address);
|
||||
int sizeReceived = recvfrom(getHandle(), data, static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), &addressSize);
|
||||
int sizeReceived = recvfrom(getHandle(), static_cast<char*>(data), static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&address), &addressSize);
|
||||
|
||||
// Check for errors
|
||||
if (sizeReceived < 0)
|
||||
|
@ -165,7 +165,7 @@ Socket::Status UdpSocket::send(Packet& packet, const IpAddress& remoteAddress, u
|
|||
|
||||
// Get the data to send from the packet
|
||||
std::size_t size = 0;
|
||||
const char* data = packet.onSend(size);
|
||||
const void* data = packet.onSend(size);
|
||||
|
||||
// Send it
|
||||
return send(data, size, remoteAddress, remotePort);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue