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

Function pbuf_take

components/net/lwip/lwip-2.1.2/src/core/pbuf.c:1195–1226  ·  view source on GitHub ↗

* @ingroup pbuf * Copy application supplied data into a pbuf. * This function can only be used to copy the equivalent of buf->tot_len data. * * @param buf pbuf to fill with data * @param dataptr application supplied data buffer * @param len length of the application supplied data buffer * * @return ERR_OK if successful, ERR_MEM if the pbuf is not big enough */

Source from the content-addressed store, hash-verified

1193 * @return ERR_OK if successful, ERR_MEM if the pbuf is not big enough
1194 */
1195err_t
1196pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
1197{
1198 struct pbuf *p;
1199 size_t buf_copy_len;
1200 size_t total_copy_len = len;
1201 size_t copied_total = 0;
1202
1203 LWIP_ERROR("pbuf_take: invalid buf", (buf != NULL), return ERR_ARG;);
1204 LWIP_ERROR("pbuf_take: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
1205 LWIP_ERROR("pbuf_take: buf not large enough", (buf->tot_len >= len), return ERR_MEM;);
1206
1207 if ((buf == NULL) || (dataptr == NULL) || (buf->tot_len < len)) {
1208 return ERR_ARG;
1209 }
1210
1211 /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
1212 for (p = buf; total_copy_len != 0; p = p->next) {
1213 LWIP_ASSERT("pbuf_take: invalid pbuf", p != NULL);
1214 buf_copy_len = total_copy_len;
1215 if (buf_copy_len > p->len) {
1216 /* this pbuf cannot hold all remaining data */
1217 buf_copy_len = p->len;
1218 }
1219 /* copy the necessary parts of the buffer */
1220 MEMCPY(p->payload, &((const char *)dataptr)[copied_total], buf_copy_len);
1221 total_copy_len -= buf_copy_len;
1222 copied_total += buf_copy_len;
1223 }
1224 LWIP_ASSERT("did not copy all data", total_copy_len == 0 && copied_total == len);
1225 return ERR_OK;
1226}
1227
1228/**
1229 * @ingroup pbuf

Callers 15

pbuf_take_atFunction · 0.70
dns_sendFunction · 0.70
START_TESTFunction · 0.50
tcp_create_segment_wndFunction · 0.50
mdns_send_outpacketFunction · 0.50
vj_uncompress_tcpFunction · 0.50
pppos_input_tcpipFunction · 0.50
eth_mac_irqFunction · 0.50
imx_emac_rxFunction · 0.50

Calls

no outgoing calls

Tested by 3

START_TESTFunction · 0.40
tcp_create_segment_wndFunction · 0.40