Skip to content

Commit 6f13b29

Browse files
authored
🐛 TCP 拆包后数据错误问题 (#48)
* 🐛 复现TCP拆包后数据错误 * 🐛 修复tcp拆包后数据错误问题 * 🐛 变量命名,代码格式化
1 parent 6113876 commit 6f13b29

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/net/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static int tcp_sendmsg(socket_t *s, msghdr_t *msg, u32 flags)
377377
continue;
378378

379379
int len = left < iov->size ? left : iov->size;
380-
tcp_enqueue(pcb, iov->base, left, flags);
380+
tcp_enqueue(pcb, iov->base, len, flags);
381381
left -= len;
382382
}
383383
tcp_output(pcb);

src/net/tcp_output.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ err_t tcp_enqueue(tcp_pcb_t *pcb, void *data, size_t size, int flags)
4747
ip_t *ip;
4848
tcp_t *tcp;
4949
pbuf_t *pbuf;
50+
void *ptr = data;
5051

5152
if (pcb->snd_mss < TCP_DEFAULT_MSS)
5253
pcb->snd_mss = TCP_DEFAULT_MSS;
@@ -83,8 +84,11 @@ err_t tcp_enqueue(tcp_pcb_t *pcb, void *data, size_t size, int flags)
8384
int seglen = (pcb->snd_mss - pbuf->size);
8485
int len = left < seglen ? left : seglen;
8586

86-
if (left > 0)
87-
memcpy(pbuf->data + pbuf->size, data, len);
87+
if (len > 0)
88+
{
89+
memcpy(pbuf->data + pbuf->size, ptr, len);
90+
ptr += len;
91+
}
8892

8993
pcb->snd_nbb += len;
9094
pbuf->size += len;

0 commit comments

Comments
 (0)