Skip to content

Commit 8797e4d

Browse files
committed
Removed dependency on boost thread, including for examples.
1 parent d601264 commit 8797e4d

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ add_definitions(-DBOOST_TEST_DYN_LINK)
4747
set(Boost_USE_MULTI_THREADED ON)
4848

4949
find_package(Boost 1.57.0
50-
REQUIRED system thread filesystem program_options)
50+
REQUIRED system filesystem program_options)
5151

5252
if (CPP-NETLIB_ENABLE_HTTPS)
5353
find_package( OpenSSL )

libs/network/example/http/fileserver.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
#include <memory>
7+
#include <thread>
78
#include <boost/network/include/http/server.hpp>
8-
#include <boost/thread.hpp>
99
#include <sys/mman.h>
1010
#include <sys/types.h>
1111
#include <sys/stat.h>
@@ -28,7 +28,7 @@ struct file_cache {
2828
std::string doc_root_;
2929
region_map regions;
3030
meta_map file_headers;
31-
boost::shared_mutex cache_mutex;
31+
std::mutex cache_mutex;
3232

3333
explicit file_cache(std::string doc_root) : doc_root_(std::move(doc_root)) {}
3434

@@ -39,12 +39,12 @@ struct file_cache {
3939
}
4040

4141
bool has(std::string const &path) {
42-
boost::shared_lock<boost::shared_mutex> lock(cache_mutex);
42+
std::unique_lock<std::mutex> lock(cache_mutex);
4343
return regions.find(doc_root_ + path) != regions.end();
4444
}
4545

4646
bool add(std::string const &path) {
47-
boost::upgrade_lock<boost::shared_mutex> lock(cache_mutex);
47+
std::unique_lock<std::mutex> lock(cache_mutex);
4848
std::string real_filename = doc_root_ + path;
4949
if (regions.find(real_filename) != regions.end()) return true;
5050
#ifdef O_NOATIME
@@ -60,7 +60,6 @@ struct file_cache {
6060
return false;
6161
}
6262

63-
boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(lock);
6463
regions.insert(std::make_pair(real_filename, std::make_pair(region, size)));
6564
static server::response_header common_headers[] = {
6665
{"Connection", "close"}, {"Content-Type", "x-application/octet-stream"},
@@ -73,7 +72,7 @@ struct file_cache {
7372
}
7473

7574
std::pair<void *, std::size_t> get(std::string const &path) {
76-
boost::shared_lock<boost::shared_mutex> lock(cache_mutex);
75+
std::unique_lock<std::mutex> lock(cache_mutex);
7776
region_map::const_iterator region = regions.find(doc_root_ + path);
7877
if (region != regions.end())
7978
return region->second;
@@ -83,14 +82,12 @@ struct file_cache {
8382

8483
boost::iterator_range<std::vector<server::response_header>::iterator> meta(
8584
std::string const &path) {
86-
boost::shared_lock<boost::shared_mutex> lock(cache_mutex);
85+
std::unique_lock<std::mutex> lock(cache_mutex);
8786
static std::vector<server::response_header> empty_vector;
8887
auto headers = file_headers.find(doc_root_ + path);
8988
if (headers != file_headers.end()) {
90-
auto begin = headers->second
91-
.begin(),
92-
end =
93-
headers->second.end();
89+
auto begin = headers->second.begin(),
90+
end = headers->second.end();
9491
return boost::make_iterator_range(begin, end);
9592
} else
9693
return boost::make_iterator_range(empty_vector);

libs/network/example/http/hello_world_async_server_with_work_queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ int main() {
167167
auto server(std::make_shared<server_data>(
168168
server::options(request_handler)
169169
.address("0.0.0.0")
170-
.port("8800")
170+
.port("8000")
171171
.io_service(io_service)
172172
.reuse_address(true)
173173
.thread_pool(std::make_shared<boost::network::utils::thread_pool>(

0 commit comments

Comments
 (0)