O'Reilly logo

Boost.Asio C++ Network Programming by John Torjo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Boost.Asio Windows features

The features that follow apply only to the Windows operating system.

Stream Handles

Boost.Asio allows you to create a wrapper over a Windows Handle, after which you can use most of the free functions, such as read(), read_until(), write(), async_read(), async_read_until(), and async_write(). Here's how to read a line from a file:

HANDLE file = ::CreateFile("readme.txt", GENERIC_READ, 0, 0, 
    OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 0);
windows::stream_handle h(service, file);
streambuf buf;
int bytes = read_until(h, buf, '\n');
std::istream in(&buf);
std::string line;
std::getline(in, line);
std::cout << line << std::endl;

The stream_handle class is available only when the I/O completion port backend is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required