98.28% Lines (57/58)
100.00% Functions (13/13)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2026 Michael Vandeberg | 2 | // Copyright (c) 2026 Michael Vandeberg | |||||
| 3 | // | 3 | // | |||||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 6 | // | 6 | // | |||||
| 7 | // Official repository: https://github.com/cppalliance/corosio | 7 | // Official repository: https://github.com/cppalliance/corosio | |||||
| 8 | // | 8 | // | |||||
| 9 | 9 | |||||||
| 10 | #include <boost/corosio/detail/platform.hpp> | 10 | #include <boost/corosio/detail/platform.hpp> | |||||
| 11 | 11 | |||||||
| 12 | #if BOOST_COROSIO_POSIX || BOOST_COROSIO_HAS_IOCP | 12 | #if BOOST_COROSIO_POSIX || BOOST_COROSIO_HAS_IOCP | |||||
| 13 | 13 | |||||||
| 14 | #include <boost/corosio/local_stream_socket.hpp> | 14 | #include <boost/corosio/local_stream_socket.hpp> | |||||
| 15 | #include <boost/corosio/detail/except.hpp> | 15 | #include <boost/corosio/detail/except.hpp> | |||||
| 16 | #include <boost/corosio/detail/local_stream_service.hpp> | 16 | #include <boost/corosio/detail/local_stream_service.hpp> | |||||
| 17 | #include <boost/corosio/native/detail/make_err.hpp> | 17 | #include <boost/corosio/native/detail/make_err.hpp> | |||||
| 18 | 18 | |||||||
| 19 | #if BOOST_COROSIO_POSIX | 19 | #if BOOST_COROSIO_POSIX | |||||
| 20 | #include <sys/ioctl.h> | 20 | #include <sys/ioctl.h> | |||||
| 21 | #elif BOOST_COROSIO_HAS_IOCP | 21 | #elif BOOST_COROSIO_HAS_IOCP | |||||
| 22 | #include <boost/corosio/native/detail/iocp/win_windows.hpp> | 22 | #include <boost/corosio/native/detail/iocp/win_windows.hpp> | |||||
| 23 | #endif | 23 | #endif | |||||
| 24 | 24 | |||||||
| 25 | namespace boost::corosio { | 25 | namespace boost::corosio { | |||||
| 26 | 26 | |||||||
| HITCBC | 27 | 342 | local_stream_socket::~local_stream_socket() | 27 | 342 | local_stream_socket::~local_stream_socket() | ||
| 28 | { | 28 | { | |||||
| HITCBC | 29 | 342 | close(); | 29 | 342 | close(); | ||
| HITCBC | 30 | 342 | } | 30 | 342 | } | ||
| 31 | 31 | |||||||
| HITCBC | 32 | 284 | local_stream_socket::local_stream_socket(capy::execution_context& ctx) | 32 | 284 | local_stream_socket::local_stream_socket(capy::execution_context& ctx) | ||
| HITCBC | 33 | 284 | : io_object(create_handle<detail::local_stream_service>(ctx)) | 33 | 284 | : io_object(create_handle<detail::local_stream_service>(ctx)) | ||
| 34 | { | 34 | { | |||||
| HITCBC | 35 | 284 | } | 35 | 284 | } | ||
| 36 | 36 | |||||||
| 37 | std::error_code | 37 | std::error_code | |||||
| HITCBC | 38 | 51 | local_stream_socket::open(local_stream proto) noexcept | 38 | 51 | local_stream_socket::open(local_stream proto) noexcept | ||
| 39 | { | 39 | { | |||||
| HITCBC | 40 | 51 | if (is_open()) | 40 | 51 | if (is_open()) | ||
| MISUBC | 41 | ✗ | return {}; | 41 | ✗ | return {}; | ||
| HITCBC | 42 | 51 | return open_for_family(proto.family(), proto.type(), proto.protocol()); | 42 | 51 | return open_for_family(proto.family(), proto.type(), proto.protocol()); | ||
| 43 | } | 43 | } | |||||
| 44 | 44 | |||||||
| 45 | std::error_code | 45 | std::error_code | |||||
| HITCBC | 46 | 51 | local_stream_socket::open_for_family( | 46 | 51 | local_stream_socket::open_for_family( | ||
| 47 | int family, int type, int protocol) noexcept | 47 | int family, int type, int protocol) noexcept | |||||
| 48 | { | 48 | { | |||||
| HITCBC | 49 | 51 | auto& svc = static_cast<detail::local_stream_service&>(h_.service()); | 49 | 51 | auto& svc = static_cast<detail::local_stream_service&>(h_.service()); | ||
| HITCBC | 50 | 51 | std::error_code ec = svc.open_socket( | 50 | 51 | std::error_code ec = svc.open_socket( | ||
| HITCBC | 51 | 51 | static_cast<local_stream_socket::implementation&>(*h_.get()), family, | 51 | 51 | static_cast<local_stream_socket::implementation&>(*h_.get()), family, | ||
| 52 | type, protocol); | 52 | type, protocol); | |||||
| HITCBC | 53 | 51 | return ec; | 53 | 51 | return ec; | ||
| 54 | } | 54 | } | |||||
| 55 | 55 | |||||||
| 56 | void | 56 | void | |||||
| HITCBC | 57 | 355 | local_stream_socket::close() noexcept | 57 | 355 | local_stream_socket::close() noexcept | ||
| 58 | { | 58 | { | |||||
| HITCBC | 59 | 355 | if (!is_open()) | 59 | 355 | if (!is_open()) | ||
| HITCBC | 60 | 133 | return; | 60 | 133 | return; | ||
| HITCBC | 61 | 222 | h_.service().close(h_); | 61 | 222 | h_.service().close(h_); | ||
| 62 | } | 62 | } | |||||
| 63 | 63 | |||||||
| 64 | void | 64 | void | |||||
| HITCBC | 65 | 8 | local_stream_socket::cancel() noexcept | 65 | 8 | local_stream_socket::cancel() noexcept | ||
| 66 | { | 66 | { | |||||
| HITCBC | 67 | 8 | if (!is_open()) | 67 | 8 | if (!is_open()) | ||
| HITCBC | 68 | 2 | return; | 68 | 2 | return; | ||
| HITCBC | 69 | 6 | get().cancel(); | 69 | 6 | get().cancel(); | ||
| 70 | } | 70 | } | |||||
| 71 | 71 | |||||||
| 72 | std::error_code | 72 | std::error_code | |||||
| HITCBC | 73 | 6 | local_stream_socket::shutdown(shutdown_type what) noexcept | 73 | 6 | local_stream_socket::shutdown(shutdown_type what) noexcept | ||
| 74 | { | 74 | { | |||||
| HITCBC | 75 | 6 | if (!is_open()) | 75 | 6 | if (!is_open()) | ||
| HITCBC | 76 | 2 | return make_error_code(std::errc::bad_file_descriptor); | 76 | 2 | return make_error_code(std::errc::bad_file_descriptor); | ||
| HITCBC | 77 | 4 | return get().shutdown(what); | 77 | 4 | return get().shutdown(what); | ||
| 78 | } | 78 | } | |||||
| 79 | 79 | |||||||
| 80 | std::error_code | 80 | std::error_code | |||||
| HITCBC | 81 | 173 | local_stream_socket::assign(native_handle_type fd) noexcept | 81 | 173 | local_stream_socket::assign(native_handle_type fd) noexcept | ||
| 82 | { | 82 | { | |||||
| HITCBC | 83 | 173 | auto& svc = static_cast<detail::local_stream_service&>(h_.service()); | 83 | 173 | auto& svc = static_cast<detail::local_stream_service&>(h_.service()); | ||
| HITCBC | 84 | 173 | std::error_code ec = svc.assign_socket( | 84 | 173 | std::error_code ec = svc.assign_socket( | ||
| HITCBC | 85 | 173 | static_cast<local_stream_socket::implementation&>(*h_.get()), fd); | 85 | 173 | static_cast<local_stream_socket::implementation&>(*h_.get()), fd); | ||
| HITCBC | 86 | 173 | return ec; | 86 | 173 | return ec; | ||
| 87 | } | 87 | } | |||||
| 88 | 88 | |||||||
| 89 | native_handle_type | 89 | native_handle_type | |||||
| HITCBC | 90 | 25 | local_stream_socket::native_handle() const noexcept | 90 | 25 | local_stream_socket::native_handle() const noexcept | ||
| 91 | { | 91 | { | |||||
| HITCBC | 92 | 25 | if (!is_open()) | 92 | 25 | if (!is_open()) | ||
| 93 | #if BOOST_COROSIO_HAS_IOCP | 93 | #if BOOST_COROSIO_HAS_IOCP | |||||
| 94 | return ~native_handle_type(0); | 94 | return ~native_handle_type(0); | |||||
| 95 | #else | 95 | #else | |||||
| HITCBC | 96 | 2 | return -1; | 96 | 2 | return -1; | ||
| 97 | #endif | 97 | #endif | |||||
| HITCBC | 98 | 23 | return get().native_handle(); | 98 | 23 | return get().native_handle(); | ||
| 99 | } | 99 | } | |||||
| 100 | 100 | |||||||
| 101 | native_handle_type | 101 | native_handle_type | |||||
| HITCBC | 102 | 6 | local_stream_socket::release() | 102 | 6 | local_stream_socket::release() | ||
| 103 | { | 103 | { | |||||
| HITCBC | 104 | 6 | if (!is_open()) | 104 | 6 | if (!is_open()) | ||
| HITCBC | 105 | 2 | detail::throw_system_error( | 105 | 2 | detail::throw_system_error( | ||
| HITCBC | 106 | 2 | make_error_code(std::errc::bad_file_descriptor), | 106 | 2 | make_error_code(std::errc::bad_file_descriptor), | ||
| 107 | "local_stream_socket::release"); | 107 | "local_stream_socket::release"); | |||||
| HITCBC | 108 | 4 | return get().release_socket(); | 108 | 4 | return get().release_socket(); | ||
| 109 | } | 109 | } | |||||
| 110 | 110 | |||||||
| 111 | std::size_t | 111 | std::size_t | |||||
| HITCBC | 112 | 11 | local_stream_socket::available() const | 112 | 11 | local_stream_socket::available() const | ||
| 113 | { | 113 | { | |||||
| HITCBC | 114 | 11 | if (!is_open()) | 114 | 11 | if (!is_open()) | ||
| HITCBC | 115 | 2 | detail::throw_system_error( | 115 | 2 | detail::throw_system_error( | ||
| HITCBC | 116 | 4 | make_error_code(std::errc::bad_file_descriptor), | 116 | 4 | make_error_code(std::errc::bad_file_descriptor), | ||
| 117 | "local_stream_socket::available"); | 117 | "local_stream_socket::available"); | |||||
| 118 | #if BOOST_COROSIO_HAS_IOCP | 118 | #if BOOST_COROSIO_HAS_IOCP | |||||
| 119 | u_long value = 0; | 119 | u_long value = 0; | |||||
| 120 | if (::ioctlsocket(static_cast<SOCKET>(native_handle()), FIONREAD, &value) != | 120 | if (::ioctlsocket(static_cast<SOCKET>(native_handle()), FIONREAD, &value) != | |||||
| 121 | 0) | 121 | 0) | |||||
| 122 | detail::throw_system_error( | 122 | detail::throw_system_error( | |||||
| 123 | detail::make_err(static_cast<unsigned long>(::WSAGetLastError())), | 123 | detail::make_err(static_cast<unsigned long>(::WSAGetLastError())), | |||||
| 124 | "local_stream_socket::available"); | 124 | "local_stream_socket::available"); | |||||
| 125 | return static_cast<std::size_t>(value); | 125 | return static_cast<std::size_t>(value); | |||||
| 126 | #else | 126 | #else | |||||
| HITCBC | 127 | 9 | int value = 0; | 127 | 9 | int value = 0; | ||
| HITCBC | 128 | 9 | if (::ioctl(native_handle(), FIONREAD, &value) < 0) | 128 | 9 | if (::ioctl(native_handle(), FIONREAD, &value) < 0) | ||
| HITCBC | 129 | 5 | detail::throw_system_error( | 129 | 5 | detail::throw_system_error( | ||
| HITCBC | 130 | 10 | detail::make_err(errno), "local_stream_socket::available"); | 130 | 10 | detail::make_err(errno), "local_stream_socket::available"); | ||
| HITCBC | 131 | 4 | return static_cast<std::size_t>(value); | 131 | 4 | return static_cast<std::size_t>(value); | ||
| 132 | #endif | 132 | #endif | |||||
| 133 | } | 133 | } | |||||
| 134 | 134 | |||||||
| 135 | local_endpoint | 135 | local_endpoint | |||||
| HITCBC | 136 | 6 | local_stream_socket::local_endpoint() const noexcept | 136 | 6 | local_stream_socket::local_endpoint() const noexcept | ||
| 137 | { | 137 | { | |||||
| HITCBC | 138 | 6 | if (!is_open()) | 138 | 6 | if (!is_open()) | ||
| HITCBC | 139 | 2 | return corosio::local_endpoint{}; | 139 | 2 | return corosio::local_endpoint{}; | ||
| HITCBC | 140 | 4 | return get().local_endpoint(); | 140 | 4 | return get().local_endpoint(); | ||
| 141 | } | 141 | } | |||||
| 142 | 142 | |||||||
| 143 | local_endpoint | 143 | local_endpoint | |||||
| HITCBC | 144 | 6 | local_stream_socket::remote_endpoint() const noexcept | 144 | 6 | local_stream_socket::remote_endpoint() const noexcept | ||
| 145 | { | 145 | { | |||||
| HITCBC | 146 | 6 | if (!is_open()) | 146 | 6 | if (!is_open()) | ||
| HITCBC | 147 | 2 | return corosio::local_endpoint{}; | 147 | 2 | return corosio::local_endpoint{}; | ||
| HITCBC | 148 | 4 | return get().remote_endpoint(); | 148 | 4 | return get().remote_endpoint(); | ||
| 149 | } | 149 | } | |||||
| 150 | 150 | |||||||
| 151 | } // namespace boost::corosio | 151 | } // namespace boost::corosio | |||||
| 152 | 152 | |||||||
| 153 | #endif // BOOST_COROSIO_POSIX || BOOST_COROSIO_HAS_IOCP | 153 | #endif // BOOST_COROSIO_POSIX || BOOST_COROSIO_HAS_IOCP | |||||