userver: userver/engine/io/exception.hpp Source File
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/engine/io/exception.hpp
4/// @brief I/O exceptions
5
6#include <stdexcept>
7#include <string_view>
8#include <system_error>
9
10#include <userver/utils/traceful_exception.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace engine::io {
15
16/// Generic I/O error.
17class IoException : public utils::TracefulException {
18 public:
19 IoException();
20
21 explicit IoException(std::string_view message);
22};
23
24/// I/O interruption.
25class IoInterrupted : public IoException {
26 public:
27 explicit IoInterrupted(std::string_view reason, size_t bytes_transferred);
28
29 /// Number of bytes transferred before interruption.
30 size_t BytesTransferred() const { return bytes_transferred_; }
31
32 private:
33 size_t bytes_transferred_;
34};
35
36/// I/O timeout.
37class IoTimeout : public IoInterrupted {
38 public:
39 IoTimeout();
40 explicit IoTimeout(size_t bytes_transferred);
41};
42
43/// Task cancellation during I/O.
44/// Context description is expected to be provided by user.
45class IoCancelled : public IoInterrupted {
46 public:
47 IoCancelled();
48 explicit IoCancelled(size_t bytes_transferred);
49};
50
51/// Operating system I/O error.
52class IoSystemError : public IoException {
53 public:
54 IoSystemError(int err_value, std::string_view reason);
55 IoSystemError(std::error_code code, std::string_view reason);
56
57 /// Operating system error code.
58 const std::error_code& Code() const { return code_; }
59
60 private:
61 std::error_code code_;
62};
63
64/// TLS I/O error.
65class TlsException : public IoException {
66 public:
67 using IoException::IoException;
68 ~TlsException() override;
69};
70
71} // namespace engine::io
72
73USERVER_NAMESPACE_END