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; struct sockaddr_in addr;
socklen_t len = sizeof(addr); socklen_t len = sizeof(addr);
/* Accept clients in a loop. This is halting so other threads will /* Accept clients in a loop. This should block when there are no clients
* be able to process clients. * so other threads can run.
*/ */
do { do {
client = zsock_accept(server, (struct sockaddr *)&addr, &len); client = zsock_accept(server, (struct sockaddr *)&addr, &len);
@ -64,23 +64,20 @@ server_accept_client(int server)
} }
bool bool
sock_read_buf(int sock, struct bufptr *bp) sock_read_buf(int sock, struct bufptr *bp, bool entire)
{ {
if (bp->left < 2) if (bp->left < 2)
return false; return false;
ssize_t l = zsock_recv(sock, bp->p, bp->left - 1, 0); do {
if (l < 0) ssize_t l = zsock_recv(sock, bp->p, bp->left - 1, 0);
return false; if (l < 0)
return false;
bp->left -= l; bp->left -= l;
bp->p += l; bp->p += l;
if (bp->left == 0) { } while (entire && bp->left > 0);
LOG_ERR("internal out of bounds error in %s", __func__);
k_fatal_halt(K_ERR_KERNEL_PANIC);
}
*bp->p = 0;
return true; 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 /* Read data into buffer. Returns false if error occurs. This is
* raw binary (no NUL termination). * 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 /* Write raw buffer data into socket. This data is raw binary and
* does not have to be NUL terminated. * does not have to be NUL terminated.