locked
Asynchronious IO and HTTP response streams use incompatible types

    Question

  • I've been trying out the response streams but I'm vexed by the fact that stream returned by open_istream() isn't compatible with http_request::set_response_stream().

    Here's what I currently do:

    void get(http::http_request request) { http::http_response response(http::status_codes::OK); auto opened = async::fstream::open_istream(L"foo.txt"); opened.then([=] (async::istream stream) mutable { static_assert(sizeof(char) == sizeof(async::byte), "We can only do the following cast if these " "two types match"); auto byteStream = reinterpret_cast<async::basic_istream<async::byte>&>(stream); response.set_response_stream(byteStream); request.reply(response); }); }

    Am I doing this wrong, or will this be cleaned up in a future release?

    Wednesday, October 10, 2012 6:00 AM

Answers

  • Hi Philip,

    Yes, we are looking into the issue around byte streams and char streams.

    For now, the following code could be used to hide the reinterpret cast (the library essentially does what you did above)

    auto bytestream = async::basic_istream<async::byte>(stream.rdbuf());

    Thank you,

    --Krishnan (Microsoft)


    --Krishnan (Microsoft)

    • Marked as answer by Philip Jackson Wednesday, October 10, 2012 9:19 PM
    Wednesday, October 10, 2012 8:14 PM

All replies

  • Hi Philip,

    Yes, we are looking into the issue around byte streams and char streams.

    For now, the following code could be used to hide the reinterpret cast (the library essentially does what you did above)

    auto bytestream = async::basic_istream<async::byte>(stream.rdbuf());

    Thank you,

    --Krishnan (Microsoft)


    --Krishnan (Microsoft)

    • Marked as answer by Philip Jackson Wednesday, October 10, 2012 9:19 PM
    Wednesday, October 10, 2012 8:14 PM
  • Thanks.

    I am really enjoying using Casablanca! Keep up the great work :D

    Wednesday, October 10, 2012 9:19 PM