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

Thread group#590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
deanberris merged 3 commits intocpp-netlib:masterfromglynos:thread_group
Jan 31, 2016
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Removed dependency on boost thread, including for examples.
  • Loading branch information
@glynos
glynos committedJan 30, 2016
commit8797e4daeef0bed955424b89788953afe7ddb49e
2 changes: 1 addition & 1 deletionCMakeLists.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,7 +47,7 @@ add_definitions(-DBOOST_TEST_DYN_LINK)
set(Boost_USE_MULTI_THREADED ON)

find_package(Boost 1.57.0
REQUIRED systemthreadfilesystem program_options)
REQUIRED system filesystem program_options)

if (CPP-NETLIB_ENABLE_HTTPS)
find_package( OpenSSL )
Expand Down
19 changes: 8 additions & 11 deletionslibs/network/example/http/fileserver.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,8 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include <memory>
#include <thread>
#include <boost/network/include/http/server.hpp>
#include <boost/thread.hpp>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand All@@ -28,7 +28,7 @@ struct file_cache {
std::string doc_root_;
region_map regions;
meta_map file_headers;
boost::shared_mutex cache_mutex;
std::mutex cache_mutex;

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

Expand All@@ -39,12 +39,12 @@ struct file_cache {
}

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

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

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

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

boost::iterator_range<std::vector<server::response_header>::iterator> meta(
std::string const &path) {
boost::shared_lock<boost::shared_mutex> lock(cache_mutex);
std::unique_lock<std::mutex> lock(cache_mutex);
static std::vector<server::response_header> empty_vector;
auto headers = file_headers.find(doc_root_ + path);
if (headers != file_headers.end()) {
auto begin = headers->second
.begin(),
end =
headers->second.end();
auto begin = headers->second.begin(),
end = headers->second.end();
return boost::make_iterator_range(begin, end);
} else
return boost::make_iterator_range(empty_vector);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -167,7 +167,7 @@ int main() {
auto server(std::make_shared<server_data>(
server::options(request_handler)
.address("0.0.0.0")
.port("8800")
.port("8000")
.io_service(io_service)
.reuse_address(true)
.thread_pool(std::make_shared<boost::network::utils::thread_pool>(
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp