forked from LiXizhi/TMInterface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.hpp
More file actions
74 lines (60 loc) · 1.92 KB
/
Copy pathqueue.hpp
File metadata and controls
74 lines (60 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// server.hpp
// ~~~~~~~~~~
//
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef QUEUE_HPP
#define QUEUE_HPP
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <string>
#include <vector>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include "connection.hpp"
#include "TMService.hpp"
#define THREADS_POOL_COUNT 10
///queue class.
class queue
: private boost::noncopyable
{
public:
static queue& Instance()
{
static queue instanceQueue(THREADS_POOL_COUNT);
if(!instanceQueue.isRunning)
{
instanceQueue.isRunning = true;
instanceQueue.run();
instanceQueue.iWorkingSocketCount = 0;
}
return instanceQueue;
}
/// Construct the server to listen on the specified TCP address and port, and
/// serve up files from the given directory.
explicit queue(std::size_t thread_pool_size);
void start();
/// Run the server's io_service loop.
void run();
/// Stop the server.
void stop();
void handle_request(const std::string& server,const std::string& port,const char * sendbuf,int iOutLength,int iProxyFlag,const char* sMsg, int iMsgLength);
bool isRunning;
int iWorkingSocketCount;
boost::mutex m_QueueCountMutex;
private:
/// The number of threads that will call io_service::run().
std::size_t thread_pool_size_;
/// The io_service used to perform asynchronous operations.
boost::asio::io_service io_service_;
/** Work for the private m_io_service_dispatcher to perform. If we do not give the
io_service some work to do then the io_service::run() function will exit immediately.*/
boost::scoped_ptr<boost::asio::io_service::work> m_work_lifetime;
};
#endif // QUEUE_HPP