Reported by: https://casablanca.codeplex.com/discussions/561562.
When using a ```std::ofstream``` as a backing stream through the interop wrappers, write errors (such as disk full) do not cause an exception to be thrown.
As mentioned in the discussion, this is compounded by https://casablanca.codeplex.com/workitem/243, which prevents the easiest workaround.
Comments: Full Repro: ``` #include <cpprest/http_client.h> #include <cpprest/streams.h> #include <cpprest/interopstream.h> #include <boost/interprocess/streams/bufferstream.hpp> using namespace utility; // Common utilities like string conversions using namespace web; // Common features like URIs. using namespace web::http; // Common HTTP functionality using namespace web::http::client; // HTTP client features using namespace concurrency::streams; // Asynchronous streams int main(int argc, char* argv[]) { //auto fileStream = std::make_shared<ostream>(); // We'll write to a fixed length standard output stream: char our_buffer[200]; boost::interprocess::bufferstream limited_stream(our_buffer, sizeof(our_buffer), ::std::ios_base::out | std::ios_base::binary); concurrency::streams::stdio_ostream<char> os_wrapper(limited_stream); concurrency::streams::streambuf<char> os_streambuf = os_wrapper.streambuf(); auto p_os_streambuf = &os_streambuf; // for lambda below // No need to open stream here... pplx::task<void> requestTask = pplx::create_task([=]() { // Create http_client to send the request. http_client client(U("http://www.bing.com/")); // Build request URI and start the request. uri_builder builder(U("/search")); builder.append_query(U("q"), U("Casablanca CodePlex")); return client.request(methods::GET, builder.to_string()); }).then([=](http_response response) { // Write response body into the file. return response.body().read_to_end(*p_os_streambuf); }).then([=](size_t ret) { // Close the file stream. printf("read_to_end() returned %u\n", ret); return; // no need to close }); // Wait for all the outstanding I/O to complete and handle any exceptions try { requestTask.wait(); // Bytes in our buffer: std::streamoff nb_bytes = limited_stream.tellp(); std::cout << "We have captured " << nb_bytes << " bytes in our buffer." << std::endl; } catch (std::exception& e) { std::cerr << e.what() << std::endl; } return 0; } ```
When using a ```std::ofstream``` as a backing stream through the interop wrappers, write errors (such as disk full) do not cause an exception to be thrown.
As mentioned in the discussion, this is compounded by https://casablanca.codeplex.com/workitem/243, which prevents the easiest workaround.
Comments: Full Repro: ``` #include <cpprest/http_client.h> #include <cpprest/streams.h> #include <cpprest/interopstream.h> #include <boost/interprocess/streams/bufferstream.hpp> using namespace utility; // Common utilities like string conversions using namespace web; // Common features like URIs. using namespace web::http; // Common HTTP functionality using namespace web::http::client; // HTTP client features using namespace concurrency::streams; // Asynchronous streams int main(int argc, char* argv[]) { //auto fileStream = std::make_shared<ostream>(); // We'll write to a fixed length standard output stream: char our_buffer[200]; boost::interprocess::bufferstream limited_stream(our_buffer, sizeof(our_buffer), ::std::ios_base::out | std::ios_base::binary); concurrency::streams::stdio_ostream<char> os_wrapper(limited_stream); concurrency::streams::streambuf<char> os_streambuf = os_wrapper.streambuf(); auto p_os_streambuf = &os_streambuf; // for lambda below // No need to open stream here... pplx::task<void> requestTask = pplx::create_task([=]() { // Create http_client to send the request. http_client client(U("http://www.bing.com/")); // Build request URI and start the request. uri_builder builder(U("/search")); builder.append_query(U("q"), U("Casablanca CodePlex")); return client.request(methods::GET, builder.to_string()); }).then([=](http_response response) { // Write response body into the file. return response.body().read_to_end(*p_os_streambuf); }).then([=](size_t ret) { // Close the file stream. printf("read_to_end() returned %u\n", ret); return; // no need to close }); // Wait for all the outstanding I/O to complete and handle any exceptions try { requestTask.wait(); // Bytes in our buffer: std::streamoff nb_bytes = limited_stream.tellp(); std::cout << "We have captured " << nb_bytes << " bytes in our buffer." << std::endl; } catch (std::exception& e) { std::cerr << e.what() << std::endl; } return 0; } ```