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

Function netbuf_alloc

components/net/lwip/lwip-1.4.1/src/api/netbuf.c:106–123  ·  view source on GitHub ↗

* 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

104 * NULL if no memory could be allocated
105 */
106void *
107netbuf_alloc(struct netbuf *buf, u16_t size)
108{
109 LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;);
110
111 /* Deallocate any previously allocated memory. */
112 if (buf->p != NULL) {
113 pbuf_free(buf->p);
114 }
115 buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
116 if (buf->p == NULL) {
117 return NULL;
118 }
119 LWIP_ASSERT("check that first pbuf can hold size",
120 (buf->p->len >= size));
121 buf->ptr = buf->p;
122 return buf->p->payload;
123}
124
125/**
126 * Free the packet buffer included in a netbuf

Callers 1

sockets.cFile · 0.70

Calls 2

pbuf_freeFunction · 0.50
pbuf_allocFunction · 0.50

Tested by

no test coverage detected