简体   繁体   中英

boost.asio multi-thread I/O server with async_read

The basic logic is as follows

main_thread:

for(;;) {
accept socket
async_read head(length of packet),binded to head_handler
io_service.run() }

head_handler(non-thread):

async_read body(using length read from head) ,binded to body_handler

body_handler(non-thread):

parse message into Request objects (custom class).
push Request to request_pool

read_thread:

for(;;) {
if request_pool not empty (lock otherwise) { perform actions described by the Request } }

So I have a simple echo server using above logics. It prints out whatever messages passed in.However, only the first message will be displayed, all others will have "xxx.xxx.xxx.xxx connected" message printed out correctly.But no messages are printed

If you do not issue any async. operation in body_handler , io_service runs out of work and io_service::run() exits. Before any subsequent call to io_service::run() you have to call io_service::reset() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM