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

Understanding the Boost.Bind library


We have been able to use the io_service object and initialize the work object. What we should know after this is how to give some work to the io_service object. But before we progress to giving work to the io_service service, we need to understand the boost::bind library.

The Boost.Bind library is used to ease the invocation of a function pointer. It converts the syntax from something that is abstruse and confusing to something that is easy to understand.

Wrapping a function invocation

Let's look at the following code in order to understand how to wrap a function invocation:

/* uncalledbind.cpp */
#include <boost/bind.hpp>
#include <iostream>

void func() {
  std::cout << "Binding Function" << std::endl;
}

int main(void) {
  boost::bind(&func);
  return 0;
}

Save the preceding code as uncalledbind.cpp and then compile it using the following command:

g++ -Wall -ansi -I ../boost_1_58_0 uncalledbind.cpp -o uncalledbind

We will not...