diff --git a/include/boost/beast/core/detail/win32_unicode_path.hpp b/include/boost/beast/core/detail/win32_unicode_path.hpp index 3f77e651be..f0ff9295db 100644 --- a/include/boost/beast/core/detail/win32_unicode_path.hpp +++ b/include/boost/beast/core/detail/win32_unicode_path.hpp @@ -29,6 +29,7 @@ class win32_unicode_path public: win32_unicode_path(const char* utf8_path, error_code& ec) { + ec = {}; int ret = mb2wide(utf8_path, static_buf_.data(), static_buf_.size()); if (ret == 0) diff --git a/include/boost/beast/core/impl/file_posix.ipp b/include/boost/beast/core/impl/file_posix.ipp index e8fa900e0c..bdd5c45f1d 100644 --- a/include/boost/beast/core/impl/file_posix.ipp +++ b/include/boost/beast/core/impl/file_posix.ipp @@ -288,12 +288,13 @@ read(void* buffer, std::size_t n, error_code& ec) const if(result == 0) { // short read - return nread; + break; } n -= result; nread += result; buffer = static_cast(buffer) + result; } + ec = {}; return nread; } @@ -328,6 +329,7 @@ write(void const* buffer, std::size_t n, error_code& ec) nwritten += result; buffer = static_cast(buffer) + result; } + ec = {}; return nwritten; } diff --git a/include/boost/beast/core/impl/file_stdio.ipp b/include/boost/beast/core/impl/file_stdio.ipp index 69dbcfed58..63cf87eef7 100644 --- a/include/boost/beast/core/impl/file_stdio.ipp +++ b/include/boost/beast/core/impl/file_stdio.ipp @@ -300,6 +300,7 @@ read(void* buffer, std::size_t n, error_code& ec) const ec.assign(errno, generic_category()); return 0; } + ec = {}; return nread; } @@ -318,6 +319,7 @@ write(void const* buffer, std::size_t n, error_code& ec) ec.assign(errno, generic_category()); return 0; } + ec = {}; return nwritten; } diff --git a/test/beast/core/file_test.hpp b/test/beast/core/file_test.hpp index e5a54b9d20..ecf3ffc869 100644 --- a/test/beast/core/file_test.hpp +++ b/test/beast/core/file_test.hpp @@ -445,6 +445,80 @@ test_file() } BEAST_EXPECT(! fs::exists(path)); + { + string_view const s = "Hello, world!"; + + { + File f; + error_code ec = make_error_code(errc::no_such_file_or_directory); + f.open(path, file_mode::write, ec); + BEAST_EXPECT(! ec); + } + + { + File f; + error_code ec; + f.open(path, file_mode::write, ec); + BEAST_EXPECT(! ec); + ec = make_error_code(errc::no_such_file_or_directory); + f.write(s.data(), s.size(), ec); + BEAST_EXPECT(! ec); + } + + { + File f; + error_code ec; + f.open(path, file_mode::read, ec); + BEAST_EXPECT(! ec); + ec = make_error_code(errc::no_such_file_or_directory); + f.size(ec); + BEAST_EXPECT(! ec); + } + + { + File f; + error_code ec; + f.open(path, file_mode::read, ec); + BEAST_EXPECT(! ec); + ec = make_error_code(errc::no_such_file_or_directory); + f.pos(ec); + BEAST_EXPECT(! ec); + } + + { + File f; + error_code ec; + f.open(path, file_mode::read, ec); + BEAST_EXPECT(! ec); + ec = make_error_code(errc::no_such_file_or_directory); + f.seek(0, ec); + BEAST_EXPECT(! ec); + } + + { + File f; + error_code ec; + f.open(path, file_mode::read, ec); + BEAST_EXPECT(! ec); + std::string buf; + buf.resize(s.size()); + ec = make_error_code(errc::no_such_file_or_directory); + f.read(&buf[0], buf.size(), ec); + BEAST_EXPECT(! ec); + } + + { + File f; + error_code ec; + f.open(path, file_mode::read, ec); + BEAST_EXPECT(! ec); + ec = make_error_code(errc::no_such_file_or_directory); + f.close(ec); + BEAST_EXPECT(! ec); + } + + remove(path); + } } } // beast diff --git a/tools/get-boost.sh b/tools/get-boost.sh index 281b01640f..45d5297e79 100755 --- a/tools/get-boost.sh +++ b/tools/get-boost.sh @@ -82,6 +82,7 @@ git submodule update --init --depth 20 --jobs 4 \ libs/ratio \ libs/rational \ libs/regex \ + libs/static_assert \ libs/thread \ libs/tuple \ libs/type_index \