76 #if LWIP_CHECKSUM_ON_COPY
82 #define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
85 #define PBUF_POOL_BUFSIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE)
87 #if !LWIP_TCP || !TCP_QUEUE_OOSEQ || NO_SYS
88 #define PBUF_POOL_IS_EMPTY()
91 #ifndef PBUF_POOL_FREE_OOSEQ
92 #define PBUF_POOL_FREE_OOSEQ 1
95 #if PBUF_POOL_FREE_OOSEQ
97 #define PBUF_POOL_IS_EMPTY() pbuf_pool_is_empty()
98 static u8_t pbuf_free_ooseq_queued;
108 pbuf_free_ooseq(
void* arg)
115 pbuf_free_ooseq_queued = 0;
118 for (pcb = tcp_active_pcbs;
NULL != pcb; pcb = pcb->next) {
119 if (
NULL != pcb->ooseq) {
122 tcp_segs_free(pcb->ooseq);
131 pbuf_pool_is_empty(
void)
137 queued = pbuf_free_ooseq_queued;
138 pbuf_free_ooseq_queued = 1;
145 pbuf_free_ooseq_queued = 0;
187 struct pbuf *p, *q, *r;
228 LWIP_ASSERT(
"pbuf_alloc: pbuf p->payload properly aligned",
234 LWIP_ASSERT(
"check p->payload + p->len does not overflow pbuf",
237 LWIP_ASSERT(
"PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT",
247 rem_len = length - p->
len;
249 while (rem_len > 0) {
264 LWIP_ASSERT(
"rem_len < max_u16_t", rem_len < 0xffff);
269 LWIP_ASSERT(
"pbuf_alloc: pbuf q->payload properly aligned",
271 LWIP_ASSERT(
"check p->payload + p->len does not overflow pbuf",
296 LWIP_ASSERT(
"pbuf_alloc: pbuf->payload properly aligned",
307 (
"pbuf_alloc: Could not allocate MEMP_PBUF for PBUF_%s.\n",
308 (type ==
PBUF_ROM) ?
"ROM" :
"REF"));
329 #if LWIP_SUPPORT_CUSTOM_PBUF
345 void *payload_mem,
u16_t payload_mem_len)
368 LWIP_ASSERT(
"pbuf_alloced_custom: bad pbuf layer", 0);
378 if (payload_mem !=
NULL) {
381 p->pbuf.payload =
NULL;
384 p->pbuf.len = p->pbuf.tot_len = length;
433 while (rem_len > q->
len) {
492 u16_t increment_magnitude;
495 if ((header_size_increment == 0) || (p ==
NULL)) {
499 if (header_size_increment < 0){
500 increment_magnitude = -header_size_increment;
502 LWIP_ERROR(
"increment_magnitude <= p->len", (increment_magnitude <= p->
len),
return 1;);
504 increment_magnitude = header_size_increment;
509 LWIP_ASSERT(
"p->type == PBUF_RAM || p->type == PBUF_POOL",
512 LWIP_ASSERT(
"p->payload - increment_magnitude >= p + SIZEOF_STRUCT_PBUF",
528 (
"pbuf_header: failed as %p < %p (not enough space for new header size)\n",
529 (
void *)p->
payload, (
void *)(p + 1)));
538 if ((header_size_increment < 0) && (increment_magnitude <= p->
len)) {
552 p->
len += header_size_increment;
553 p->
tot_len += header_size_increment;
556 (
void *)payload, (
void *)p->
payload, header_size_increment));
605 (
"pbuf_free(p == NULL) was called.\n"));
637 #if LWIP_SUPPORT_CUSTOM_PBUF
640 struct pbuf_custom *pc = (
struct pbuf_custom*)p;
641 LWIP_ASSERT(
"pc->custom_free_function != NULL", pc->custom_free_function !=
NULL);
642 pc->custom_free_function(p);
726 LWIP_ERROR(
"(h != NULL) && (t != NULL) (programmer violates API)",
727 ((h !=
NULL) && (t !=
NULL)),
return;);
801 (
"pbuf_dechain: deallocated %p (as it is no longer referenced)\n", (
void *)q));
807 return ((tail_gone > 0) ?
NULL : q);
831 u16_t offset_to=0, offset_from=0,
len;
834 (
void*)p_to, (
void*)p_from));
837 LWIP_ERROR(
"pbuf_copy: target not big enough to hold source", ((p_to !=
NULL) &&
845 if ((p_to->
len - offset_to) >= (p_from->
len - offset_from)) {
847 len = p_from->
len - offset_from;
850 len = p_to->
len - offset_to;
856 if (offset_to == p_to->
len) {
861 LWIP_ASSERT(
"offset_from <= p_from->len", offset_from <= p_from->len);
862 if (offset_from >= p_from->
len) {
865 p_from = p_from->
next;
870 LWIP_ERROR(
"pbuf_copy() does not allow packet queues!\n",
875 LWIP_ERROR(
"pbuf_copy() does not allow packet queues!\n",
900 u16_t copied_total = 0;
902 LWIP_ERROR(
"pbuf_copy_partial: invalid buf", (buf !=
NULL),
return 0;);
903 LWIP_ERROR(
"pbuf_copy_partial: invalid dataptr", (dataptr !=
NULL),
return 0;);
907 if((buf ==
NULL) || (dataptr ==
NULL)) {
912 for(p = buf; len != 0 && p !=
NULL; p = p->
next) {
913 if ((offset != 0) && (offset >= p->
len)) {
918 buf_copy_len = p->
len - offset;
919 if (buf_copy_len > len)
922 MEMCPY(&((
char*)dataptr)[left], &((
char*)p->
payload)[offset], buf_copy_len);
923 copied_total += buf_copy_len;
924 left += buf_copy_len;
948 u16_t copied_total = 0;
951 LWIP_ERROR(
"pbuf_take: invalid dataptr", (dataptr !=
NULL),
return 0;);
958 for(p = buf; total_copy_len != 0; p = p->
next) {
960 buf_copy_len = total_copy_len;
961 if (buf_copy_len > p->
len) {
963 buf_copy_len = p->
len;
966 MEMCPY(p->
payload, &((
char*)dataptr)[copied_total], buf_copy_len);
967 total_copy_len -= buf_copy_len;
968 copied_total += buf_copy_len;
970 LWIP_ASSERT(
"did not copy all data", total_copy_len == 0 && copied_total == len);
1005 #if LWIP_CHECKSUM_ON_COPY
1019 pbuf_fill_chksum(
struct pbuf *p,
u16_t start_offset,
const void *dataptr,
1030 if ((start_offset >= p->
len) || (start_offset + len > p->
len)) {
1034 dst_ptr = ((
char*)p->
payload) + start_offset;
1035 copy_chksum = LWIP_CHKSUM_COPY(dst_ptr, dataptr, len);
1036 if ((start_offset & 1) != 0) {
1056 u16_t copy_from = offset;
1060 while ((q !=
NULL) && (q->
len <= copy_from)) {
1061 copy_from -= q->
len;
1065 if ((q !=
NULL) && (q->
len > copy_from)) {
1083 u16_t start = offset;
1087 while ((q !=
NULL) && (q->
len <= start)) {
1092 if ((q !=
NULL) && (q->
len > start)) {
1094 for(i = 0; i < n; i++) {
1121 if (p->
tot_len >= mem_len + start_offset) {
1122 for(i = start_offset; i <= max; ) {
1148 if ((substr ==
NULL) || (substr[0] == 0) || (p->
tot_len == 0xFFFF)) {
1151 substr_len = strlen(substr);
1152 if (substr_len >= 0xFFFF) {