diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-09-17 22:50:47 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-09-17 22:50:47 +0100 |
| commit | 1e8f1be709e8a3fa58f1147db2e58a39396313d8 (patch) | |
| tree | 1f86e375afbc1ec2a7e81ad48594bef7542bf71d /src/lib/server.h | |
| parent | d7135bda7b1db2ee2728c90ff4570c350834338f (diff) | |
Move server code into library; Server -> ServerDescription.
Diffstat (limited to 'src/lib/server.h')
| -rw-r--r-- | src/lib/server.h | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/lib/server.h b/src/lib/server.h index d06df34e9..8c0f86ebb 100644 --- a/src/lib/server.h +++ b/src/lib/server.h @@ -19,21 +19,25 @@ /** @file src/server.h * @brief Class to describe a server to which we can send - * encoding work. + * encoding work, and a class to implement such a server. */ #include <string> +#include <boost/thread.hpp> +#include <boost/asio.hpp> +#include <boost/thread/condition.hpp> +#include "log.h" -/** @class Server +/** @class ServerDescription * @brief Class to describe a server to which we can send encoding work. */ -class Server +class ServerDescription { public: /** @param h Server host name or IP address in string form. * @param t Number of threads to use on the server. */ - Server (std::string h, int t) + ServerDescription (std::string h, int t) : _host_name (h) , _threads (t) {} @@ -58,7 +62,7 @@ public: std::string as_metadata () const; - static Server * create_from_metadata (std::string v); + static ServerDescription * create_from_metadata (std::string v); private: /** server's host name */ @@ -66,3 +70,21 @@ private: /** number of threads to use on the server */ int _threads; }; + +class Server +{ +public: + Server (); + + void run (); + +private: + void worker_thread (); + int process (boost::shared_ptr<boost::asio::ip::tcp::socket> socket); + + std::vector<boost::thread *> _worker_threads; + std::list<boost::shared_ptr<boost::asio::ip::tcp::socket> > _queue; + boost::mutex _worker_mutex; + boost::condition _worker_condition; + Log _log; +}; |
