boost的官方例子,有單執行緒的網路框架,httpserver2是執行緒池的。下面參照網上某人的**修改了一點(忘了哪位大仙的**了)
測試工具,適用stressmark,測試效果非常好, 9000個/s
#
include
#include
"authenhandle.h"
#include
"configure.h"
#ifdef win32 //for windows nt/2000/xp
#include
#include
#include
"gelsserver.h"
#pragma comment(lib,
"ws2_32.lib")#
else
//for unix
#include
socket
.h>
// #include
// #include
// #include
#include
//socket
// #include
#include
//gethostname
// #include
#include
#include
<
string
.h>
//memset
typedef
intsocket
;typedef
struct
sockaddr_in
sockaddr_in
;typedef
struct
sockaddr
sockaddr;#
ifdef m_i386
typedef
intsocklen_t;#
endif
#define
bool
int#
define invalid_socket -1
#define socket_error -1
#define
true 1
#define
false 0
#endif
//end #ifdef win32
static
int count111 = 0;
static
time_t oldtime = 0, nowtime = 0;
#include
#include
<
iostream
>
#include
#include
bind
.hpp>
#include
#include
#include
using
namespace
std;
using boost:
:asio:
:ip:
:tcp;
class io_service_pool
:public boost:
:noncopyable
}void start()}
void join()}
void stop()}
boost:
:asio:
:io_service& get_io_service(
)return io_service;
}private
:typedef boost:
:shared_ptr:asio:
:io_service> io_service_sptr;
typedef boost:
:shared_ptr:asio:
:io_service:
:work> work_sptr;
typedef boost:
:shared_ptr:thread> thread_sptr;
boost:
:mutex mtx;
std:
:vector
io_services_;
std:
:vector
work_;
std:
:vector
threads_;
std:
:size_t next_io_service_;};
boost:
:mutex cout_mtx;
int packet_size = 0;
enum
;class session
virtual
~session(
)tcp:
:socket
&socket()
inline
void start(
)void handle_read(
const boost:
:system
::error_code&
error
,size_t bytes_transferred)
boost:
:asio:
:async_write(socket_, boost:
:asio:
:buffer(data_, bytes_transferred)
,boost:
:bind
(&session:
:handle_write,
this
, boost:
:asio:
:placeholders:
:error))
;}else
}void handle_write(
const boost:
:system
::error_code&
error
)else
}private
:tcp:
:socket socket_;
char data_[max_packet_len]
;int recv_times;};
class server
void handle_accept(session* new_session,
const boost:
:system
::error_code&
error
)else
new_session =
new session(io_service_pool_.get_io_service())
;acceptor_.async_accept(new_session-
>
socket()
,boost:
:bind
(&server:
:handle_accept,
this
, new_session, boost:
:asio:
:placeholders:
:error))
;}void run(
)private
:io_service_pool io_service_pool_;
tcp:
:acceptor acceptor_;};
int main(
)return 0;
}
boost高併發網路框架 執行緒池
boost的官方例子,有單執行緒的網路框架,httpserver2是執行緒池的。下面參照網上某人的 修改了一點 忘了哪位大仙的 了 測試工具,適用stressmark,測試效果非常好,9000個 s include include authenhandle.h include configure.h...
boost高併發網路框架 執行緒池
from 有幾個地方改了下,要不編譯不過 include include authenhandle.h 與原來的不同 include configure.h 與原來的不同 ifdef win32 for windows nt 2000 xp include include 需要在stdafx.h 檔...
Quartz定時任務框架執行緒池
springboot使用 enablescheduling註解開啟定時任務功能後,預設建立乙個固定執行緒數為1的執行緒池給定時任務框架呼叫執行定時任務。當多個任務同時執行時,會導致多個任務競爭執行執行緒,當上乙個任務執行完畢後,執行緒才會被釋放出來用於其他任務的執行。導致定時任務延時執行。因此需要建...