Lines Matching defs:p
29 * loop end condition (tot_len == p->len), NOT (next == NULL).
209 struct pbuf *p, *q, *r;
238 /* allocate head of pbuf chain into p */
239 p = (struct pbuf *)memp_malloc(MEMP_PBUF_POOL);
240 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc: allocated pbuf %p\n", (void *)p));
241 if (p == NULL) {
245 p->type = type;
246 p->next = NULL;
249 p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + (SIZEOF_STRUCT_PBUF + offset)));
250 LWIP_ASSERT("pbuf_alloc: pbuf p->payload properly aligned",
251 ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
253 p->tot_len = length;
255 p->len = LWIP_MIN(length, PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset));
256 LWIP_ASSERT("check p->payload + p->len does not overflow pbuf",
257 ((u8_t*)p->payload + p->len <=
258 (u8_t*)p + SIZEOF_STRUCT_PBUF + PBUF_POOL_BUFSIZE_ALIGNED));
262 p->ref = 1;
267 r = p;
269 rem_len = length - p->len;
276 pbuf_free(p);
293 LWIP_ASSERT("check p->payload + p->len does not overflow pbuf",
294 ((u8_t*)p->payload + p->len <=
295 (u8_t*)p + SIZEOF_STRUCT_PBUF + PBUF_POOL_BUFSIZE_ALIGNED));
308 p = (struct pbuf*)mem_malloc(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF + offset) + LWIP_MEM_ALIGN_SIZE(length));
309 if (p == NULL) {
313 p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset));
314 p->len = p->tot_len = length;
315 p->next = NULL;
316 p->type = type;
319 ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
326 p = (struct pbuf *)memp_malloc(MEMP_PBUF);
327 if (p == NULL) {
334 p->payload = NULL;
335 p->len = p->tot_len = length;
336 p->next = NULL;
337 p->type = type;
344 p->ref = 1;
346 p->flags = 0;
347 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p));
348 return p;
358 * @param p pointer to the custom pbuf to initialize (already allocated)
367 pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, struct pbuf_custom *p,
400 p->pbuf.next = NULL;
402 p->pbuf.payload = (u8_t *)payload_mem + LWIP_MEM_ALIGN_SIZE(offset);
404 p->pbuf.payload = NULL;
406 p->pbuf.flags = PBUF_FLAG_IS_CUSTOM;
407 p->pbuf.len = p->pbuf.tot_len = length;
408 p->pbuf.type = type;
409 p->pbuf.ref = 1;
410 return &p->pbuf;
417 * @param p pbuf to shrink.
430 pbuf_realloc(struct pbuf *p, u16_t new_len)
436 LWIP_ASSERT("pbuf_realloc: p != NULL", p != NULL);
437 LWIP_ASSERT("pbuf_realloc: sane p->type", p->type == PBUF_POOL ||
438 p->type == PBUF_ROM ||
439 p->type == PBUF_RAM ||
440 p->type == PBUF_REF);
443 if (new_len >= p->tot_len) {
448 /* the pbuf chain grows by (new_len - p->tot_len) bytes
450 grow = new_len - p->tot_len;
454 q = p;
498 * @param p pbuf to change the header size.
511 pbuf_header(struct pbuf *p, s16_t header_size_increment)
517 LWIP_ASSERT("p != NULL", p != NULL);
518 if ((header_size_increment == 0) || (p == NULL)) {
525 LWIP_ERROR("increment_magnitude <= p->len", (increment_magnitude <= p->len), return 1;);
532 LWIP_ASSERT("p->type == PBUF_RAM || p->type == PBUF_POOL",
533 p->type == PBUF_RAM || p->type == PBUF_POOL);
535 LWIP_ASSERT("p->payload - increment_magnitude >= p + SIZEOF_STRUCT_PBUF",
536 (u8_t *)p->payload - increment_magnitude >= (u8_t *)p + SIZEOF_STRUCT_PBUF);
540 type = p->type;
542 payload = p->payload;
547 p->payload = (u8_t *)p->payload - header_size_increment;
549 if ((u8_t *)p->payload < (u8_t *)p + SIZEOF_STRUCT_PBUF) {
551 ("pbuf_header: failed as %p < %p (not enough space for new header size)\n",
552 (void *)p->payload, (void *)(p + 1)));
554 p->payload = payload;
561 if ((header_size_increment < 0) && (increment_magnitude <= p->len)) {
563 p->payload = (u8_t *)p->payload - header_size_increment;
575 p->len += header_size_increment;
576 p->tot_len += header_size_increment;
578 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_header: old %p new %p (%"S16_F")\n",
579 (void *)payload, (void *)p->payload, header_size_increment));
596 * @param p The pbuf (chain) to be dereferenced.
618 pbuf_free(struct pbuf *p)
624 if (p == NULL) {
625 LWIP_ASSERT("p != NULL", p != NULL);
628 ("pbuf_free(p == NULL) was called.\n"));
631 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free(%p)\n", (void *)p));
636 p->type == PBUF_RAM || p->type == PBUF_ROM ||
637 p->type == PBUF_REF || p->type == PBUF_POOL);
642 while (p != NULL) {
650 LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0);
652 ref = --(p->ref);
657 q = p->next;
658 LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: deallocating %p\n", (void *)p));
659 type = p->type;
662 if ((p->flags & PBUF_FLAG_IS_CUSTOM) != 0) {
663 struct pbuf_custom *pc = (struct pbuf_custom*)p;
665 pc->custom_free_function(p);
671 memp_free(MEMP_PBUF_POOL, p);
674 memp_free(MEMP_PBUF, p);
677 mem_free(p);
682 p = q;
683 /* p->ref > 0, this pbuf is still referenced to */
686 LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: %p has ref %"U16_F", ending here.\n", (void *)p, ref));
688 p = NULL;
699 * @param p first pbuf of chain
704 pbuf_clen(struct pbuf *p)
709 while (p != NULL) {
711 p = p->next;
719 * @param p pbuf to increase reference counter of
723 pbuf_ref(struct pbuf *p)
727 if (p != NULL) {
729 ++(p->ref);
747 struct pbuf *p;
753 for (p = h; p->next != NULL; p = p->next) {
755 p->tot_len += t->tot_len;
757 /* { p is last pbuf of first h chain, p->next == NULL } */
758 LWIP_ASSERT("p->tot_len == p->len (of last pbuf in chain)", p->tot_len == p->len);
759 LWIP_ASSERT("p->next == NULL", p->next == NULL);
761 p->tot_len += t->tot_len;
762 /* chain last pbuf of head (p) with first of tail (t) */
763 p->next = t;
764 /* p->next now references t, but the caller will drop its reference to t,
791 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_chain: %p references %p\n", (void *)h, (void *)t));
797 * Makes p->tot_len field equal to p->len.
798 * @param p pbuf to dechain
803 pbuf_dechain(struct pbuf *p)
808 q = p->next;
811 /* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */
812 LWIP_ASSERT("p->tot_len == p->len + q->tot_len", q->tot_len == p->tot_len - p->len);
814 q->tot_len = p->tot_len - p->len;
816 p->next = NULL;
817 /* total length of pbuf p is its own length only */
818 p->tot_len = p->len;
819 /* q is no longer referenced by p, free it */
820 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_dechain: unreferencing %p\n", (void *)q));
824 ("pbuf_dechain: deallocated %p (as it is no longer referenced)\n", (void *)q));
828 /* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */
829 LWIP_ASSERT("p->tot_len == p->len", p->tot_len == p->len);
840 * @note You MUST explicitly use p = pbuf_take(p);
856 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy(%p, %p)\n",
920 struct pbuf *p;
935 for(p = buf; len != 0 && p != NULL; p = p->next) {
936 if ((offset != 0) && (offset >= p->len)) {
938 offset -= p->len;
941 buf_copy_len = p->len - offset;
945 MEMCPY(&((char*)dataptr)[left], &((char*)p->payload)[offset], buf_copy_len);
968 struct pbuf *p;
981 for(p = buf; total_copy_len != 0; p = p->next) {
982 LWIP_ASSERT("pbuf_take: invalid pbuf", p != NULL);
984 if (buf_copy_len > p->len) {
986 buf_copy_len = p->len;
989 MEMCPY(p->payload, &((char*)dataptr)[copied_total], buf_copy_len);
1000 * @remark: Either the source pbuf 'p' is freed by this function or the original
1001 * pbuf 'p' is returned, therefore the caller has to check the result!
1003 * @param p the source pbuf
1006 * @return a new, single pbuf (p->next is NULL)
1010 pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
1014 if (p->next == NULL) {
1015 return p;
1017 q = pbuf_alloc(layer, p->tot_len, PBUF_RAM);
1020 return p;
1022 err = pbuf_copy(q, p);
1024 pbuf_free(p);
1033 * @param p the pbuf to copy data into
1034 * @param start_offset offset of p->payload where to copy the data to
1042 pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
1048 LWIP_ASSERT("p != NULL", p != NULL);
1053 if ((start_offset >= p->len) || (start_offset + len > p->len)) {
1057 dst_ptr = ((char*)p->payload) + start_offset;
1070 * WARNING: returns zero for offset >= p->tot_len
1072 * @param p pbuf to parse
1073 * @param offset offset into p of the byte to return
1074 * @return byte at an offset into p OR ZERO IF 'offset' >= p->tot_len
1077 pbuf_get_at(struct pbuf* p, u16_t offset)
1080 struct pbuf* q = p;
1096 * @param p pbuf to compare
1097 * @param offset offset into p at wich to start comparing
1101 * (0xffff if p is too short, diffoffset+1 otherwise)
1104 pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n)
1107 struct pbuf* q = p;
1129 /** Find occurrence of mem (with length mem_len) in pbuf p, starting at offset
1132 * @param p pbuf to search, maximum length is 0xFFFE since 0xFFFF is used as
1136 * @param start_offset offset into p at which to start searching
1137 * @return 0xFFFF if substr was not found in p or the index where it was found
1140 pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset)
1143 u16_t max = p->tot_len - mem_len;
1144 if (p->tot_len >= mem_len + start_offset) {
1146 u16_t plus = pbuf_memcmp(p, i, mem, mem_len);
1157 /** Find occurrence of substr with length substr_len in pbuf p, start at offset
1162 * @param p pbuf to search, maximum length is 0xFFFE since 0xFFFF is used as
1164 * @param substr string to search for in p, maximum length is 0xFFFE
1165 * @return 0xFFFF if substr was not found in p or the index where it was found
1168 pbuf_strstr(struct pbuf* p, const char* substr)
1171 if ((substr == NULL) || (substr[0] == 0) || (p->tot_len == 0xFFFF)) {
1178 return pbuf_memfind(p, substr, (u16_t)substr_len, 0);