Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Commit

Permalink
issue #1 use a boost::asio::io_service::work object to keep the io_se…
Browse files Browse the repository at this point in the history
…rvice::run loop alive
  • Loading branch information
Cylix committed Nov 15, 2015
1 parent b96dd15 commit f08d987
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/redis_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <signal.h>
#include <iostream>

bool should_exit = false;
volatile std::atomic_bool should_exit(false);
cpp_redis::redis_client client;

void
Expand Down
3 changes: 2 additions & 1 deletion includes/cpp_redis/network/io_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace network {
class io_service {
public:
//! ctor & dtor
io_service(void) = default;
io_service(void);
~io_service(void);

//! copy ctor & assignment operator
Expand All @@ -28,6 +28,7 @@ class io_service {

private:
boost::asio::io_service m_io_service;
boost::asio::io_service::work m_work;
std::thread m_io_service_thread;
};

Expand Down
7 changes: 6 additions & 1 deletion sources/network/io_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ namespace cpp_redis {

namespace network {

io_service::io_service(void)
: m_work(m_io_service) {}

io_service::~io_service(void) {
if (m_io_service_thread.joinable())
if (m_io_service_thread.joinable()) {
m_io_service.stop();
m_io_service_thread.join();
}
}

void
Expand Down

0 comments on commit f08d987

Please sign in to comment.