Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9584345

Browse files
committed
Adjusting test to only support streaming in asynchronous clients for now.
1 parent00b8cf8 commit9584345

File tree

5 files changed

+79
-35
lines changed

5 files changed

+79
-35
lines changed

‎CMakeLists.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ cmake_minimum_required(VERSION 2.6)
77
project(CPP-NETLIB)
88
find_package( Boost 1.41.0 )
99
set(CMAKE_VERBOSE_MAKEFILEtrue)
10+
11+
if (CMAKE_BUILD_TYPEMATCHES Debug)
12+
add_definitions(-DBOOST_NETWORK_DEBUG)
13+
endif()
14+
1015
if (Boost_FOUND)
1116
set(Boost_USE_STATIC_LIBSON)
1217
set(Boost_USE_MULTI_THREADEDON)

‎boost/network/protocol/http/client/connection/async_normal.hpp‎

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include<boost/network/version.hpp>
11+
#include<boost/network/detail/debug.hpp>
1112
#include<boost/thread/future.hpp>
1213
#include<boost/throw_exception.hpp>
1314
#include<boost/cstdint.hpp>
@@ -237,7 +238,7 @@ namespace boost { namespace network { namespace http { namespace impl {
237238
boost::bind(
238239
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
239240
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
240-
body, get_body, callback,
241+
headers, get_body, callback,
241242
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
242243
)
243244
)
@@ -247,29 +248,43 @@ namespace boost { namespace network { namespace http { namespace impl {
247248
this->body_promise.set_value("");
248249
return;
249250
}
250-
this->parse_body(
251-
*socket_,
252-
request_strand_.wrap(
253-
boost::bind(
254-
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
255-
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
256-
body, get_body, callback,
257-
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
258-
)
259-
),
260-
remainder);
261-
break;
262-
case body:
263-
if (!get_body) {
251+
if (callback) {
252+
typename protocol_base::buffer_type::const_iterator begin =this->part.begin();
253+
std::advance(begin, remainder);
254+
typename protocol_base::buffer_type::const_iterator end = begin;
255+
std::advance(end,this->part.size() - remainder);
256+
callback(make_iterator_range(begin, end), ec);
257+
socket_->async_read_some(
258+
boost::asio::mutable_buffers_1(this->part.c_array(),this->part.size()),
259+
request_strand_.wrap(
260+
boost::bind(
261+
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
262+
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
263+
body, get_body, callback,
264+
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)
265+
)
266+
);
264267
this->body_promise.set_value("");
265-
return;
268+
}else {
269+
this->parse_body(
270+
*socket_,
271+
request_strand_.wrap(
272+
boost::bind(
273+
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
274+
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
275+
body, get_body, callback,
276+
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
277+
)
278+
),
279+
remainder);
266280
}
281+
break;
282+
case body:
267283
if (ec == boost::asio::error::eof) {
268-
if (!callback.empty()) {
284+
if (callback) {
269285
typename protocol_base::buffer_type::const_iterator begin =this->part.begin(), end = begin;
270286
std::advance(end, bytes_transferred);
271287
callback(make_iterator_range(begin, end), ec);
272-
this->body_promise.set_value("");
273288
}else {
274289
string_type body_string;
275290
std::swap(body_string,this->partial_parsed);
@@ -285,7 +300,7 @@ namespace boost { namespace network { namespace http { namespace impl {
285300
this->part.assign('\0');
286301
this->response_parser_.reset();
287302
}else {
288-
if (!callback.empty()) {
303+
if (callback) {
289304
typename protocol_base::buffer_type::const_iterator begin =this->part.begin(), end = begin;
290305
std::advance(end, bytes_transferred);
291306
callback(make_iterator_range(begin, end), ec);

‎libs/network/test/http/CMakeLists.txt‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ if (OPENSSL_FOUND)
1313
add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS)
1414
endif()
1515

16-
if (CMAKE_BUILD_TYPEMATCHES Debug)
17-
add_definitions(-DBOOST_NETWORK_DEBUG)
18-
endif()
19-
2016
find_package( Threads )
2117
set(Boost_USE_STATIC_LIBSON)
2218
set(Boost_USE_MULTITHREADEDON)
@@ -28,6 +24,7 @@ if (Boost_FOUND)
2824
client_get_different_port_test
2925
client_get_timeout_test
3026
client_localhost_normal_test
27+
client_get_streaming_test
3128
)
3229
if (OPENSSL_FOUND)
3330
set ( TESTS${TESTS} client_localhost_ssl_test )

‎libs/network/test/http/client_get_streaming_test.cpp‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#defineBOOST_TEST_MODULE HTTP1.1 Get Streaming Test
77
#include<boost/network/include/http/client.hpp>
88
#include<boost/test/unit_test.hpp>
9+
#include<iostream>
910
#include"client_types.hpp"
1011

1112
namespacenet= boost::network;
@@ -17,7 +18,6 @@ struct body_handler {
1718
: body(body) {}
1819

1920
BOOST_NETWORK_HTTP_BODY_CALLBACK(operator(), range, error) {
20-
std::cout <<"Length:" <<std::distance(boost::begin(range),boost::end(range)) << std::endl;
2121
body.append(boost::begin(range),boost::end(range));
2222
}
2323

@@ -26,20 +26,23 @@ struct body_handler {
2626
};
2727

2828

29-
BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_get_streaming_test, client,client_types) {
29+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_get_streaming_test, client,async_only_client_types) {
3030
typename client::requestrequest("http://www.boost.org");
31-
client client_;
3231
typename client::response response;
3332
typename client::string_type body_string;
33+
typename client::string_type dummy_body;
3434
body_handlerhandler_instance(body_string);
35-
BOOST_CHECK_NO_THROW( response = client_.get(request, http::_body_handler=handler_instance) );
36-
typename net::headers_range<typename client::response>::type range =headers(response)["Content-Type"];
37-
BOOST_CHECK ( !boost::empty(range) );
38-
BOOST_CHECK (body(response).size() !=0 );
39-
BOOST_CHECK_EQUAL ( response.version().substr(0,7),std::string("HTTP/1.") );
40-
BOOST_CHECK_EQUAL ( response.status(),200u );
41-
BOOST_CHECK_EQUAL ( response.status_message(),std::string("OK") );
42-
typename client::string_type dummy_body =body(response);
43-
BOOST_CHECK_EQUAL ( dummy_body,typenameclient::string_type() );
35+
{
36+
client client_;
37+
BOOST_CHECK_NO_THROW( response = client_.get(request, http::_body_handler=handler_instance) );
38+
typename net::headers_range<typename client::response>::type range =headers(response)["Content-Type"];
39+
BOOST_CHECK ( !boost::empty(range) );
40+
BOOST_CHECK_EQUAL (body(response).size(),0u );
41+
BOOST_CHECK_EQUAL ( response.version().substr(0,7),std::string("HTTP/1.") );
42+
BOOST_CHECK_EQUAL ( response.status(),200u );
43+
BOOST_CHECK_EQUAL ( response.status_message(),std::string("OK") );
44+
dummy_body =body(response);
45+
}
46+
BOOST_CHECK ( dummy_body ==typenameclient::string_type() );
4447
}
4548

‎libs/network/test/http/client_types.hpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include<boost/mpl/joint_view.hpp>
1111
#include<boost/mpl/bind.hpp>
1212
#include<boost/mpl/transform.hpp>
13+
#include<boost/mpl/remove_if.hpp>
1314
#include<boost/mpl/int.hpp>
15+
#include<boost/network/support/is_sync.hpp>
1416

1517
namespacempl= boost::mpl ;
1618

@@ -41,4 +43,26 @@ typedef mpl::joint_view<
4143
, client_1_1
4244
>::type client_types;
4345

46+
typedef
47+
mpl::joint_view<
48+
mpl::transform<
49+
mpl::remove_if<
50+
tag_types,
51+
boost::network::is_sync<
52+
boost::mpl::_
53+
>
54+
>::type,
55+
client_adapter<1,0>
56+
>::type,
57+
mpl::transform<
58+
mpl::remove_if<
59+
tag_types,
60+
boost::network::is_sync<
61+
boost::mpl::_
62+
>
63+
>::type,
64+
client_adapter<1,1>
65+
>::type
66+
>::type async_only_client_types;
67+
4468
#endif/* CLIENT_TYPES_ROOWQCLE*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp