10000 extmod/modlwip: lwip_tcp_send(): Common subexpression elimination, us… · micropython/micropython@fa87e90 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa87e90

Browse files
author
Paul Sokolovsky
committed
extmod/modlwip: lwip_tcp_send(): Common subexpression elimination, use MIN().
1 parent 7621706 commit fa87e90

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

extmod/modlwip.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,19 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
353353
}
354354

355355
// Helper function for send/sendto to handle TCP packets
356-
STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t
357-
len, int *_errno) {
358-
u16_t available = tcp_sndbuf((struct tcp_pcb *)socket->pcb);
356+
STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) {
357+
struct tcp_pcb *pcb = (struct tcp_pcb *)socket->pcb;
358+
u16_t available = tcp_sndbuf(pcb);
359+
u16_t write_len = MIN(available, len);
359360

360-
err_t err = tcp_write((struct tcp_pcb *)socket->pcb, buf, (available > len ? len : available), TCP_WRITE_FLAG_COPY);
361+
err_t err = tcp_write(pcb, buf, write_len, TCP_WRITE_FLAG_COPY);
361362

362363
if (err != ERR_OK) {
363364
*_errno = error_lookup_table[-err];
364365
return -1;
365366
}
366367

367-
return available > len ? len : available;
368+
return write_len;
368369
}
369370

370371
// Helper function for recv/recvfrom to handle TCP packets

0 commit comments

Comments
 (0)
0