Skip to content

Commit 8e63590

Browse files
committed
Conflicts: libs/network/src/CMakeLists.txt libs/network/test/CMakeLists.txt
2 parents 6b9c321 + b9c3a01 commit 8e63590

32 files changed

+360
-78
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ libs/mime/test/mime-roundtrip
1010
bin/
1111
tests/
1212
_build
13+
*~

CMakeLists.txt

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@
77
cmake_minimum_required(VERSION 2.8)
88
project(CPP-NETLIB)
99

10+
option(BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF)
11+
option(BUILD_TESTS "Build the unit tests." ON)
12+
option(BUILD_EXAMPLES "Build the examples using cpp-netlib." ON)
13+
1014
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
1115
find_package( ICU )
1216

13-
set(Boost_USE_STATIC_LIBS ON)
17+
if(BUILD_SHARED_LIBS)
18+
set(Boost_USE_STATIC_LIBS OFF)
19+
else()
20+
set(Boost_USE_STATIC_LIBS ON)
21+
endif()
1422
set(Boost_USE_MULTITHREADED ON)
15-
find_package( Boost 1.45.0 REQUIRED unit_test_framework system regex date_time thread chrono filesystem program_options )
23+
if(BUILD_TESTS)
24+
set(Boost_COMPONENTS unit_test_framework system regex date_time thread chrono filesystem program_options )
25+
else()
26+
set(Boost_COMPONENTS system regex date_time thread chrono filesystem program_options )
27+
endif()
28+
find_package( Boost 1.51 REQUIRED ${Boost_COMPONENTS} )
1629
find_package( OpenSSL )
1730
find_package( Threads )
1831
set(CMAKE_VERBOSE_MAKEFILE true)
@@ -54,13 +67,27 @@ if (Boost_FOUND)
5467
add_definitions(-D_WIN32_WINNT=0x0501)
5568
endif(WIN32)
5669
include_directories(${Boost_INCLUDE_DIRS})
57-
enable_testing()
70+
if(BUILD_TESTS)
71+
enable_testing()
72+
endif()
5873
add_subdirectory(libs/network/src)
59-
add_subdirectory(libs/network/test)
60-
if (NOT MSVC)
61-
add_subdirectory(libs/mime/test)
62-
endif(NOT MSVC)
63-
add_subdirectory(libs/network/example)
74+
if(BUILD_TESTS)
75+
enable_testing()
76+
add_subdirectory(libs/network/test)
77+
if (NOT MSVC)
78+
add_subdirectory(libs/mime/test)
79+
endif(NOT MSVC)
80+
endif()
81+
if(BUILD_EXAMPLES)
82+
add_subdirectory(libs/network/example)
83+
endif()
6484
endif(Boost_FOUND)
6585

66-
enable_testing()
86+
if(BUILD_TESTS)
87+
enable_testing()
88+
endif()
89+
90+
message(STATUS "Options selected:")
91+
message(STATUS " BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}\t(Build cpp-netlib as shared libraries: OFF, ON)")
92+
message(STATUS " BUILD_TESTS: ${BUILD_TESTS}\t(Build the unit tests: ON, OFF)")
93+
message(STATUS " BUILD_EXAMPLES: ${BUILD_EXAMPLES}\t(Build the examples using cpp-netlib: ON, OFF)")

Jamroot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import os ;
88

9-
local BOOST_ROOT = [ os.environ BOOST_ROOT ] ;
9+
path-constant BOOST_ROOT : [ os.environ BOOST_ROOT ] ;
1010

1111
use-project /boost : $(BOOST_ROOT) ;
1212
use-project /cpp-netlib : libs/network/build ;

