2016-05-05 10 views
3

新しいプロジェクトにcpp netlibを使用することを検討しています。例のすべては、ブロッキングの方法で応答の本文を読んで示していますcpp-netlibによる非同期クライアントの応答?

client::response response_ = client_.get(request_); 
std::string body_ = body(response_); 

私は非同期タグと私のクライアントオブジェクトを作成する場合:

basic_client<http_async_8bit_udp_resolve_tags, 1, 1> client_(); 

それはどのような影響を与えるがありますか?

bodyラッパーの結果をboost::shared_future<std::string>として取得できますか?

ブロッキングコールを自分のスレッドにラップするだけでいいですか?現在のHTTPクライアントドキュメントで

答えて

1

ルック:http://cpp-netlib.org/0.12.0/reference/http_client.html

  1. HTTPクライアントを使用すると、getまたはpost呼び出しでコールバック関数やオブジェクトを提供するためのオプションがあり、デフォルト
  2. によって常に今非同期です。

    struct body_handler { 
    
        explicit body_handler(std::string & body) 
        : body(body) {} 
    
        BOOST_NETWORK_HTTP_BODY_CALLBACK(operator(), range, error) { 
         // in here, range is the Boost.Range iterator_range, and error is 
         // the Boost.System error code. 
         if (!error) 
          body.append(boost::begin(range), boost::end(range)); 
        } 
    
        std::string & body; 
    }; 
    
    // somewhere else 
    std::string some_string; 
    response_ = client_.get(request("http://cpp-netlib.github.com/"), 
            body_handler(some_string)); 
    
  3. client::responseオブジェクトがすでにfutureオブジェクトをincapsulates:

レスポンスオブジェクトは、値が用意されていたらでいっぱいに先物をカプセル化します。

関連する問題