Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/test/unit/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3685,6 +3685,7 @@ START_TEST(test_sock_sendto_tcp_multiple_segments_flags)
ck_assert_int_gt(tcp_sd, 0);
ts = &s.tcpsockets[SOCKET_UNMARK(tcp_sd)];
ts->sock.tcp.state = TCP_ESTABLISHED;
ts->sock.tcp.peer_mss = TCP_MSS;
ts->src_port = 1234;
ts->dst_port = 4321;
ts->local_ip = 0x0A000001U;
Expand All @@ -3699,12 +3700,12 @@ START_TEST(test_sock_sendto_tcp_multiple_segments_flags)
first = fifo_peek(&ts->sock.tcp.txbuf);
ck_assert_ptr_nonnull(first);
tcp1 = (struct wolfIP_tcp_seg *)(txbuf + first->pos + sizeof(*first));
ck_assert_uint_eq(tcp1->flags & (TCP_FLAG_ACK | TCP_FLAG_PSH), (TCP_FLAG_ACK | TCP_FLAG_PSH));
ck_assert_uint_eq(tcp1->flags & (TCP_FLAG_ACK | TCP_FLAG_PSH), TCP_FLAG_ACK);

second = fifo_next(&ts->sock.tcp.txbuf, first);
ck_assert_ptr_nonnull(second);
tcp2 = (struct wolfIP_tcp_seg *)(txbuf + second->pos + sizeof(*second));
ck_assert_uint_eq(tcp2->flags & (TCP_FLAG_ACK | TCP_FLAG_PSH), TCP_FLAG_ACK);
ck_assert_uint_eq(tcp2->flags & (TCP_FLAG_ACK | TCP_FLAG_PSH), (TCP_FLAG_ACK | TCP_FLAG_PSH));
}
END_TEST

Expand Down
23 changes: 21 additions & 2 deletions src/wolfip.c
Original file line number Diff line number Diff line change
Expand Up @@ -3897,7 +3897,7 @@ int wolfIP_sock_sendto(struct wolfIP *s, int sockfd, const void *buf, size_t len
tcp->seq = ee32(ts->sock.tcp.seq);
tcp->ack = ee32(ts->sock.tcp.ack);
tcp->hlen = (uint8_t)((TCP_HEADER_LEN + opt_len) << 2);
tcp->flags = TCP_FLAG_ACK | ((sent == 0) ? TCP_FLAG_PSH : 0); /* ACK; PSH only on first */
tcp->flags = TCP_FLAG_ACK;
tcp->win = ee16(tcp_adv_win(ts));
tcp->csum = 0;
tcp->urg = 0;
Expand All @@ -3923,8 +3923,27 @@ int wolfIP_sock_sendto(struct wolfIP *s, int sockfd, const void *buf, size_t len
}
if (sent == 0) {
return -WOLFIP_EAGAIN;
} else
} else {
struct pkt_desc *desc;
struct pkt_desc *last_desc = NULL;
uint32_t guard = 0;
uint32_t budget = fifo_desc_budget(&ts->sock.tcp.txbuf);
desc = fifo_peek(&ts->sock.tcp.txbuf);
while (desc && guard++ < budget) {
struct pkt_desc *next = fifo_next(&ts->sock.tcp.txbuf, desc);
last_desc = desc;
if (next == desc)
break;
desc = next;
}
if (last_desc) {
/* PSH flag is set on the last segment in this train */
struct wolfIP_tcp_seg *last_tcp =
(struct wolfIP_tcp_seg *)((uint8_t *)last_desc + sizeof(*last_desc));
last_tcp->flags |= TCP_FLAG_PSH;
Comment thread
danielinux marked this conversation as resolved.
}
return sent;
}
} else if (IS_SOCKET_UDP(sockfd)) {
const struct wolfIP_sockaddr_in *sin = (const struct wolfIP_sockaddr_in *)dest_addr;
unsigned int if_idx;
Expand Down