• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jbaldwin / libcoro / 21855558657

10 Feb 2026 07:22AM UTC coverage: 86.153%. First build
21855558657

Pull #436

github

web-flow
Merge 60a0bb5d7 into 95524de1d
Pull Request #436: Read/Write API

85 of 127 new or added lines in 7 files covered. (66.93%)

1879 of 2181 relevant lines covered (86.15%)

4579467.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.53
/src/net/io_status.cpp
1
#include "coro/net/io_status.hpp"
2
#include <system_error>
3

4
#if defined(_WIN32)
5
    #ifndef WIN32_LEAN_AND_MEAN
6
        #define WIN32_LEAN_AND_MEAN
7
    #endif
8
    #include <windows.h>
9
    #include <winsock2.h>
10
#endif
11

NEW
12
std::string coro::net::io_status::message() const
×
13
{
NEW
14
    if (not is_native())
×
15
    {
NEW
16
        return std::string{to_string(type)};
×
17
    }
18

NEW
19
    if (native_code == 0)
×
20
    {
NEW
21
        return "Success";
×
22
    }
23

24
#if defined(_WIN32)
25
    char*  buffer = nullptr;
26
    size_t size   = FormatMessageA(
27
        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
28
        nullptr,
29
        static_cast<DWORD>(native_code),
30
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
31
        reinterpret_cast<LPSTR>(&buffer),
32
        0,
33
        nullptr);
34

35
    if (size > 0 && buffer)
36
    {
37
        std::string msg(buffer, size);
38
        LocalFree(buffer);
39
        return msg;
40
    }
41
#else // Linux/BSD
42
    try
43
    {
NEW
44
        return std::system_category().message(native_code);
×
45
    }
NEW
46
    catch (...)
×
47
    {
NEW
48
        return "Unknown system error" + std::to_string(native_code) + ")";
×
NEW
49
    }
×
50
#endif
51
}
52

53
auto coro::net::make_io_status_from_native(int native_code) -> coro::net::io_status
196,595✔
54
{
55
#if defined(_WIN32)
56
    #error "TODO: WIN32"
57
#else // Linux/BSD
58
    using kind = io_status::kind;
59
    kind type;
60
    switch (native_code)
196,595✔
61
    {
62
        case 0:
1✔
63
            type = kind::ok;
1✔
64
            break;
1✔
65
        case EOF:
1✔
66
            type = kind::closed;
1✔
67
            break;
1✔
68
        case ECONNREFUSED:
1✔
69
            type = kind::connection_refused;
1✔
70
            break;
1✔
71
        case ECONNRESET:
1✔
72
            type = kind::connection_reset;
1✔
73
            break;
1✔
74
        case EAGAIN:
197,018✔
75
    #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
76
        case EWOULDBLOCK:
77
    #endif
78
            type = kind::would_block_or_try_again;
197,018✔
79
            break;
197,018✔
80
        case EMSGSIZE:
1✔
81
            type = kind::message_too_big;
1✔
82
            break;
1✔
83
        default:
84
            type = kind::native;
85
            break;
86
    }
87
    return coro::net::io_status{.type = type, .native_code = native_code};
196,595✔
88
#endif
89
}
90
auto coro::net::make_io_status_from_poll_status(coro::poll_status status) -> coro::net::io_status
21✔
91
{
92
    switch (status)
21✔
93
    {
94
        case poll_status::read:
2✔
95
        case poll_status::write:
96
            return io_status{io_status::kind::ok};
2✔
97
        case poll_status::timeout:
15✔
98
            return io_status{io_status::kind::timeout};
15✔
99
        case poll_status::error:
1✔
100
            return io_status{io_status::kind::polling_error};
1✔
101
        case poll_status::closed:
1✔
102
            return io_status{io_status::kind::closed};
1✔
103
        case poll_status::cancelled:
2✔
104
            return io_status{io_status::kind::cancelled};
2✔
105
    }
NEW
106
}
×
NEW
107
auto coro::net::to_string(coro::net::io_status::kind k) -> std::string_view
×
108
{
109
    using kind = io_status::kind;
NEW
110
    switch (k)
×
111
    {
NEW
112
        case kind::ok:
×
NEW
113
            return "Success";
×
NEW
114
        case kind::closed:
×
NEW
115
            return "Connection closed by peer";
×
NEW
116
        case kind::connection_reset:
×
NEW
117
            return "Connection reset by peer";
×
NEW
118
        case kind::connection_refused:
×
NEW
119
            return "Connection refused by target host";
×
NEW
120
        case kind::timeout:
×
NEW
121
            return "Operation timed out";
×
NEW
122
        case kind::would_block_or_try_again:
×
NEW
123
            return "would_block_or_try_again";
×
NEW
124
        case kind::polling_error:
×
NEW
125
            return "polling_error";
×
NEW
126
        case kind::cancelled:
×
NEW
127
            return "cancelled";
×
NEW
128
        case kind::udp_not_bound:
×
NEW
129
            return "udp_not_bound";
×
NEW
130
        case kind::native:
×
NEW
131
            return "native";
×
NEW
132
        case kind::message_too_big:
×
NEW
133
            return "message_too_big";
×
134
    }
NEW
135
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc