NNTP65/POP65: Cleanup of error handling code in w5100_tcp_send_recv().

This commit is contained in:
Bobbi Webber-Manners 2020-09-13 18:34:12 -04:00
parent 5c855c825e
commit 1fbeda9e5f
2 changed files with 28 additions and 26 deletions

View File

@ -251,6 +251,8 @@ bool w5100_tcp_send_recv(char* sendbuf, char* recvbuf, size_t length,
uint16_t len = 0;
uint8_t cont = 1;
--length; // Leave space for NULL at end in case of buffer overrun
while (cont) {
if (input_check_for_abort_key()) {
printf("User abort\n");
@ -265,23 +267,21 @@ bool w5100_tcp_send_recv(char* sendbuf, char* recvbuf, size_t length,
continue;
}
if (rcv == 0) {
if (strncmp(sendbuf, "QUIT\r\n", 6) == 0)
return true; // This can happen on QUIT. It's okay.
else {
printf("Something bad\n");
return false;
}
}
// if (rcv == 0) {
// if (strncmp(sendbuf, "QUIT\r\n", 6) == 0)
// return true; // This can happen on QUIT. It's okay.
// else {
// printf("Remote host disconnected\n");
// return false;
// }
// }
if ((length - len) == 0)
cont = 0;
if (rcv > length - len)
rcv = length - len;
if (rcv == 0) {
printf("Buffer overflow\n");
return false;
}
{
// One less to allow for faster pre-increment below
// 4 bytes of overlap between blocks
@ -299,6 +299,7 @@ bool w5100_tcp_send_recv(char* sendbuf, char* recvbuf, size_t length,
w5100_receive_commit(rcv);
len += rcv;
}
recvbuf[len + 1] = '\0';
putchar('<');
print_strip_crlf(recvbuf);
}

View File

@ -246,6 +246,8 @@ bool w5100_tcp_send_recv(char* sendbuf, char* recvbuf, size_t length,
uint16_t len = 0;
uint8_t cont = 1;
--length; // Leave space for NULL at end in case of buffer overrun
while (cont) {
if (input_check_for_abort_key()) {
printf("User abort\n");
@ -260,23 +262,21 @@ bool w5100_tcp_send_recv(char* sendbuf, char* recvbuf, size_t length,
continue;
}
if (rcv == 0) {
if (strncmp(sendbuf, "QUIT\r\n", 6) == 0)
return true; // This can happen on QUIT. It's okay.
else {
printf("Something bad\n");
return false;
}
}
// if (rcv == 0) {
// if (strncmp(sendbuf, "QUIT\r\n", 6) == 0)
// return true; // This can happen on QUIT. It's okay.
// else {
// printf("Something bad\n");
// return false;
// }
// }
if ((length - len) == 0)
cont = 0;
if (rcv > length - len)
rcv = length - len;
if (rcv == 0) {
printf("Buffer overflow\n");
return false;
}
{
// One less to allow for faster pre-increment below
char *dataptr = recvbuf + len - 1;
@ -293,6 +293,7 @@ bool w5100_tcp_send_recv(char* sendbuf, char* recvbuf, size_t length,
w5100_receive_commit(rcv);
len += rcv;
}
recvbuf[len + 1] = '\0';
putchar('<');
print_strip_crlf(recvbuf);
}