include/network/protocol/http/client/connection/async_normal.ipp

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,20 +430,44 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
430430
placeholders::bytes_transferred)));
431431
} else {
432432
NETWORK_MESSAGE("no callback provided, appending to body...");
433+
bool get_more = true;
434+
if (content_length_) {
435+
buffer_type::const_iterator begin = this->part.begin();
436+
buffer_type::const_iterator end = begin;
437+
std::advance(end, bytes_transferred);
438+
get_more = (end - begin) < *content_length_;
439+
NETWORK_MESSAGE("content_length = " << * content_length_
440+
<< ", bytes read = " << (end - begin) << ", read more = " << get_more);
441+
}
433442
// Here we don't have a body callback. Let's
434443
// make sure that we deal with the remainder
435444
// from the headers part in case we do have data
436445
// that's still in the buffer.
437-
this->parse_body(request_strand_.wrap(
438-
boost::bind(
439-
&this_type::handle_received_data,
440-
this_type::shared_from_this(),
441-
body,
442-
get_body,
443-
callback,
444-
placeholders::error,
445-
placeholders::bytes_transferred)),
446-
bytes_transferred);
446+
if (get_more) {
447+
this->parse_body(request_strand_.wrap(
448+
boost::bind(
449+
&this_type::handle_received_data,
450+
this_type::shared_from_this(),
451+
body,
452+
get_body,
453+
callback,
454+
placeholders::error,
455+
placeholders::bytes_transferred)),
456+
bytes_transferred);
457+
} else {
458+
std::string body_string;
459+
std::swap(body_string, this->partial_parsed);
460+
body_string.append(
461+
this->part.begin()
462+
, bytes_transferred
463+
);
464+
this->body_promise.set_value(body_string);
465+
// TODO set the destination value somewhere!
466+
this->destination_promise.set_value("");
467+
this->source_promise.set_value("");
468+
this->part.assign('\0');
469+
this->response_parser_.reset();
470+
}
447471
}
448472
}
449473
return;
@@ -709,6 +733,21 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
709733
boost::trim(header_pair.second);
710734
headers.insert(header_pair);
711735
}
736+
// Set content length
737+
content_length_ = boost::none;
738+
auto it = headers.find("Content-Length");
739+
if (it != headers.end()) {
740+
try {
741+
content_length_ = std::stoul(it->second);
742+
NETWORK_MESSAGE("Content-Length: " << *content_length_);
743+
} catch(const std::invalid_argument&) {
744+
NETWORK_MESSAGE("invalid argument exception while interpreting "
745+
<< it->second << " as content length");
746+
} catch(const std::out_of_range&) {
747+
NETWORK_MESSAGE("out of range exception while interpreting "
748+
<< it->second << " as content length");
749+
}
750+
}
712751
headers_promise.set_value(headers);
713752
}
714753

@@ -790,6 +829,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
790829
boost::promise<boost::uint16_t> status_promise;
791830
boost::promise<std::string> status_message_promise;
792831
boost::promise<std::multimap<std::string, std::string> > headers_promise;
832+
boost::optional<size_t> content_length_;
793833
boost::promise<std::string> source_promise;
794834
boost::promise<std::string> destination_promise;
795835
boost::promise<std::string> body_promise;

libs/mime/test/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
include_directories(${CPP-NETLIB_SOURCE_DIR})
2-
find_package ( Boost 1.41.0 COMPONENTS unit_test_framework )
3-
set ( Boost_USE_STATIC_LIBS ON )
4-
set ( Boost_USE_MULTITHREADED ON )
52

63
if ( Boost_FOUND )
74
add_executable ( mime-roundtrip mime-roundtrip.cpp )

libs/network/build/Jamfile.v2

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,77 @@
44
# (See accompanying file LICENSE_1_0.txt or copy at
55
# http://www.boost.org/LICENSE_1_0.txt)
66

7-
import os ;
8-
9-
local BOOST_ROOT = [ os.environ BOOST_ROOT ] ;
7+
import pch ;
108

119
project cpp-netlib :
1210
requirements
13-
<include>../../../
11+
<variant>debug:<define>NETWORK_DEBUG
12+
<toolset>gcc:<define>NETWORK_ENABLE_HTTPS
13+
<toolset>gcc:<cxxflags>-std=c++0x
14+
<include>../../../include
1415
<include>$(BOOST_ROOT)
1516
<c++-template-depth>256
17+
<link>static
1618
: source-location ../../../
1719
;
1820

