make read_buf read until it fills up all of bufptr

This commit is contained in:
Peter McGoron 2023-04-02 21:46:10 +00:00
parent e5e8b28676
commit c5019de982
2 changed files with 11 additions and 14 deletions

View File

@ -48,8 +48,8 @@ server_accept_client(int server)
struct sockaddr_in addr;
socklen_t len = sizeof(addr);
/* Accept clients in a loop. This is halting so other threads will
* be able to process clients.
/* Accept clients in a loop. This should block when there are no clients
* so other threads can run.
*/
do {
client = zsock_accept(server, (struct sockaddr *)&addr, &len);
@ -64,23 +64,20 @@ server_accept_client(int server)
}
bool
sock_read_buf(int sock, struct bufptr *bp)
sock_read_buf(int sock, struct bufptr *bp, bool entire)
{
if (bp->left < 2)
return false;
ssize_t l = zsock_recv(sock, bp->p, bp->left - 1, 0);
if (l < 0)
return false;
do {
ssize_t l = zsock_recv(sock, bp->p, bp->left - 1, 0);
if (l < 0)
return false;
bp->left -= l;
bp->p += l;
if (bp->left == 0) {
LOG_ERR("internal out of bounds error in %s", __func__);
k_fatal_halt(K_ERR_KERNEL_PANIC);
}
bp->left -= l;
bp->p += l;
} while (entire && bp->left > 0);
*bp->p = 0;
return true;
}

View File

@ -13,7 +13,7 @@ int server_accept_client(int server);
/* Read data into buffer. Returns false if error occurs. This is
* raw binary (no NUL termination).
*/
bool sock_read_buf(int sock, struct bufptr *bp);
bool sock_read_buf(int sock, struct bufptr *bp, bool entire);
/* Write raw buffer data into socket. This data is raw binary and
* does not have to be NUL terminated.