|
Boost Users : |
Subject: [Boost-users] [boost::asio] how should I use accept and io_service?
From: Shenyu Yao (yaoxx123_at_[hidden])
Date: 2013-04-08 10:46:16
Hi guys, this is my first post to this mail list. Forgive my noob
questions, I am new to boost.
I have read some documentations but still dont understand how io_service
works.
My problem is that I need two functions in my server class, listen() and
handle()
listen() is to accept all incoming connections and bind them with a handler
function which accept a socket as argument.
and handler will simply call io_service.run()
=========================
class Server
{
io_service IOService;
std::vector<boost:: ... :: socket> SocketVector;
listen()
{
//blocking accept all incoming connection and bind socket with
handleSocket
}
HandleRequest()
{
//io_service.run();
}
}
============================
handleSocket(*Socket)
{
//handleSocket;
}
==============================
main()
{
boost::thread t1(&Server::listen, &myServer);
boost::thread t2(&Server::HandleRequest, &myServer);
}
====================================
my understanding is that
everytime you instantiate a new socket object with a constructor including
a io_service object, this socket object is associated with the io_service
object, since I only have one io_service object, these socket object will
be executed when I call io_service.run()but, the question is, how do i
assign handle_function to those socket, I saw people use
acceptor.async_accept(socket, boost::bind(handler, &socket)) like this, But
I want to use accept rather than async_accept(), but the accept() function
cant be used to bind a handler function to this socket
Thank you
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net