19-
cpp-pch client : boost/network/include/http/client.hpp ;
20-
cpp-pch server : boost/network/include/http/server.hpp ;
21-
lib cppnetlib-uri : libs/network/src/uri/parse.cpp ;
22-
lib cppnetlib-server-parsers : libs/network/src/server_request_parsers_impl.cpp ;
23-
lib cppnetlib-client-connections : libs/network/src/client.cpp ;
21+
cpp-pch client : include/network/include/http/client.hpp ;
22+
cpp-pch server : include/network/include/http/server.hpp ;
23+
lib cppnetlib-uri : libs/network/src/uri/normalize.cpp
24+
libs/network/src/uri/schemes.cpp
25+
libs/network/src/uri/uri.cpp ;
26+
27+
lib cppnetlib-message : libs/network/src/message/message.cpp cppnetlib-uri ;
28+
lib cppnetlib-message-directives : libs/network/src/message/directives.cpp ;
29+
lib cppnetlib-message-wrappers : libs/network/src/message/wrappers.cpp ;
30+
lib cppnetlib-http-message : libs/network/src/http/request.cpp
31+
libs/network/src/http/response.cpp
32+
cppnetlib-message ;
33+
34+
lib cppnetlib-http-message-wrappers : libs/network/src/http/message/wrappers.cpp ;
35+
lib cppnetlib-http-server-parsers : libs/network/src/server_request_parsers_impl.cpp ;
36+
lib cppnetlib-http-server : libs/network/src/http/server_async_impl.cpp
37+
libs/network/src/http/server_options.cpp
38+
libs/network/src/http/server_socket_options_setter.cpp
39+
libs/network/src/http/server_sync_impl.cpp
40+
cppnetlib-constants
41+
cppnetlib-uri
42+
cppnetlib-message
43+
cppnetlib-message-wrappers
44+
cppnetlib-message-directives
45+
cppnetlib-http-message
46+
cppnetlib-http-message-wrappers
47+
cppnetlib-http-server-parsers ;
48+
49+
lib cppnetlib-http-client-connections : libs/network/src/http/client_connections.cpp
50+
libs/network/src/http/simple_connection_manager.cpp
51+
libs/network/src/http/simple_connection_factory.cpp
52+
libs/network/src/http/connection_delegate_factory.cpp
53+
libs/network/src/http/client_resolver_delegate.cpp
54+
libs/network/src/http/client_resolver_delegate_factory.cpp
55+
libs/network/src/http/client_connection_delegates.cpp
56+
libs/network/src/http/client_connection_factory.cpp
57+
libs/network/src/http/client_async_resolver.cpp
58+
libs/network/src/http/client_connection_normal.cpp ;
59+
60+
lib cppnetlib-http-client : libs/network/src/http/client.cpp
61+
cppnetlib-constants
62+
cppnetlib-uri
63+
cppnetlib-message
64+
cppnetlib-message-wrappers
65+
cppnetlib-message-directives
66+
cppnetlib-http-message
67+
cppnetlib-http-message-wrappers
68+
cppnetlib-http-client-connections ;
69+
70+
lib cppnetlib-utils-thread_pool : libs/network/src/utils/thread_pool.cpp ;
71+
lib cppnetlib-constants : libs/network/src/constants.cpp ;
2472

2573
install headers : client server
2674
: <location>../../../boost/network/include/http ;
2775

28-
install libraries : cppnetlib-uri cppnetlib-server-parsers cppnetlib-client-connections ;
76+
install libraries : cppnetlib-uri cppnetlib-message cppnetlib-message-directives cppnetlib-message-wrappers
77+
cppnetlib-http-message cppnetlib-http-message-wrappers cppnetlib-http-server-parsers cppnetlib-http-server
78+
cppnetlib-http-client-connections cppnetlib-http-client cppnetlib-utils-thread_pool cppnetlib-constants ;
2979

3080
alias all : headers ;

