Skip to content

Commit 8ea3166

Browse files
wangchen61698xiaoxiang781216
authored andcommitted
tcp_recvfrom.c:malloc a new iob to handle psock_send_eventhandler when tcp_recvhandler calls tcp_newdata to clear dev->d_iob
Signed-off-by: wangchen <[email protected]>
1 parent 97eef35 commit 8ea3166

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

net/tcp/tcp_recvfrom.c

+26
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ static uint16_t tcp_recvhandler(FAR struct net_driver_s *dev,
393393
FAR void *pvpriv, uint16_t flags)
394394
{
395395
FAR struct tcp_recvfrom_s *pstate = pvpriv;
396+
FAR struct iob_s *iob = NULL;
396397

397398
ninfo("flags: %04x\n", flags);
398399

@@ -408,12 +409,37 @@ static uint16_t tcp_recvhandler(FAR struct net_driver_s *dev,
408409

409410
tcp_sender(dev, pstate);
410411

412+
if ((flags & TCP_ACKDATA) != 0)
413+
{
414+
iob = iob_tryalloc(false);
415+
if (iob == NULL)
416+
{
417+
nerr("ERROR: IOB alloc failed !\n");
418+
return flags;
419+
}
420+
421+
iob_reserve(iob, CONFIG_NET_LL_GUARDSIZE);
422+
int ret = iob_clone_partial(dev->d_iob, dev->d_iob->io_pktlen,
423+
0, iob, 0, false, false);
424+
if (ret < 0)
425+
{
426+
iob_free_chain(iob);
427+
nerr("ERROR: IOB clone failed ret=%d!\n", ret);
428+
return flags;
429+
}
430+
}
431+
411432
/* Copy the data from the packet (saving any unused bytes from the
412433
* packet in the read-ahead buffer).
413434
*/
414435

415436
flags = tcp_newdata(dev, pstate, flags);
416437

438+
if (iob != NULL)
439+
{
440+
netdev_iob_replace(dev, iob);
441+
}
442+
417443
/* Indicate that the data has been consumed and that an ACK
418444
* should be sent.
419445
*/

0 commit comments

Comments
 (0)