summaryrefslogtreecommitdiff
path: root/megawifi.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2018-01-31 21:59:08 -0800
committerMichael Pavone <pavone@retrodev.com>2018-01-31 21:59:08 -0800
commitaeb32eebf529a82a624f2c88f51a7706aad0bcc5 (patch)
treea1d09b547c1fa0322263034181cc5f535c9787b1 /megawifi.c
parent06373e75346f03c04a438c79ec4cf2f4a5095720 (diff)
Limit received LSD packets to 1440 bytes to match expectations of wflash code. Use MSG_NOSIGNAL to avoid getting killed with SIGPIPE
Diffstat (limited to 'megawifi.c')
-rw-r--r--megawifi.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/megawifi.c b/megawifi.c
index 23b2530..a0adfba 100644
--- a/megawifi.c
+++ b/megawifi.c
@@ -19,6 +19,7 @@ enum {
};
#define STX 0x7E
#define ETX 0x7E
+#define MAX_RECV_SIZE 1440
#define E(N) N
enum {
@@ -130,12 +131,11 @@ static void poll_socket(megawifi *mw, uint8_t channel)
mw->channel_flags |= 1 << (channel + 1);
}
} else if (mw->channel_state[channel] == 2 && mw->receive_bytes < sizeof(mw->receive_buffer) - 4) {
- int bytes = recv(
- mw->sock_fds[channel],
- mw->receive_buffer + mw->receive_bytes + 3,
- sizeof(mw->receive_buffer) - 4 - mw->receive_bytes,
- 0
- );
+ size_t max = sizeof(mw->receive_buffer) - 4 - mw->receive_bytes;
+ if (max > MAX_RECV_SIZE) {
+ max = MAX_RECV_SIZE;
+ }
+ int bytes = recv(mw->sock_fds[channel], mw->receive_buffer + mw->receive_bytes + 3, max, 0);
if (bytes > 0) {
mw_putc(mw, STX);
mw_putc(mw, bytes >> 8 | (channel+1) << 4);
@@ -315,7 +315,7 @@ static void process_packet(megawifi *mw)
}
} else if (mw->sock_fds[mw->transmit_channel - 1] >= 0 && mw->channel_state[mw->transmit_channel - 1] == 2) {
uint8_t channel = mw->transmit_channel - 1;
- int sent = send(mw->sock_fds[channel], mw->transmit_buffer, mw->transmit_bytes, 0);
+ int sent = send(mw->sock_fds[channel], mw->transmit_buffer, mw->transmit_bytes, MSG_NOSIGNAL);
if (sent < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
close(mw->sock_fds[channel]);
mw->sock_fds[channel] = -1;