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

jbaldwin / libcoro / 21535532851

31 Jan 2026 12:35AM UTC coverage: 84.889%. First build
21535532851

Pull #436

github

web-flow
Merge 0e762f846 into 582f5096e
Pull Request #436: Read/Write API

41 of 115 new or added lines in 6 files covered. (35.65%)

1837 of 2164 relevant lines covered (84.89%)

4642848.01 hits per line

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

8.82
/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
        switch (type)
×
17
        {
NEW
18
            case kind::ok:
×
NEW
19
                return "Success";
×
NEW
20
            case kind::closed:
×
NEW
21
                return "Connection closed by peer";
×
NEW
22
            case kind::connection_reset:
×
NEW
23
                return "Connection reset by peer";
×
NEW
24
            case kind::connection_refused:
×
NEW
25
                return "Connection refused by target host";
×
NEW
26
            case kind::timeout:
×
NEW
27
                return "Operation timed out";
×
NEW
28
            case kind::would_block_or_try_again:
×
NEW
29
                return "would_block_or_try_again";
×
NEW
30
            case kind::polling_error:
×
NEW
31
                return "polling_error";
×
NEW
32
            case kind::cancelled:
×
NEW
33
                return "cancelled";
×
NEW
34
            case kind::udp_not_bound:
×
NEW
35
                return "udp_not_bound";
×
NEW
36
            case kind::native:
×
NEW
37
                return "native";
×
NEW
38
            case kind::message_to_big:
×
NEW
39
                return "message_to_big";
×
40
        }
41
    }
42

NEW
43
    if (native_code == 0)
×
44
    {
NEW
45
        return "Success";
×
46
    }
47

48
#if defined(_WIN32)
49
    char*  buffer = nullptr;
50
    size_t size   = FormatMessageA(
51
        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
52
        nullptr,
53
        static_cast<DWORD>(native_code),
54
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
55
        reinterpret_cast<LPSTR>(&buffer),
56
        0,
57
        nullptr);
58

59
    if (size > 0 && buffer)
60
    {
61
        std::string msg(buffer, size);
62
        LocalFree(buffer);
63
        return msg;
64
    }
65
#else // Linux/BSD
66
    try
67
    {
NEW
68
        return std::system_category().message(native_code);
×
69
    }
NEW
70
    catch (...)
×
71
    {
NEW
72
        return "Unknown system error" + std::to_string(native_code) + ")";
×
NEW
73
    }
×
74
#endif
75
}
76

NEW
77
auto coro::net::make_io_status_from_native(int native_code) -> coro::net::io_status
×
78
{
79
#if defined(_WIN32)
80
    #error "TODO: WIN32"
81
#else // Linux/BSD
82
    using kind = io_status::kind;
83
    kind type;
NEW
84
    switch (native_code)
×
85
    {
NEW
86
        case 0:
×
NEW
87
            type = kind::ok;
×
NEW
88
            break;
×
NEW
89
        case EOF:
×
NEW
90
            type = kind::closed;
×
NEW
91
            break;
×
NEW
92
        case ECONNREFUSED:
×
NEW
93
            type = kind::connection_refused;
×
NEW
94
            break;
×
NEW
95
        case ECONNRESET:
×
NEW
96
            type = kind::connection_reset;
×
NEW
97
            break;
×
NEW
98
        case EAGAIN:
×
99
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
100
        case EWOULDBLOCK:
101
#endif
NEW
102
            type = kind::would_block_or_try_again;
×
NEW
103
            break;
×
NEW
104
        case EMSGSIZE:
×
NEW
105
            type = kind::message_to_big;
×
NEW
106
            break;
×
NEW
107
        default:
×
NEW
108
            type = kind::native;
×
NEW
109
            break;
×
110
    }
NEW
111
    return coro::net::io_status{.type = type, .native_code = native_code};
×
112
#endif
113
}
114
auto coro::net::make_io_status_from_poll_status(coro::poll_status status) -> coro::net::io_status
12✔
115
{
116
    switch (status)
12✔
117
    {
NEW
118
        case poll_status::read:
×
119
        case poll_status::write:
NEW
120
            return io_status{io_status::kind::ok};
×
121
        case poll_status::timeout:
11✔
122
            return io_status{io_status::kind::timeout};
11✔
NEW
123
        case poll_status::error:
×
NEW
124
            return io_status{io_status::kind::polling_error};
×
NEW
125
        case poll_status::closed:
×
NEW
126
            return io_status{io_status::kind::closed};
×
127
        case poll_status::cancelled:
1✔
128
            return io_status{io_status::kind::cancelled};
1✔
129
    }
NEW
130
}
×
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