diff options
Diffstat (limited to 'src/util/sock.h')
-rw-r--r-- | src/util/sock.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util/sock.h b/src/util/sock.h index 2d9cac14af..209d30def4 100644 --- a/src/util/sock.h +++ b/src/util/sock.h @@ -6,6 +6,7 @@ #define BITCOIN_UTIL_SOCK_H #include <compat.h> +#include <threadinterrupt.h> #include <util/time.h> #include <chrono> @@ -114,6 +115,34 @@ public: Event requested, Event* occurred = nullptr) const; + /* Higher level, convenience, methods. These may throw. */ + + /** + * Send the given data, retrying on transient errors. + * @param[in] data Data to send. + * @param[in] timeout Timeout for the entire operation. + * @param[in] interrupt If this is signaled then the operation is canceled. + * @throws std::runtime_error if the operation cannot be completed. In this case only some of + * the data will be written to the socket. + */ + virtual void SendComplete(const std::string& data, + std::chrono::milliseconds timeout, + CThreadInterrupt& interrupt) const; + + /** + * Read from socket until a terminator character is encountered. Will never consume bytes past + * the terminator from the socket. + * @param[in] terminator Character up to which to read from the socket. + * @param[in] timeout Timeout for the entire operation. + * @param[in] interrupt If this is signaled then the operation is canceled. + * @return The data that has been read, without the terminating character. + * @throws std::runtime_error if the operation cannot be completed. In this case some bytes may + * have been consumed from the socket. + */ + virtual std::string RecvUntilTerminator(uint8_t terminator, + std::chrono::milliseconds timeout, + CThreadInterrupt& interrupt) const; + private: /** * Contained socket. `INVALID_SOCKET` designates the object is empty. |