Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/main/cpp/datagrampacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,34 @@

using namespace LOG4CXX_NS::helpers;

namespace
{
#if LOG4CXX_ABI_VERSION <= 15
using PacketSizeType = int;
#else
using PacketSizeType = std::size_t;
#endif
}

struct DatagramPacket::DatagramPacketPriv
{
DatagramPacketPriv(void* buf1, int length1)
DatagramPacketPriv(void* buf1, PacketSizeType length1)
: buf(buf1), offset(0), length(length1), address(), port(0)
{
}

DatagramPacketPriv(void* buf1, int length1, InetAddressPtr address1,
DatagramPacketPriv(void* buf1, PacketSizeType length1, InetAddressPtr address1,
int port1)
: buf(buf1), offset(0), length(length1), address(address1), port(port1)
{
}

DatagramPacketPriv(void* buf1, int offset1, int length1)
DatagramPacketPriv(void* buf1, PacketSizeType offset1, PacketSizeType length1)
: buf(buf1), offset(offset1), length(length1), address(), port(0)
{
}

DatagramPacketPriv(void* buf1, int offset1, int length1,
DatagramPacketPriv(void* buf1, PacketSizeType offset1, PacketSizeType length1,
InetAddressPtr address1, int port1)
: buf(buf1), offset(offset1), length(length1), address(address1), port(port1)
{
Expand All @@ -48,10 +57,10 @@ struct DatagramPacket::DatagramPacketPriv
void* buf;

/** The offset of the data for this packet. */
int offset;
PacketSizeType offset;

/** The length of the data for this packet. */
int length;
PacketSizeType length;

/** The IP address for this packet. */
InetAddressPtr address;
Expand All @@ -64,30 +73,30 @@ IMPLEMENT_LOG4CXX_OBJECT(DatagramPacket)

/** Constructs a DatagramPacket for receiving packets of length
<code>length</code>. */
DatagramPacket::DatagramPacket(void* buf1, int length1)
DatagramPacket::DatagramPacket(void* buf1, PacketSizeType length1)
: m_priv(std::make_unique<DatagramPacketPriv>(buf1, length1))
{
}

/** Constructs a datagram packet for sending packets of length
<code>length/<code> to the specified port number on the specified
host. */
DatagramPacket::DatagramPacket(void* buf1, int length1, InetAddressPtr address1,
DatagramPacket::DatagramPacket(void* buf1, PacketSizeType length1, InetAddressPtr address1,
int port1)
: m_priv(std::make_unique<DatagramPacketPriv>(buf1, length1, address1, port1))
{
}

/** Constructs a DatagramPacket for receiving packets of length
<code>length</code>, specifying an offset into the buffer. */
DatagramPacket::DatagramPacket(void* buf1, int offset1, int length1)
DatagramPacket::DatagramPacket(void* buf1, PacketSizeType offset1, PacketSizeType length1)
: m_priv(std::make_unique<DatagramPacketPriv>(buf1, offset1, length1))
{
}
/** Constructs a datagram packet for sending packets of length
<code>length</code> with offset <code>offset</code> to the
specified port number on the specified host. */
DatagramPacket::DatagramPacket(void* buf1, int offset1, int length1,
DatagramPacket::DatagramPacket(void* buf1, PacketSizeType offset1, PacketSizeType length1,
InetAddressPtr address1, int port1)
: m_priv(std::make_unique<DatagramPacketPriv>(buf1, offset1, length1, address1, port1))
{
Expand All @@ -107,12 +116,12 @@ void* DatagramPacket::getData() const
return m_priv->buf;
}

int DatagramPacket::getLength() const
PacketSizeType DatagramPacket::getLength() const
{
return m_priv->length;
}

int DatagramPacket::getOffset() const
PacketSizeType DatagramPacket::getOffset() const
{
return m_priv->offset;
}
Expand All @@ -132,14 +141,14 @@ void DatagramPacket::setData(void* buf1)
m_priv->buf = buf1;
}

void DatagramPacket::setData(void* buf1, int offset1, int length1)
void DatagramPacket::setData(void* buf1, PacketSizeType offset1, PacketSizeType length1)
{
m_priv->buf = buf1;
m_priv->offset = offset1;
m_priv->length = length1;
}

void DatagramPacket::setLength(int length1)
void DatagramPacket::setLength(PacketSizeType length1)
{
m_priv->length = length1;
}
Expand Down
40 changes: 40 additions & 0 deletions src/main/include/log4cxx/helpers/datagrampacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <log4cxx/helpers/object.h>
#include <log4cxx/helpers/inetaddress.h>
#include <cstddef>

namespace LOG4CXX_NS
{
Expand All @@ -44,6 +45,7 @@ class LOG4CXX_EXPORT DatagramPacket : public helpers::Object
LOG4CXX_CAST_ENTRY(DatagramPacket)
END_LOG4CXX_CAST_MAP()

#if LOG4CXX_ABI_VERSION <= 15
/** Constructs a DatagramPacket for receiving packets of length
<code>length</code>. */
DatagramPacket(void* buf, int length);
Expand All @@ -62,6 +64,26 @@ class LOG4CXX_EXPORT DatagramPacket : public helpers::Object
specified port number on the specified host. */
DatagramPacket(void* buf, int offset, int length, InetAddressPtr address,
int port);
#else
/** Constructs a DatagramPacket for receiving packets of length
<code>length</code>. */
DatagramPacket(void* buf, std::size_t length);

/** Constructs a datagram packet for sending packets of length
<code>length</code> to the specified port number on the specified
host. */
DatagramPacket(void* buf, std::size_t length, InetAddressPtr address, int port);

/** Constructs a DatagramPacket for receiving packets of length
<code>length</code>, specifying an offset into the buffer. */
DatagramPacket(void* buf, std::size_t offset, std::size_t length);

/** Constructs a datagram packet for sending packets of length
<code>length</code> with offset <code>offset</code> to the
specified port number on the specified host. */
DatagramPacket(void* buf, std::size_t offset, std::size_t length, InetAddressPtr address,
int port);
#endif

~DatagramPacket();

Expand All @@ -72,13 +94,23 @@ class LOG4CXX_EXPORT DatagramPacket : public helpers::Object
/** Returns the data received or the data to be sent. */
void* getData() const;

#if LOG4CXX_ABI_VERSION <= 15
/** Returns the length of the data to be sent or the length of the
data received. */
int getLength() const;

/** Returns the offset of the data to be sent or the offset of the
data received. */
int getOffset() const;
#else
/** Returns the length of the data to be sent or the length of the
data received. */
std::size_t getLength() const;

/** Returns the offset of the data to be sent or the offset of the
data received. */
std::size_t getOffset() const;
#endif

/** Returns the port number on the remote host to which this
datagram is being sent or from which the datagram was received. */
Expand All @@ -89,11 +121,19 @@ class LOG4CXX_EXPORT DatagramPacket : public helpers::Object
/** Set the data buffer for this packet. */
void setData(void* buf1);

#if LOG4CXX_ABI_VERSION <= 15
/** Set the data buffer for this packet. */
void setData(void* buf1, int offset1, int length1);

/** Set the length for this packet. */
void setLength(int length1);
#else
/** Set the data buffer for this packet. */
void setData(void* buf1, std::size_t offset1, std::size_t length1);

/** Set the length for this packet. */
void setLength(std::size_t length1);
#endif

void setPort(int port1);

Expand Down
Loading