|
enum | pbuf_layer {
PBUF_TRANSPORT = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN
, PBUF_IP = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN
, PBUF_LINK = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN
, PBUF_RAW_TX = PBUF_LINK_ENCAPSULATION_HLEN
,
PBUF_RAW = 0
} |
|
enum | pbuf_type { PBUF_RAM = (PBUF_ALLOC_FLAG_DATA_CONTIGUOUS | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP)
, PBUF_ROM = PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF
, PBUF_REF = (PBUF_TYPE_FLAG_DATA_VOLATILE | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF)
, PBUF_POOL = (PBUF_ALLOC_FLAG_RX | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL)
} |
|
|
struct pbuf * | pbuf_alloc (pbuf_layer layer, u16_t length, pbuf_type type) |
|
struct pbuf * | pbuf_alloc_reference (void *payload, u16_t length, pbuf_type type) |
|
void | pbuf_realloc (struct pbuf *p, u16_t new_len) |
|
u8_t | pbuf_free (struct pbuf *p) |
|
void | pbuf_ref (struct pbuf *p) |
|
void | pbuf_cat (struct pbuf *h, struct pbuf *t) |
|
void | pbuf_chain (struct pbuf *h, struct pbuf *t) |
|
err_t | pbuf_copy (struct pbuf *p_to, const struct pbuf *p_from) |
|
err_t | pbuf_copy_partial_pbuf (struct pbuf *p_to, const struct pbuf *p_from, u16_t copy_len, u16_t offset) |
|
u16_t | pbuf_copy_partial (const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset) |
|
void * | pbuf_get_contiguous (const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset) |
|
struct pbuf * | pbuf_skip (struct pbuf *in, u16_t in_offset, u16_t *out_offset) |
|
err_t | pbuf_take (struct pbuf *buf, const void *dataptr, u16_t len) |
|
err_t | pbuf_take_at (struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset) |
|
struct pbuf * | pbuf_coalesce (struct pbuf *p, pbuf_layer layer) |
|
struct pbuf * | pbuf_clone (pbuf_layer layer, pbuf_type type, struct pbuf *p) |
|
u8_t | pbuf_get_at (const struct pbuf *p, u16_t offset) |
|
int | pbuf_try_get_at (const struct pbuf *p, u16_t offset) |
|
void | pbuf_put_at (struct pbuf *p, u16_t offset, u8_t data) |
|
u16_t | pbuf_memcmp (const struct pbuf *p, u16_t offset, const void *s2, u16_t n) |
|
u16_t | pbuf_memfind (const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset) |
|
Packets are built from the pbuf data structure. It supports dynamic memory allocation for packet contents or can reference externally managed packet contents both in RAM and ROM. Quick allocation for incoming packets is provided through pools with fixed sized pbufs.
A packet may span over multiple pbufs, chained as a singly linked list. This is called a "pbuf chain".
Multiple packets may be queued, also using this singly linked list. This is called a "packet queue".
So, a packet queue consists of one or more pbuf chains, each of which consist of one or more pbufs. CURRENTLY, PACKET QUEUES ARE NOT SUPPORTED!!! Use helper structs to queue multiple packets.
The differences between a pbuf chain and a packet queue are very precise but subtle.
The last pbuf of a packet has a ->tot_len field that equals the ->len field. It can be found by traversing the list. If the last pbuf of a packet has a ->next field other than NULL, more packets are on the queue.
Therefore, looping through a pbuf of a single packet, has an loop end condition (tot_len == p->len), NOT (next == NULL).
Example of custom pbuf usage: Zero-copy RX
◆ PBUF_NEEDS_COPY
PBUF_NEEDS_COPY(p): return a boolean value indicating whether the given pbuf needs to be copied in order to be kept around beyond the current call stack without risking being corrupted. The default setting provides safety: it will make a copy iof any pbuf chain that does not consist entirely of PBUF_ROM type pbufs. For setups with zero-copy support, it may be redefined to evaluate to true in all cases, for example. However, doing so also has an effect on the application side: any buffers that are not copied must also not be reused by the application after passing them to lwIP. For example, when setting PBUF_NEEDS_COPY to (0), after using udp_send() with a PBUF_RAM pbuf, the application must free the pbuf immediately, rather than reusing it for other purposes. For more background information on this, see tasks #6735 and #7896, and bugs #11400 and #49914.
Definition at line 72 of file pbuf.h.
◆ pbuf_layer
Enumeration of pbuf layers
Enumerator |
---|
PBUF_TRANSPORT | Includes spare room for transport layer header, e.g. UDP header. Use this if you intend to pass the pbuf to functions like udp_send().
|
PBUF_IP | Includes spare room for IP header. Use this if you intend to pass the pbuf to functions like raw_send().
|
PBUF_LINK | Includes spare room for link layer header (ethernet header). Use this if you intend to pass the pbuf to functions like ethernet_output(). - See also
- PBUF_LINK_HLEN
|
PBUF_RAW_TX | Includes spare room for additional encapsulation header before ethernet headers (e.g. 802.11). Use this if you intend to pass the pbuf to functions like netif->linkoutput(). - See also
- PBUF_LINK_ENCAPSULATION_HLEN
|
PBUF_RAW | Use this for input packets in a netif driver when calling netif->input() in the most common case - ethernet-layer netif driver.
|
Definition at line 89 of file pbuf.h.
89 {
#define PBUF_LINK_ENCAPSULATION_HLEN
#define PBUF_TRANSPORT_HLEN
◆ pbuf_type
Enumeration of pbuf types
Enumerator |
---|
PBUF_RAM | pbuf data is stored in RAM, used for TX mostly, struct pbuf and its payload are allocated in one piece of contiguous memory (so the first payload byte can be calculated from struct pbuf). pbuf_alloc() allocates PBUF_RAM pbufs as unchained pbufs (although that might change in future versions). This should be used for all OUTGOING packets (TX).
|
PBUF_ROM | pbuf data is stored in ROM, i.e. struct pbuf and its payload are located in totally different memory areas. Since it points to ROM, payload does not have to be copied when queued for transmission.
|
PBUF_REF | pbuf comes from the pbuf pool. Much like PBUF_ROM but payload might change so it has to be duplicated when queued before transmitting, depending on who has a 'ref' to it.
|
PBUF_POOL | pbuf payload refers to RAM. This one comes from a pool and should be used for RX. Payload can be chained (scatter-gather RX) but like PBUF_RAM, struct pbuf and its payload are allocated in one piece of contiguous memory (so the first payload byte can be calculated from struct pbuf). Don't use this for TX, if the pool becomes empty e.g. because of TCP queuing, you are unable to receive TCP acks!
|
Definition at line 145 of file pbuf.h.
145 {
#define PBUF_TYPE_FLAG_DATA_VOLATILE
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF
#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS
#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS
#define PBUF_ALLOC_FLAG_RX
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP
◆ pbuf_alloc()
Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type).
The actual memory allocated for the pbuf is determined by the layer at which the pbuf is allocated and the requested size (from the size parameter).
- Parameters
-
layer | header size |
length | size of the pbuf's payload |
type | this parameter decides how and where the pbuf should be allocated as follows: |
- PBUF_RAM: buffer memory for pbuf is allocated as one large chunk. This includes protocol headers as well.
- PBUF_ROM: no buffer memory is allocated for the pbuf, even for protocol headers. Additional headers must be prepended by allocating another pbuf and chain in to the front of the ROM pbuf. It is assumed that the memory used is really similar to ROM in that it is immutable and will not be changed. Memory which is dynamic should generally not be attached to PBUF_ROM pbufs. Use PBUF_REF instead.
- PBUF_REF: no buffer memory is allocated for the pbuf, even for protocol headers. It is assumed that the pbuf is only being used in a single thread. If the pbuf gets queued, then pbuf_take should be called to copy the buffer.
- PBUF_POOL: the pbuf is allocated as a pbuf chain, with pbufs from the pbuf pool that is allocated during pbuf_init().
- Returns
- the allocated pbuf. If multiple pbufs where allocated, this is the first pbuf of a pbuf chain.
Definition at line 224 of file pbuf.c.
225{
229
234 break;
241 do {
246
249 }
250
252 }
255 rem_len, qlen,
type, 0);
256 LWIP_ASSERT(
"pbuf_alloc: pbuf q->payload properly aligned",
258 LWIP_ASSERT(
"PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT",
261
263 } else {
264
266 }
268 rem_len = (
u16_t)(rem_len - qlen);
270 } while (rem_len > 0);
271 break;
272 }
276
277
281 }
282
283
287 }
290 LWIP_ASSERT(
"pbuf_alloc: pbuf->payload properly aligned",
292 break;
293 }
294 default:
297 }
300}
void * mem_malloc(mem_size_t size_in)
#define LWIP_DEBUGF(debug, message)
#define LWIP_ASSERT(message, assertion)
GLuint GLuint GLsizei GLenum type
GLdouble GLdouble GLdouble GLdouble q
GLuint GLsizei GLsizei * length
GLenum GLuint GLint GLint layer
#define LWIP_MEM_ALIGN(addr)
#define LWIP_MEM_ALIGN_SIZE(size)
struct pbuf * pbuf_alloc_reference(void *payload, u16_t length, pbuf_type type)
u8_t pbuf_free(struct pbuf *p)
void * memp_malloc(memp_t type)
#define PBUF_POOL_BUFSIZE_ALIGNED
static void pbuf_init_alloced_pbuf(struct pbuf *p, void *payload, u16_t tot_len, u16_t len, pbuf_type type, u8_t flags)
#define SIZEOF_STRUCT_PBUF
#define PBUF_POOL_IS_EMPTY()
Referenced by create_arp_response(), create_ip4_input_fragment(), eth_mac_irq(), input_pkt(), LibIPInsertPacket(), pbuf_clone(), send_pkt(), slipif_rxbyte(), START_TEST(), tcp_create_segment_wnd(), test_tcp_netif_output(), and test_udp_create_test_packet().
◆ pbuf_alloc_reference()
Allocates a pbuf for referenced data. Referenced data can be volatile (PBUF_REF) or long-lived (PBUF_ROM).
The actual memory allocated for the pbuf is determined by the layer at which the pbuf is allocated and the requested size (from the size parameter).
- Parameters
-
payload | referenced payload |
length | size of the pbuf's payload |
type | this parameter decides how and where the pbuf should be allocated as follows: |
- PBUF_ROM: It is assumed that the memory used is really similar to ROM in that it is immutable and will not be changed. Memory which is dynamic should generally not be attached to PBUF_ROM pbufs. Use PBUF_REF instead.
- PBUF_REF: It is assumed that the pbuf is only being used in a single thread. If the pbuf gets queued, then pbuf_take should be called to copy the buffer.
- Returns
- the allocated pbuf.
Definition at line 327 of file pbuf.c.
328{
331
335 ("pbuf_alloc_reference: Could not allocate MEMP_PBUF for PBUF_%s.\n",
338 }
341}
#define LWIP_DBG_LEVEL_SERIOUS
Referenced by pbuf_alloc().
◆ pbuf_cat()
Concatenate two pbufs (each may be a pbuf chain) and take over the caller's reference of the tail pbuf.
- Note
- The caller MAY NOT reference the tail pbuf afterwards. Use pbuf_chain() for that purpose.
This function explicitly does not check for tot_len overflow to prevent failing to queue too long pbufs. This can produce invalid pbufs, so handle with care!
- See also
- pbuf_chain()
Definition at line 855 of file pbuf.c.
856{
858
859 LWIP_ERROR(
"(h != NULL) && (t != NULL) (programmer violates API)",
861
862
864
865 p->tot_len = (
u16_t)(
p->tot_len +
t->tot_len);
866 }
867
868 LWIP_ASSERT(
"p->tot_len == p->len (of last pbuf in chain)",
p->tot_len ==
p->len);
870
871 p->tot_len = (
u16_t)(
p->tot_len +
t->tot_len);
872
874
875
876
877}
#define LWIP_ERROR(message, expression, handler)
GLfloat GLfloat GLfloat GLfloat h
Referenced by pbuf_chain(), slipif_rxbyte(), START_TEST(), and test_tcp_netif_output().
◆ pbuf_chain()
Chain two pbufs (or pbuf chains) together.
The caller MUST call pbuf_free(t) once it has stopped using it. Use pbuf_cat() instead if you no longer use t.
- Parameters
-
h | head pbuf (chain) |
t | tail pbuf (chain) |
- Note
- The pbufs MUST belong to the same packet.
-
MAY NOT be called on a packet queue.
The ->tot_len fields of all pbufs of the head chain are adjusted. The ->next field of the last pbuf of the head chain is adjusted. The ->ref field of the first pbuf of the tail chain is adjusted.
Definition at line 897 of file pbuf.c.
898{
900
903}
void pbuf_ref(struct pbuf *p)
void pbuf_cat(struct pbuf *h, struct pbuf *t)
◆ pbuf_clone()
Allocates a new pbuf of same length (via pbuf_alloc()) and copies the source pbuf into this new pbuf (using pbuf_copy()).
- Parameters
-
layer | pbuf_layer of the new pbuf |
type | this parameter decides how and where the pbuf should be allocated ( |
- See also
- pbuf_alloc())
- Parameters
-
- Returns
- a new pbuf or NULL if allocation fails
Definition at line 1337 of file pbuf.c.
1338{
1344 }
1349}
#define LWIP_UNUSED_ARG(x)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
Referenced by pbuf_coalesce().
◆ pbuf_coalesce()
Creates a single pbuf out of a queue of pbufs.
- Parameters
-
p | the source pbuf |
layer | pbuf_layer of the new pbuf |
- Returns
- a new, single pbuf (p->next is NULL) or the old pbuf if allocation fails
Definition at line 1309 of file pbuf.c.
1310{
1312 if (
p->next ==
NULL) {
1314 }
1317
1319 }
1322}
struct pbuf * pbuf_clone(pbuf_layer layer, pbuf_type type, struct pbuf *p)
◆ pbuf_copy()
Copy the contents of one packet buffer into another.
- Note
- Only one packet is copied, no packet queue!
- Parameters
-
p_to | pbuf destination of the copy |
p_from | pbuf source of the copy |
- Returns
- ERR_OK if pbuf was copied ERR_ARG if one of the pbufs is NULL or p_to is not big enough to hold p_from ERR_VAL if any of the pbufs are part of a queue
Definition at line 959 of file pbuf.c.
960{
962 (const void *)p_to, (const void *)p_from));
963
966}
err_t pbuf_copy_partial_pbuf(struct pbuf *p_to, const struct pbuf *p_from, u16_t copy_len, u16_t offset)
Referenced by pbuf_clone(), START_TEST(), and test_tcp_netif_output().
◆ pbuf_copy_partial()
Copy (part of) the contents of a packet buffer to an application supplied buffer.
- Parameters
-
buf | the pbuf from which to copy data |
dataptr | the application supplied buffer |
len | length of data to copy (dataptr must be big enough). No more than buf->tot_len will be copied, irrespective of len |
offset | offset into the packet buffer from where to begin copying len bytes |
- Returns
- the number of bytes copied, or 0 on failure
Definition at line 1058 of file pbuf.c.
1059{
1060 const struct pbuf *
p;
1063 u16_t copied_total = 0;
1064
1067
1068
1071
1073 } else {
1074
1076 if (buf_copy_len >
len) {
1078 }
1079
1081 copied_total = (
u16_t)(copied_total + buf_copy_len);
1085 }
1086 }
1087 return copied_total;
1088}
GLenum GLuint GLenum GLsizei const GLchar * buf
int const JOCTET * dataptr
#define MEMCPY(DST, SRC, BYTES)
Referenced by get_tcp_flags_from_packet(), LibTCPGetDataFromConnectionQueue(), netif_output(), pbuf_get_contiguous(), START_TEST(), test_netif_linkoutput(), and test_tcp_tx_full_window_lost().
◆ pbuf_copy_partial_pbuf()
Copy part or all of one packet buffer into another, to a specified offset.
- Note
- Only data in one packet is copied, no packet queue!
-
Argument order is shared with pbuf_copy, but different than pbuf_copy_partial.
- Parameters
-
p_to | pbuf destination of the copy |
p_from | pbuf source of the copy |
copy_len | number of bytes to copy |
offset | offset in destination pbuf where to copy to |
- Returns
- ERR_OK if copy_len bytes were copied ERR_ARG if one of the pbufs is NULL or p_from is shorter than copy_len or p_to is not big enough to hold copy_len at offset ERR_VAL if any of the pbufs are part of a queue
Definition at line 986 of file pbuf.c.
987{
988 size_t offset_to =
offset, offset_from = 0,
len;
989
991 (
const void *)p_to, (
const void *)p_from, copy_len,
offset));
992
993
994 LWIP_ERROR(
"pbuf_copy_partial_pbuf: copy_len bigger than source", ((p_from !=
NULL) &&
996
997 LWIP_ERROR(
"pbuf_copy_partial_pbuf: target not big enough", ((p_to !=
NULL) &&
999
1000
1001 do {
1002
1003 if ((p_to->len - offset_to) >= (p_from->
len - offset_from)) {
1004
1005 len = p_from->
len - offset_from;
1006 } else {
1007
1008 len = p_to->len - offset_to;
1009 }
1014 copy_len = (
u16_t)(copy_len -
len);
1016 LWIP_ASSERT(
"offset_from <= p_from->len", offset_from <= p_from->
len);
1017 if (offset_from >= p_from->
len) {
1018
1019 offset_from = 0;
1020 p_from = p_from->
next;
1022 }
1023 if (offset_to == p_to->len) {
1024
1025 offset_to = 0;
1026 p_to = p_to->next;
1028 }
1029
1031
1032 LWIP_ERROR(
"pbuf_copy_partial_pbuf() does not allow packet queues!",
1034 }
1035 if ((p_to !=
NULL) && (p_to->len == p_to->tot_len)) {
1036
1037 LWIP_ERROR(
"pbuf_copy_partial_pbuf() does not allow packet queues!",
1039 }
1040 } while (copy_len);
1043}
Referenced by pbuf_copy(), and START_TEST().
◆ pbuf_free()
Dereference a pbuf chain or queue and deallocate any no-longer-used pbufs at the head of this chain or queue.
Decrements the pbuf reference count. If it reaches zero, the pbuf is deallocated.
For a pbuf chain, this is repeated for each pbuf in the chain, up to the first pbuf which has a non-zero reference count after decrementing. So, when all reference counts are one, the whole chain is free'd.
- Parameters
-
p | The pbuf (chain) to be dereferenced. |
- Returns
- the number of pbufs that were de-allocated from the head of the chain.
- Note
- the reference counter of a pbuf equals the number of pointers that refer to the pbuf (or into the pbuf).
Definition at line 727 of file pbuf.c.
728{
732
735
737 ("pbuf_free(p == NULL) was called.\n"));
738 return 0;
739 }
741
743
745
746
750
751
752
754
756
759
761
765#if LWIP_SUPPORT_CUSTOM_PBUF
766
768 struct pbuf_custom *pc = (
struct pbuf_custom *)
p;
769 LWIP_ASSERT(
"pc->custom_free_function != NULL", pc->custom_free_function !=
NULL);
770 pc->custom_free_function(
p);
771 } else
772#endif
773 {
774
777
780
783 } else {
784
786 }
787 }
789
791
792
793 } else {
795
797 }
798 }
800
802}
#define mem_free(ptr, bsize)
#define SYS_ARCH_UNPROTECT(lev)
#define SYS_ARCH_PROTECT(lev)
#define SYS_ARCH_DECL_PROTECT(lev)
GLuint GLuint GLsizei count
void memp_free(memp_t type, void *mem)
#define pbuf_get_allocsrc(p)
#define PBUF_FLAG_IS_CUSTOM
Referenced by create_ip4_input_fragment(), eth_mac_irq(), eth_rx_irq(), input_pkt(), InternalRecvEventHandler(), ip4_teardown(), LibTCPEmptyQueue(), main(), pbuf_alloc(), pbuf_coalesce(), pbuf_dechain(), pbuf_free_header(), pbuf_free_int(), pbuf_realloc(), slipif_rxbyte_input(), START_TEST(), tcpip_thread_handle_msg(), test_recv(), test_rst_generation_with_incoming_packet(), test_tcp_counters_recv(), test_tcp_recv_expect1byte(), and test_tcp_tx_full_window_lost().
◆ pbuf_get_at()
Get one byte from the specified position in a pbuf WARNING: returns zero for offset >= p->tot_len
- Parameters
-
p | pbuf to parse |
offset | offset into p of the byte to return |
- Returns
- byte at an offset into p OR ZERO IF 'offset' >= p->tot_len
Definition at line 1402 of file pbuf.c.
1403{
1407 }
1408 return 0;
1409}
int pbuf_try_get_at(const struct pbuf *p, u16_t offset)
Referenced by pbuf_memcmp(), and START_TEST().
◆ pbuf_get_contiguous()
Get part of a pbuf's payload as contiguous memory. The returned memory is either a pointer into the pbuf's payload or, if split over multiple pbufs, a copy into the user-supplied buffer.
- Parameters
-
p | the pbuf from which to copy data |
buffer | the application supplied buffer |
bufsize | size of the application supplied buffer |
len | length of data to copy (dataptr must be big enough). No more than buf->tot_len will be copied, irrespective of len |
offset | offset into the packet buffer from where to begin copying len bytes |
- Returns
- the number of bytes copied, or 0 on failure
Definition at line 1105 of file pbuf.c.
1106{
1107 const struct pbuf *
q;
1109
1113
1116 if (
q->len >= (out_offset +
len)) {
1117
1118 return (
u8_t *)
q->payload + out_offset;
1119 }
1120
1122
1124 }
1126 }
1127
1129}
GLenum GLuint GLsizei bufsize
u16_t pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
static const struct pbuf * pbuf_skip_const(const struct pbuf *in, u16_t in_offset, u16_t *out_offset)
◆ pbuf_memcmp()
Compare pbuf contents at specified offset with memory s2, both of length n
- Parameters
-
p | pbuf to compare |
offset | offset into p at which to start comparing |
s2 | buffer to compare |
n | length of buffer to compare |
- Returns
- zero if equal, nonzero otherwise (0xffff if p is too short, diffoffset+1 otherwise)
Definition at line 1465 of file pbuf.c.
1466{
1468 const struct pbuf *
q =
p;
1470
1471
1473 return 0xffff;
1474 }
1475
1476
1480 }
1481
1482
1483 for (
i = 0;
i <
n;
i++) {
1484
1489 }
1490 }
1491 return 0;
1492}
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
u8_t pbuf_get_at(const struct pbuf *p, u16_t offset)
Referenced by pbuf_memfind().
◆ pbuf_memfind()
Find occurrence of mem (with length mem_len) in pbuf p, starting at offset start_offset.
- Parameters
-
p | pbuf to search, maximum length is 0xFFFE since 0xFFFF is used as return value 'not found' |
mem | search for the contents of this buffer |
mem_len | length of 'mem' |
start_offset | offset into p at which to start searching |
- Returns
- 0xFFFF if substr was not found in p or the index where it was found
Definition at line 1507 of file pbuf.c.
1508{
1510 u16_t max_cmp_start = (
u16_t)(
p->tot_len - mem_len);
1511 if (
p->tot_len >= mem_len + start_offset) {
1512 for (
i = start_offset;
i <= max_cmp_start;
i++) {
1516 }
1517 }
1518 }
1519 return 0xFFFF;
1520}
u16_t pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
Referenced by pbuf_strstr().
◆ pbuf_put_at()
Put one byte to the specified position in a pbuf WARNING: silently ignores offset >= p->tot_len
- Parameters
-
p | pbuf to fill |
offset | offset into p of the byte to write |
data | byte to write at an offset into p |
Definition at line 1442 of file pbuf.c.
1443{
1446
1447
1448 if ((
q !=
NULL) && (
q->len > q_idx)) {
1450 }
1451}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
struct pbuf * pbuf_skip(struct pbuf *in, u16_t in_offset, u16_t *out_offset)
Referenced by START_TEST().
◆ pbuf_realloc()
Shrink a pbuf chain to a desired length.
- Parameters
-
p | pbuf to shrink. |
new_len | desired new length of pbuf chain |
Depending on the desired length, the first few pbufs in a chain might be skipped and left unchanged. The new last pbuf in the chain will be resized, and any remaining pbufs will be freed.
- Note
- If the pbuf is ROM/REF, only the ->tot_len and ->len fields are adjusted.
-
May not be called on a packet queue.
-
Despite its name, pbuf_realloc cannot grow the size of a pbuf (chain).
Definition at line 402 of file pbuf.c.
403{
407
409
410
411 if (new_len >=
p->tot_len) {
412
413 return;
414 }
415
416
417
418 shrink = (
u16_t)(
p->tot_len - new_len);
419
420
421 rem_len = new_len;
423
424 while (rem_len >
q->len) {
425
426 rem_len = (
u16_t)(rem_len -
q->len);
427
428 q->tot_len = (
u16_t)(
q->tot_len - shrink);
429
432 }
433
434
435
436
437
441#endif
442 ) {
443
446
449 }
450
453
454
455 if (
q->next !=
NULL) {
456
458 }
459
461
462}
void * mem_trim(void *rmem, mem_size_t new_size)
GLdouble GLdouble GLdouble r
#define LWIP_SUPPORT_CUSTOM_PBUF
#define pbuf_match_allocsrc(p, type)
Referenced by slipif_rxbyte().
◆ pbuf_ref()
Increment the reference count of the pbuf.
- Parameters
-
p | pbuf to increase reference counter of |
Definition at line 831 of file pbuf.c.
832{
833
837 }
838}
#define SYS_ARCH_SET(var, val)
Referenced by pbuf_chain().
◆ pbuf_skip()
Skip a number of bytes at the start of a pbuf
- Parameters
-
in | input pbuf |
in_offset | offset to skip |
out_offset | resulting offset in the returned pbuf |
- Returns
- the pbuf in the queue where the offset is or NULL when the offset is too high
Definition at line 1209 of file pbuf.c.
1210{
1213}
#define LWIP_CONST_CAST(target_type, val)
Referenced by pbuf_put_at(), and pbuf_take_at().
◆ pbuf_take()
Copy application supplied data into a pbuf. This function can only be used to copy the equivalent of buf->tot_len data.
- Parameters
-
buf | pbuf to fill with data |
dataptr | application supplied data buffer |
len | length of the application supplied data buffer |
- Returns
- ERR_OK if successful, ERR_MEM if the pbuf is not big enough
Definition at line 1227 of file pbuf.c.
1228{
1230 size_t buf_copy_len;
1231 size_t total_copy_len =
len;
1232 size_t copied_total = 0;
1233
1237
1240 }
1241
1242
1243 for (
p =
buf; total_copy_len != 0;
p =
p->next) {
1245 buf_copy_len = total_copy_len;
1246 if (buf_copy_len >
p->len) {
1247
1248 buf_copy_len =
p->len;
1249 }
1250
1251 MEMCPY(
p->payload, &((
const char *)
dataptr)[copied_total], buf_copy_len);
1252 total_copy_len -= buf_copy_len;
1253 copied_total += buf_copy_len;
1254 }
1255 LWIP_ASSERT(
"did not copy all data", total_copy_len == 0 && copied_total ==
len);
1257}
Referenced by eth_mac_irq(), pbuf_take_at(), START_TEST(), tcp_create_segment_wnd(), and test_udp_create_test_packet().
◆ pbuf_take_at()
Same as pbuf_take() but puts data at an offset
- Parameters
-
buf | pbuf to fill with data |
dataptr | application supplied data buffer |
len | length of the application supplied data buffer |
offset | offset in pbuf where to copy dataptr to |
- Returns
- ERR_OK if successful, ERR_MEM if the pbuf is not big enough
Definition at line 1271 of file pbuf.c.
1272{
1273 u16_t target_offset;
1275
1276
1277 if ((
q !=
NULL) && (
q->tot_len >= target_offset +
len)) {
1280
1281 u16_t first_copy_len;
1285 remaining_len = (
u16_t)(remaining_len - first_copy_len);
1286 src_ptr += first_copy_len;
1287 if (remaining_len > 0) {
1288 return pbuf_take(
q->next, src_ptr, remaining_len);
1289 }
1291 }
1293}
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
Referenced by START_TEST().
◆ pbuf_try_get_at()
Get one byte from the specified position in a pbuf
- Parameters
-
p | pbuf to parse |
offset | offset into p of the byte to return |
- Returns
- byte at an offset into p [0..0xFF] OR negative if 'offset' >= p->tot_len
Definition at line 1420 of file pbuf.c.
1421{
1424
1425
1426 if ((
q !=
NULL) && (
q->len > q_idx)) {
1427 return ((
u8_t *)
q->payload)[q_idx];
1428 }
1429 return -1;
1430}
Referenced by pbuf_get_at().