libs/network/src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ endforeach(src_file)
8484
set(CPP-NETLIB_HTTP_MESSAGE_SRCS http/request.cpp http/response.cpp)
8585
add_library(cppnetlib-http-message ${CPP-NETLIB_HTTP_MESSAGE_SRCS})
8686
add_dependencies(cppnetlib-http-message
87-
${Boost_LIBRARIES}
87+
# ${Boost_LIBRARIES}
8888
cppnetlib-message)
8989
target_link_libraries(cppnetlib-http-message
9090
${Boost_LIBRARIES}
@@ -122,7 +122,6 @@ set(CPP-NETLIB_HTTP_SERVER_SRCS
122122
)
123123
add_library(cppnetlib-http-server ${CPP-NETLIB_HTTP_SERVER_SRCS})
124124
add_dependencies(cppnetlib-http-server
125-
${Boost_LIBRARIES}
126125
${CPP-NETLIB_LOGGING_LIB}
127126
cppnetlib-constants
128127
cppnetlib-uri
@@ -132,6 +131,7 @@ add_dependencies(cppnetlib-http-server
132131
cppnetlib-http-message
133132
cppnetlib-http-message-wrappers
134133
cppnetlib-http-server-parsers
134+
cppnetlib-utils-thread_pool
135135
)
136136
target_link_libraries(cppnetlib-http-server
137137
${Boost_LIBRARIES}
@@ -144,6 +144,7 @@ target_link_libraries(cppnetlib-http-server
144144
cppnetlib-http-message
145145
cppnetlib-http-message-wrappers
146146
cppnetlib-http-server-parsers
147+
cppnetlib-utils-thread_pool
147148
)
148149
foreach (src_file ${CPP-NETLIB_HTTP_SERVER_SRCS})
149150
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
@@ -175,7 +176,6 @@ set(CPP-NETLIB_HTTP_CLIENT_SRCS
175176
http/client.cpp)
176177
add_library(cppnetlib-http-client ${CPP-NETLIB_HTTP_CLIENT_SRCS})
177178
add_dependencies(cppnetlib-http-client
178-
${Boost_LIBRARIES}
179179
${CPP-NETLIB_LOGGING_LIB}
180180
cppnetlib-constants
181181
cppnetlib-uri

libs/network/test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
include_directories(${CPP-NETLIB_SOURCE_DIR}/include)
77

8+
if(BUILD_SHARED_LIBS)
9+
add_definitions(-DBUILD_SHARED_LIBS)
10+
endif()
11+
812
add_subdirectory(logging)
913
add_subdirectory(uri)
1014
add_subdirectory(http)

libs/network/test/Jamfile.v2

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
# Copyright Dean Michael Berris 2007.
33
# Distributed under the Boost Software License, Version 1.0.
44
# (See accompanying file LICENSE_1_0.txt or copy at
@@ -15,24 +15,23 @@ if [ os.name ] = CYGWIN
1515

1616
project network_test :
1717
requirements
18-
<include>../../../
19-
<include>.
18+
<include>../../../include
2019
<source>/boost//unit_test_framework
2120
<source>/boost//system
2221
<source>/boost//date_time
2322
<source>/boost//regex
2423
<source>/boost//thread
2524
<source>/boost//filesystem
26-
<variant>debug:<define>BOOST_NETWORK_DEBUG
27-
<toolset>gcc:<define>BOOST_NETWORK_ENABLE_HTTPS
25+
<variant>debug:<define>NETWORK_DEBUG
26+
<toolset>gcc:<define>NETWORK_ENABLE_HTTPS
2827
<toolset>gcc:<linkflags>-lpthread
2928
<toolset>gcc:<linkflags>-lssl
3029
<toolset>gcc:<linkflags>-lcrypto
31-
<toolset>darwin:<define>BOOST_NETWORK_ENABLE_HTTPS
30+
<toolset>darwin:<define>NETWORK_ENABLE_HTTPS
3231
<toolset>darwin:<linkflags>-lpthread
3332
<toolset>darwin:<linkflags>-lssl
3433
<toolset>darwin:<linkflags>-lcrypto
35-
<toolset>clang:<define>BOOST_NETWORK_ENABLE_HTTPS
34+
<toolset>clang:<define>NETWORK_ENABLE_HTTPS
3635
<toolset>clang:<linkflags>-lpthread
3736
<toolset>clang:<linkflags>-lssl
3837
<toolset>clang:<linkflags>-lcrypto
@@ -43,13 +42,19 @@ project network_test :
4342
<toolset>msvc:<define>BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN
4443
<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
4544
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
46-
<toolset>msvc:<define>_WIN32_WINNT=0x0501
45+
<toolset>msvc:<define>_WIN32_WINNT=0x0501
4746
<c++-template-depth>256
4847
<link>static
4948
;
5049

5150
build-project http ;
5251
build-project uri ;
5352

54-
run message_test.cpp ;
55-
run message_transform_test.cpp ;
53+
run message_test.cpp /cpp-netlib//cppnetlib-message
54+
/cpp-netlib//cppnetlib-message-directives
55+
/cpp-netlib//cppnetlib-message-wrappers ;
56+
57+
run message_transform_test.cpp /cpp-netlib//cppnetlib-message
58+
/cpp-netlib//cppnetlib-message-directives
59+
/cpp-netlib//cppnetlib-message-wrappers ;
60+

0 commit comments

Comments
 (0)