MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / netbuf_alloc

Function netbuf_alloc

components/net/lwip/lwip-2.1.2/src/api/netbuf.c:101–118  ·  view source on GitHub ↗

* @ingroup netbuf * Allocate memory for a packet buffer for a given netbuf. * * @param buf the netbuf for which to allocate a packet buffer * @param size the size of the packet buffer to allocate * @return pointer to the allocated memory * NULL if no memory could be allocated */

Source from the content-addressed store, hash-verified

99 * NULL if no memory could be allocated
100 */
101void *
102netbuf_alloc(struct netbuf *buf, u16_t size)
103{
104 LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;);
105
106 /* Deallocate any previously allocated memory. */
107 if (buf->p != NULL) {
108 pbuf_free(buf->p);
109 }
110 buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
111 if (buf->p == NULL) {
112 return NULL;
113 }
114 LWIP_ASSERT("check that first pbuf can hold size",
115 (buf->p->len >= size));
116 buf->ptr = buf->p;
117 return buf->p->payload;
118}
119
120/**
121 * @ingroup netbuf

Callers 2

lwip_sendmsgFunction · 0.70
lwip_sendtoFunction · 0.70

Calls 2

pbuf_freeFunction · 0.50
pbuf_allocFunction · 0.50

Tested by

no test coverage detected