mirror of
https://github.com/bobbimanners/emailler.git
synced 2025-08-09 20:25:07 +00:00
NNTP65/POP65: Cleanup of error handling code in w5100_tcp_send_recv().
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
27
apps/pop65.c
27
apps/pop65.c
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user