Net module

SocketPacket

Default packet type emitted by sockets.

SocketPacket

#include <icy/net/socket.h>

Inherits: RawPacket

Default packet type emitted by sockets.

SocketPacket carries the remote peer address plus a borrowed view of the received byte buffer for zero-copy processing inside the receive callback.

The referenced packet buffer lifetime is only guaranteed for the duration of the receiver callback.

Public Methods

ReturnNameDescription
SocketPacket inlineConstructs a SocketPacket wrapping the received buffer.
SocketPacket inlineCopy constructor; shares the underlying buffer reference.
PacketInfo *packetInfo const inlineReturns the PacketInfo for this socket packet.
voidprint virtual const inlinePrints a one-line description of the packet to os.
std::unique_ptr< IPacket >clone virtual const inlineReturns a heap-allocated copy of this SocketPacket.
ssize_tread virtual inlineNot supported; always throws std::logic_error.
voidwrite virtual const inlineAppends the packet payload to buf.
const char *className virtual const inline#### Returns

SocketPacket

inline

inline SocketPacket(const Socket::Ptr & socket, const MutableBuffer & buffer, const Address & peerAddress)

Constructs a SocketPacket wrapping the received buffer.

The buffer data pointer remains valid only for the duration of the enclosing receive callback; do not retain references beyond that scope.

Parameters

  • socket Shared pointer to the receiving socket.

  • buffer View of the raw received bytes.

  • peerAddress Address of the remote sender.


SocketPacket

inline

inline SocketPacket(const SocketPacket & that)

Copy constructor; shares the underlying buffer reference.

Parameters


packetInfo

const inline

inline PacketInfo * packetInfo() const

Returns the PacketInfo for this socket packet.

Returns

Pointer to the associated PacketInfo (never null for a valid packet).


print

virtual const inline

virtual inline void print(std::ostream & os) const

Prints a one-line description of the packet to os.

Parameters

  • os Output stream to write to.

clone

virtual const inline

virtual inline std::unique_ptr< IPacket > clone() const

Returns a heap-allocated copy of this SocketPacket.


read

virtual inline

virtual inline ssize_t read(const ConstBuffer &)

Not supported; always throws std::logic_error.


write

virtual const inline

virtual inline void write(Buffer & buf) const

Appends the packet payload to buf.

Parameters

  • buf Destination buffer to append raw bytes to.

className

virtual const inline

virtual inline const char * className() const

Returns

The string "SocketPacket".