op_pk_transfer()
Abstract
Replaces the contents of a packet with those of another packet.
Syntax
op_pk_transfer (from_pkptr, to_pkptr)
| Argument | Type | Description |
|---|---|---|
from_pkptr |
Packet * |
Source packet for the transfer. |
to_pkptr |
Packet * |
Destination packet for the transfer. |
Return Type
void
No return value.
Example
/* receive a frame from upper layer */
ul_pkptr = op_pk_get (0);
/* transfer contents to messenger packet and send onward */
op_pk_transfer (ul_pkptr, msg_pkptr);
op_pk_send (msg_pkptr, 1);
Details
Any objects contained in to_pkptr are deallocated before the transfer. Some information fields are preserved in to_pkptr; these are:
- creation time
- object ID of the creation module
- packet owner
- packet ID
Purpose
Provides a way to clone a packet by copying the contents of the packet into another existing packet. This function is faster than copying a packet field-by-field, and is useful when detailed information about the format of the source packet is not known to the code.
Errors
- Program Abort: Packet pointer references unowned packet (
<pk_id>). - Program Abort: Segmentation violation. (due to an invalid packet pointer, malformed packet, or malformed structure or packet field within the packet)
Reference
- Use the KP op_pk_copy() to clone a packet into a newly created packet