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

Function netbuf_ref

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

* @ingroup netbuf * Let a netbuf reference existing (non-volatile) data. * * @param buf netbuf which should reference the data * @param dataptr pointer to the data to reference * @param size size of the data * @return ERR_OK if data is referenced * ERR_MEM if data couldn't be referenced due to lack of memory */

Source from the content-addressed store, hash-verified

148 * ERR_MEM if data couldn't be referenced due to lack of memory
149 */
150err_t
151netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size)
152{
153 LWIP_ERROR("netbuf_ref: invalid buf", (buf != NULL), return ERR_ARG;);
154 if (buf->p != NULL) {
155 pbuf_free(buf->p);
156 }
157 buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
158 if (buf->p == NULL) {
159 buf->ptr = NULL;
160 return ERR_MEM;
161 }
162 ((struct pbuf_rom *)buf->p)->payload = dataptr;
163 buf->p->len = buf->p->tot_len = size;
164 buf->ptr = buf->p;
165 return ERR_OK;
166}
167
168/**
169 * @ingroup netbuf

Callers 1

lwip_sendtoFunction · 0.70

Calls 2

pbuf_freeFunction · 0.50
pbuf_allocFunction · 0.50

Tested by

no test coverage detected