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

Fix CMakeLists.txt for compilation on windows#345

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 1 commit intocpp-netlib:0.11-develfromcodemedic:0.11-devel
Dec 12, 2013
Merged
Show file tree
Hide file tree
Changes fromall commits
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
Fix CMakeLists.txt for compilation on windows
missing libraries for target hello_world_async_server_with_work_queue isnow added.also fixes the formatting error with using tabs instead of spaces, according tothe style guide (fix in hello_world_async_server_with_work_queue.cpp)
  • Loading branch information
@codemedic
codemedic committedDec 10, 2013
commit9ca0703be6e5e606fc27fa622d711ab3bcf25029
5 changes: 3 additions & 2 deletionslibs/network/example/CMakeLists.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -85,7 +85,8 @@ target_link_libraries(hello_world_async_server_with_work_queue
${BOOST_CLIENT_LIBS}
${CMAKE_THREAD_LIBS_INIT}
cppnetlib-uri
cppnetlib-client-connections)
cppnetlib-client-connections
cppnetlib-server-parsers)

if (OPENSSL_FOUND)
target_link_libraries(http_client${OPENSSL_LIBRARIES})
Expand All@@ -106,7 +107,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(twitter_search rt)
target_link_libraries(hello_world_server rt)
target_link_libraries(hello_world_client rt)
target_link_libraries(hello_world_async_server_with_work_queuecppnetlib-server-parsersrt)
target_link_libraries(hello_world_async_server_with_work_queue rt)
endif()

if (UNIX)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
#include<signal.h>

#defineLog(line) \
do { std::cout << line << std::endl; }while(false)
do { std::cout << line << std::endl; }while(false)

structhandler;
typedef boost::network::http::async_server<handler> server;
Expand All@@ -28,66 +28,66 @@ typedef boost::network::http::async_server<handler> server;
*/
structrequest_data
{
const server::request req;
server::connection_ptr conn;
const server::request req;
server::connection_ptr conn;

typedef boost::shared_ptr< request_data > pointer;
typedef boost::shared_ptr< request_data > pointer;

request_data(server::requestconst& req,const server::connection_ptr& conn) :
req(req), conn(conn)
{
}
request_data(server::requestconst& req,const server::connection_ptr& conn) :
req(req), conn(conn)
{
}
};

/**
* A basic work queue
*/
structwork_queue
{
typedef std::list<request_data::pointer> list;
typedef std::list<request_data::pointer> list;

list requests;
boost::mutex mutex;
list requests;
boost::mutex mutex;

inlinevoidput(const request_data::pointer& p_rd)
{
boost::unique_lock< boost::mutex >lock(mutex);
requests.push_back(p_rd);
(void)lock;
}
inlinevoidput(const request_data::pointer& p_rd)
{
boost::unique_lock< boost::mutex >lock(mutex);
requests.push_back(p_rd);
(void)lock;
}

inline request_data::pointerget()
{
boost::unique_lock< boost::mutex >lock(mutex);
inline request_data::pointerget()
{
boost::unique_lock< boost::mutex >lock(mutex);

request_data::pointer p_ret;
if (!requests.empty()) {
p_ret = requests.front();
requests.pop_front();
}
request_data::pointer p_ret;
if (!requests.empty()) {
p_ret = requests.front();
requests.pop_front();
}

(void)lock;
(void)lock;

return p_ret;
}
return p_ret;
}
};

structhandler
{
work_queue& queue;

handler(work_queue& queue) : queue(queue) { }

/**
* Feed the work queue
*
* @param req
* @param conn
*/
voidoperator()(server::requestconst& req,const server::connection_ptr& conn)
{
queue.put(boost::make_shared<request_data>(req, conn));
}
work_queue& queue;

handler(work_queue& queue) : queue(queue) { }

/**
* Feed the work queue
*
* @param req
* @param conn
*/
voidoperator()(server::requestconst& req,const server::connection_ptr& conn)
{
queue.put(boost::make_shared<request_data>(req, conn));
}
};

/**
Expand All@@ -98,11 +98,11 @@ struct handler
* @param p_server_instance
*/
voidshut_me_down(
const boost::system::error_code& error
,int signal, boost::shared_ptr< server > p_server_instance)
const boost::system::error_code& error
,int signal, boost::shared_ptr< server > p_server_instance)
{
if (!error)
p_server_instance->stop();
if (!error)
p_server_instance->stop();
}

