citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit 6990aaa3f5fa1dc5275bc73641772c8e4e536b87
parent 87391981e57467a2b0018c40f5d25cc80fa6f62f
Author: Kyle Milz <kyle@0x30.net>
Date:   Sun, 31 Jul 2016 10:31:36 -0600

src: throw an exception when read == 0 too

Diffstat:
Msrc/af_unix.cc | 5+++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/af_unix.cc b/src/af_unix.cc @@ -22,6 +22,7 @@ #include <fcntl.h> // fcntl, F_GETFL #include <iostream> #include <stdexcept> +#include <system_error> // system_error #include <unistd.h> // close, read #include "af_unix.h" @@ -122,7 +123,7 @@ af_unix::write_all(uint8_t *buf, size_t bytes_total) n = write(m_fd, buf + bytes_wrote, bytes_left); if (n < 0) - throw std::runtime_error("write failed"); + throw std::system_error(errno, std::system_category()); bytes_wrote += n; bytes_left -= n; @@ -142,7 +143,7 @@ af_unix::read_all(uint8_t *buf, size_t bytes_total) n = read(m_fd, buf + bytes_read, bytes_left); if (n == 0) - errx(1, "read(): read 0 bytes on socket"); + throw std::runtime_error("read 0 bytes on socket"); if (n < 0) err(1, "read()");