diff options
| author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-10-28 11:26:02 +0100 | 
|---|---|---|
| committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-10-28 11:26:02 +0100 | 
| commit | 43c79b0269236cf981150645b46054d2ecf8ce61 (patch) | |
| tree | 6d43b928dabea9f46e71a2b4bf088d91c52bed56 | |
| parent | b25d18020f13766495d61411ace3bd89c08016ac (diff) | |
| download | ODR-SourceCompanion-43c79b0269236cf981150645b46054d2ecf8ce61.tar.gz ODR-SourceCompanion-43c79b0269236cf981150645b46054d2ecf8ce61.tar.bz2 ODR-SourceCompanion-43c79b0269236cf981150645b46054d2ecf8ce61.zip | |
common 81f518d: TCPSocket: let recv throw Interrupted on EINTR
| -rw-r--r-- | lib/Socket.cpp | 9 | ||||
| -rw-r--r-- | lib/Socket.h | 6 | 
2 files changed, 10 insertions, 5 deletions
| diff --git a/lib/Socket.cpp b/lib/Socket.cpp index bc1b179..d41ed1c 100644 --- a/lib/Socket.cpp +++ b/lib/Socket.cpp @@ -630,8 +630,13 @@ ssize_t TCPSocket::recv(void *buffer, size_t length, int flags)  {      ssize_t ret = ::recv(m_sock, buffer, length, flags);      if (ret == -1) { -        std::string errstr(strerror(errno)); -        throw std::runtime_error("TCP receive error: " + errstr); +        if (errno == EINTR) { +            throw Interrupted(); +        } +        else { +            std::string errstr(strerror(errno)); +            throw std::runtime_error("TCP receive error: " + errstr); +        }      }      return ret;  } diff --git a/lib/Socket.h b/lib/Socket.h index 8c6f8a9..8881be3 100644 --- a/lib/Socket.h +++ b/lib/Socket.h @@ -180,12 +180,12 @@ class TCPSocket {           */          ssize_t send(const void* data, size_t size, int timeout_ms=0); -        /* Returns number of bytes read, 0 on disconnect. Throws a -         * runtime_error on error */ +        class Interrupted {}; +        /* Returns number of bytes read, 0 on disconnect. +         * Throws Interrupted on EINTR, runtime_error on error */          ssize_t recv(void *buffer, size_t length, int flags);          class Timeout {}; -        class Interrupted {};          /* Returns number of bytes read, 0 on disconnect or refused connection.           * Throws a Timeout on timeout, Interrupted on EINTR, a runtime_error           * on error | 
