Boost logo

Boost Users :

Subject: [Boost-users] playing around with tutorial codes to understand ioservice
From: Ozgur Ozturk (ozgur7_at_[hidden])
Date: 2009-07-11 16:53:18


Hi,
     I have been working on asio from the online documentation for more than
a week but I am still confused about the io_service.
Especially about what happens when we pass io_service to so many other
things (timer, socket, chat_client etc.)?

I hoped playing around with the codes in tutorial may help me in
understanding.
I modified the code a bit from timer3.cpp
example<http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/tutorial/tuttimer3.html>.
(modified code is in attachment)

When I add another io_service object, I was thinking one would run then the
other one would start since in the comments of io_service.hpp it says
   * The run() function blocks until all work has finished and there are no
   * more handlers to be dispatched, or until the io_service has been
stopped.
but when I run two io_service objects
  io.run();
  io2.run();
I get output from two of them interchangingly. (first print in each line is
address of deadline timer, I added in print function to see which thread is
running.)

0012FF04 0
0012FEE4 1
0012FEE4 2
0012FEE4 3
0012FF04 4

Could someone help me understand io_service class?
(Maybe some pointers to old discussions could help.)
I also read some papers about Proactor pattern, without too much help.

Maybe example code can be supplied with more comments.

I would also appreciate suggestions and pointers (probably in private emails
to ozgur7 AT gmail com) to help me about implementing a simple command
server (proxy).
I am trying to implement a server to accept clients and run MySQL queries
(example: look up name and password pair in a table) and pass results to
clients.
I am using connector/C++ for MySQL part, and that part seems very easy.
However I am having difficulty in understanding asio. Do you think, I am
overkilling for such a simple thing.
(I thought it could pay back later when I needed to improve my program...)

Thanks in advance,
Best regards,
Ozgur (Oscar) Ozturk
www.DrOzgur.com
+1 (614) 805-4370





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