aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/coroutine/engine/iostatus.h
blob: 8478ce05e80e3dde642d9efee37f155e59ce94a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
 
#include <util/generic/yexception.h>

class TIOStatus { 
public: 
    TIOStatus(int status) noexcept
        : Status_(status) 
    { 
    } 
 
    static TIOStatus Error(int status) noexcept {
        return TIOStatus(status); 
    } 
 
    static TIOStatus Error() noexcept {
        return TIOStatus(LastSystemError()); 
    } 
 
    static TIOStatus Success() noexcept {
        return TIOStatus(0); 
    } 
 
    void Check() const {
        if (Status_) { 
            ythrow TSystemError(Status_) << "io error"; 
        } 
    } 
 
    bool Failed() const noexcept {
        return (bool)Status_; 
    } 
 
    bool Succeed() const noexcept {
        return !Failed(); 
    } 
 
    int Status() const noexcept {
        return Status_; 
    } 
 
private: 
    int Status_; 
}; 
 

class TContIOStatus { 
public: 
    TContIOStatus(size_t processed, TIOStatus status) noexcept
        : Processed_(processed) 
        , Status_(status) 
    { 
    } 
 
    static TContIOStatus Error(TIOStatus status) noexcept {
        return TContIOStatus(0, status); 
    } 
 
    static TContIOStatus Error() noexcept {
        return TContIOStatus(0, TIOStatus::Error()); 
    } 
 
    static TContIOStatus Success(size_t processed) noexcept {
        return TContIOStatus(processed, TIOStatus::Success()); 
    } 
 
    static TContIOStatus Eof() noexcept {
        return Success(0); 
    } 
 
    ~TContIOStatus() {
    } 
 
    size_t Processed() const noexcept {
        return Processed_; 
    } 
 
    int Status() const noexcept {
        return Status_.Status(); 
    } 
 
    size_t Checked() const {
        Status_.Check(); 
 
        return Processed_; 
    } 
 
private: 
    size_t Processed_; 
    TIOStatus Status_; 
};