/**
Expand All@@ -112,89 +112,89 @@ void shut_me_down(
*/
voidprocess_request(work_queue& queue)
{
while(!boost::this_thread::interruption_requested()) {
request_data::pointerp_req(queue.get());
if (p_req) {
while(!boost::this_thread::interruption_requested()) {
request_data::pointerp_req(queue.get());
if (p_req) {

// some heavy work!
boost::this_thread::sleep(boost::posix_time::seconds(10));
// some heavy work!
boost::this_thread::sleep(boost::posix_time::seconds(10));

p_req->conn->set_status(server::connection::ok);
p_req->conn->write("Hello, world!");
}
p_req->conn->set_status(server::connection::ok);
p_req->conn->write("Hello, world!");
}

boost::this_thread::sleep(boost::posix_time::microseconds(1000));
}
boost::this_thread::sleep(boost::posix_time::microseconds(1000));
}
}

intmain(void) try
{
// the thread group
boost::shared_ptr< boost::thread_group >p_threads(
boost::make_shared< boost::thread_group>());

// setup asio::io_service
boost::shared_ptr< boost::asio::io_service >p_io_service(
boost::make_shared< boost::asio::io_service >());
boost::shared_ptr< boost::asio::io_service::work >p_work(
boost::make_shared< boost::asio::io_service::work >(
boost::ref(*p_io_service)));

// io_service threads
{
int n_threads =5;
while(0 < n_threads--) {
p_threads->create_thread(
boost::bind(&boost::asio::io_service::run, p_io_service));
}
}

// the shared work queue
work_queue queue;

// worker threads that will process the request; off the queue
{
int n_threads =5;
while(0 < n_threads--) {
p_threads->create_thread(
boost::bind(process_request,boost::ref(queue)));
}
}

// setup the async server
handlerrequest_handler(queue);
boost::shared_ptr< server >p_server_instance(
boost::make_shared<server>(
server::options(request_handler).
address("0.0.0.0")
.port("8800")
.io_service(p_io_service)
.reuse_address(true)
.thread_pool(
boost::make_shared<boost::network::utils::thread_pool>(
2 , p_io_service, p_threads))));

// setup clean shutdown
boost::asio::signal_setsignals(*p_io_service, SIGINT, SIGTERM);
signals.async_wait(boost::bind(shut_me_down, _1, _2, p_server_instance));

// run the async server
p_server_instance->run();

// we are stopped - shutting down

p_threads->interrupt_all();

p_work.reset();
p_io_service->stop();

p_threads->join_all();

Log("Terminated normally");
exit(EXIT_SUCCESS);
// the thread group
boost::shared_ptr< boost::thread_group >p_threads(
boost::make_shared< boost::thread_group>());

// setup asio::io_service
boost::shared_ptr< boost::asio::io_service >p_io_service(
boost::make_shared< boost::asio::io_service >());
boost::shared_ptr< boost::asio::io_service::work >p_work(
boost::make_shared< boost::asio::io_service::work >(
boost::ref(*p_io_service)));

// io_service threads
{
int n_threads =5;
while(0 < n_threads--) {
p_threads->create_thread(
boost::bind(&boost::asio::io_service::run, p_io_service));
}
}

// the shared work queue
work_queue queue;

// worker threads that will process the request; off the queue
{
int n_threads =5;
while(0 < n_threads--) {
p_threads->create_thread(
boost::bind(process_request,boost::ref(queue)));
}
}

// setup the async server
handlerrequest_handler(queue);
boost::shared_ptr< server >p_server_instance(
boost::make_shared<server>(
server::options(request_handler).
address("0.0.0.0")
.port("8800")
.io_service(p_io_service)
.reuse_address(true)
.thread_pool(
boost::make_shared<boost::network::utils::thread_pool>(
2 , p_io_service, p_threads))));

// setup clean shutdown
boost::asio::signal_setsignals(*p_io_service, SIGINT, SIGTERM);
signals.async_wait(boost::bind(shut_me_down, _1, _2, p_server_instance));

// run the async server
p_server_instance->run();

// we are stopped - shutting down

p_threads->interrupt_all();

p_work.reset();
p_io_service->stop();

p_threads->join_all();

Log("Terminated normally");
exit(EXIT_SUCCESS);
}
catch(const std::exception& e)
{
Log("Abnormal termination - exception:"<<e.what());
exit(EXIT_FAILURE);
Log("Abnormal termination - exception:"<<e.what());
exit(EXIT_FAILURE);
}

[8]ページ先頭

©2009-2025 Movatter.jp