Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions
MsgHeaderIterator Struct Reference

Allows iteration through the list of message headers received in the control parameter of the socket_sendto_control / socket_recvfrom_control methods. More...

#include <MsgHeader.h>

Public Member Functions

 MsgHeaderIterator (nsapi_msghdr_t *hdr, nsapi_size_t size)
 Create a MsgHeaderIterator over given nsapi_msghdr_t list. More...
 
bool has_next ()
 Checks if the next address of the iterator is a valid list member. More...
 
nsapi_msghdr_tnext ()
 Returns next element of the list. More...
 

Detailed Description

Allows iteration through the list of message headers received in the control parameter of the socket_sendto_control / socket_recvfrom_control methods.

Members types

MsgHeaderIterator works on the list which members are of type nsapi_msghdr_t or other types extending this struct. For example nsapi_pktinfo:

typedef struct nsapi_pktinfo {
nsapi_addr_t ipi_addr;
int ipi_ifindex;
void *network_interface;

There are two requirements for such structures to work well with MsgHeaderIterator.

nsapi_pktinfo_t pkt_info;
pkt_info.hdr.len = sizeof(nsapi_pktinfo_t);

This value is used in the MsgHeaderIterator to calculate proper addresses of the list elements.

Example

Code presenting minimal usage example.

struct default_buffer_t {
default_buffer_t()
{
el1.hdr.len = sizeof(nsapi_pktinfo_t);
el2.len = sizeof(nsapi_msghdr_t);
el3.len = sizeof(nsapi_msghdr_t);
el4.hdr.len = sizeof(nsapi_pktinfo_t);
}
};
default_buffer buff;
nsapi_msghdr_t *hdr_p = reinterpret_cast<nsapi_msghdr_t *>(&buff);
MsgHeaderIterator it(hdr_p, sizeof(buff));
it.has_next() // returns true
auto p1 = it.next() // returns pointer to el1
auto p2 = it.next() // returns pointer to el2
auto p3 = it.next() // returns pointer to el3
auto p4 = it.next() // returns pointer to el4
it.has_next() // returns false
auto p5 = it.next() // returns nullptr
Note
More usage examples are implemented in the MsgHeaderIterator unit test in netsocket/tests/UNITTESTS/NetworkStack/test_MsgHeaderIterator.cpp

Definition at line 91 of file MsgHeader.h.

Constructor & Destructor Documentation

Create a MsgHeaderIterator over given nsapi_msghdr_t list.

Parameters
hdrPointer to the first list element.
sizeSize of the whole list.

Definition at line 97 of file MsgHeader.h.

Member Function Documentation

bool has_next ( )

Checks if the next address of the iterator is a valid list member.

Return values
Trueif the next address is a valid member.
Falseotherwise.

Definition at line 108 of file MsgHeader.h.

nsapi_msghdr_t* next ( )

Returns next element of the list.

Return values
nullptrif the list doesn't contain next element.
Pointerto the next element otherwise.

Definition at line 134 of file MsgHeader.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.