Book Image

Boost.Asio C++ Network Programming

By : Wisnu Anggoro
Book Image

Boost.Asio C++ Network Programming

By: Wisnu Anggoro

Overview of this book

Table of Contents (15 chapters)
Boost.Asio C++ Network Programming Second Edition
Credits
About the Authors
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

Giving some work to the I/O service


Now, it is time for us to give some work to the io_service object. Knowing more about boost::bind and boost::mutex will help us to give the io_service object work to do. There are two member functions in the io_service object: the post() and dispatch() functions, which we will frequently use to do this. The post() function is used to request the io_service object to run the io_service object's work after we queue up all the work, so it does not allow us to run the work immediately. While the dispatch() function is also used to make a request to the io_service object to run the io_service object's work, but it will execute the work right away without queuing it up.

Using the post() function

Let's examine the post() function by creating the following code. We will use the mutexbind.cpp file as our base code, since we will just modify the source code:

/* post.cpp */
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread...