Skip to content

Commit c3d16f7

Browse files
Adding documentation and minor code changes
Doxygen documentation for MsgHeaderIterator was added. Type used for alignment of the nsapi_msghdr_t struct was changed.
1 parent ec3f437 commit c3d16f7

File tree

3 files changed

+80
-6
lines changed

3 files changed

+80
-6
lines changed

connectivity/lwipstack/include/lwipstack/lwipopts.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@
311311

312312
#endif
313313

314-
// FIXME: Add compile time configuration and define conditionaly
315314
#define LWIP_NETBUF_RECVINFO MBED_CONF_LWIP_NETBUF_RECVINFO_ENABLED
316315

317316
// Make sure we default these to off, so

connectivity/netsocket/include/netsocket/MsgHeader.h

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,88 @@
2323
/**
2424
* Allows iteration through the list of message headers received in the control parameter of the
2525
* socket_sendto_control / socket_recvfrom_control methods.
26+
*
27+
* @par Members types
28+
*
29+
* MsgHeaderIterator works on the list which members are of type nsapi_msghdr_t or other types
30+
* extending this struct. For example nsapi_pktinfo:
31+
*
32+
* @code
33+
typedef struct nsapi_pktinfo {
34+
nsapi_msghdr_t hdr;
35+
nsapi_addr_t ipi_addr;
36+
int ipi_ifindex;
37+
void *network_interface;
38+
} nsapi_pktinfo_t;
39+
* @endcode
40+
*
41+
* There are two requirements for such structs to work well with MsgHeaderIterator:
42+
* first element needs to of type nsapi_msghdr_t
43+
* value of the field len of the nsapi_msghdr_t needs to bet set to the size of the whole extending type. For example:
44+
*
45+
* @code
46+
nsapi_pktinfo_t pkt_info;
47+
pkt_info.hdr.len = sizeof(nsapi_pktinfo_t);
48+
* @endcode
49+
*
50+
* This value is used in the MsgHeaderIterator to calculate proper addresses of the list elements.
51+
*
52+
* @par Example
53+
*
54+
* Code presenting minimal usage example.
55+
*
56+
* @code
57+
*
58+
struct default_buffer_t {
59+
default_buffer_t()
60+
{
61+
el1.hdr.len = sizeof(nsapi_pktinfo_t);
62+
el2.len = sizeof(nsapi_msghdr_t);
63+
el3.len = sizeof(nsapi_msghdr_t);
64+
el4.hdr.len = sizeof(nsapi_pktinfo_t);
65+
}
66+
nsapi_pktinfo_t el1;
67+
nsapi_msghdr_t el2;
68+
nsapi_msghdr_t el3;
69+
nsapi_pktinfo_t el4;
70+
};
71+
72+
default_buffer buff;
73+
nsapi_msghdr_t *hdr_p = reinterpret_cast<nsapi_msghdr_t *>(&buff);
74+
75+
MsgHeaderIterator it(hdr_p, sizeof(buff));
76+
77+
it.has_next() // returns true
78+
auto p1 = it.next() // returns pointer to el1
79+
auto p2 = it.next() // returns pointer to el2
80+
auto p3 = it.next() // returns pointer to el3
81+
auto p4 = it.next() // returns pointer to el4
82+
83+
it.has_next() // returns false
84+
auto p5 = it.next() // returns nullptr
85+
* @endcode
86+
*
87+
* @note More usage examples are implemented in the `MsgHeaderIterator` unit test
88+
* in `netsocket/tests/UNITTESTS/NetworkStack/test_MsgHeaderIterator.cpp`
2689
*/
2790

2891
struct MsgHeaderIterator {
29-
// Constructor takes pointer to the first header element and size of the whole list.
92+
/** Create a MsgHeaderIterator over given nsapi_msghdr_t list.
93+
*
94+
* @param hdr Pointer to the first list element.
95+
* @param size Size of the whole list.
96+
*/
3097
MsgHeaderIterator(nsapi_msghdr_t *hdr, nsapi_size_t size) :
3198
start(hdr),
3299
current(nullptr),
33100
size(size)
34101
{}
35102

36-
// Checks if the next address of the iterator is a valid list member.
103+
/** Checks if the next address of the iterator is a valid list member.
104+
*
105+
* @retval True if the next address is a valid member.
106+
* @retval False otherwise.
107+
*/
37108
bool has_next()
38109
{
39110
if (current == nullptr) {
@@ -55,8 +126,11 @@ struct MsgHeaderIterator {
55126
return true;
56127
}
57128

58-
// Returns pointer to the next member of the list.
59-
// If next member doesn't exist nullptr is returned.
129+
/** Returns next element of the list.
130+
*
131+
* @retval nullptr if the list doesn't contain next element.
132+
* @retval Pointer to the next element otherwise.
133+
*/
60134
nsapi_msghdr_t *next()
61135
{
62136
if (!has_next()) {

connectivity/netsocket/include/netsocket/nsapi_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define NSAPI_TYPES_H
2323

2424
#include <stdint.h>
25+
#include <stddef.h>
2526
#include "mbed_toolchain.h"
2627

2728
#ifdef __cplusplus
@@ -410,7 +411,7 @@ typedef struct nsapi_stagger_req {
410411

411412
/** nsapi_msghdr
412413
*/
413-
typedef struct MBED_ALIGN(double) nsapi_msghdr {
414+
typedef struct MBED_ALIGN(max_align_t) nsapi_msghdr {
414415
nsapi_size_t len; /* Data byte count, including header */
415416
int level; /* Originating protocol */
416417
int type; /* Protocol-specific type */

0 commit comments

Comments
 (0)