Adds asio library and Storage Module

This commit is contained in:
Suraxius committed 2020-12-01 22:41:04 +01:00
1 parent 79a6ee5779
commit 30439acd43
4869 files changed
+618801 -903

No files matched your search

@@ -0,0 +1,546 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>The BSD Socket API and Asio</title>
<link rel="stylesheet" href="../../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../../index.html" title="Asio">
<link rel="up" href="../networking.html" title="Networking">
<link rel="prev" href="iostreams.html" title="Socket Iostreams">
<link rel="next" href="../timers.html" title="Timers">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="asio C++ library" width="250" height="60" src="../../../asio.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="iostreams.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../networking.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="../timers.html"><img src="../../../next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="asio.overview.networking.bsd_sockets"></a><a class="link" href="bsd_sockets.html" title="The BSD Socket API and Asio">The BSD Socket
API and Asio</a>
</h4></div></div></div>
<p>
The Asio library includes a low-level socket interface based on the BSD
socket API, which is widely implemented and supported by extensive literature.
It is also used as the basis for networking APIs in other languages, like
Java. This low-level interface is designed to support the development of
efficient and scalable applications. For example, it permits programmers
to exert finer control over the number of system calls, avoid redundant
data copying, minimise the use of resources like threads, and so on.
</p>
<p>
Unsafe and error prone aspects of the BSD socket API are not included.
For example, the use of <code class="computeroutput">int</code> to represent all sockets lacks
type safety. The socket representation in Asio uses a distinct type for
each protocol, e.g. for TCP one would use <code class="computeroutput">ip::tcp::socket</code>,
and for UDP one uses <code class="computeroutput">ip::udp::socket</code>.
</p>
<p>
The following table shows the mapping between the BSD socket API and Asio:
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
BSD Socket API Elements
</p>
</th>
<th>
<p>
Equivalents in Asio
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
socket descriptor - <code class="computeroutput">int</code> (POSIX) or <code class="computeroutput">SOCKET</code>
(Windows)
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/ip__tcp/socket.html" title="ip::tcp::socket">ip::tcp::socket</a>,
<a class="link" href="../../reference/ip__tcp/acceptor.html" title="ip::tcp::acceptor">ip::tcp::acceptor</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/ip__udp/socket.html" title="ip::udp::socket">ip::udp::socket</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket.html" title="basic_socket">basic_socket</a>,
<a class="link" href="../../reference/basic_stream_socket.html" title="basic_stream_socket">basic_stream_socket</a>,
<a class="link" href="../../reference/basic_datagram_socket.html" title="basic_datagram_socket">basic_datagram_socket</a>,
<a class="link" href="../../reference/basic_raw_socket.html" title="basic_raw_socket">basic_raw_socket</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">in_addr</code>, <code class="computeroutput">in6_addr</code>
</p>
</td>
<td>
<p>
<a class="link" href="../../reference/ip__address.html" title="ip::address">ip::address</a>,
<a class="link" href="../../reference/ip__address.html" title="ip::address">ip::address_v4</a>,
<a class="link" href="../../reference/ip__address.html" title="ip::address">ip::address_v6</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">sockaddr_in</code>, <code class="computeroutput">sockaddr_in6</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/ip__tcp/endpoint.html" title="ip::tcp::endpoint">ip::tcp::endpoint</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/ip__udp/endpoint.html" title="ip::udp::endpoint">ip::udp::endpoint</a>
</p>
<p>
<a class="link" href="../../reference/ip__basic_endpoint.html" title="ip::basic_endpoint">ip::basic_endpoint</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">accept()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket_acceptor/accept.html" title="basic_socket_acceptor::accept">ip::tcp::acceptor::accept()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket_acceptor/accept.html" title="basic_socket_acceptor::accept">basic_socket_acceptor::accept()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">bind()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/bind.html" title="basic_socket::bind">ip::tcp::acceptor::bind()</a>,
<a class="link" href="../../reference/basic_socket/bind.html" title="basic_socket::bind">ip::tcp::socket::bind()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_socket/bind.html" title="basic_socket::bind">ip::udp::socket::bind()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/bind.html" title="basic_socket::bind">basic_socket::bind()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">close()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/close.html" title="basic_socket::close">ip::tcp::acceptor::close()</a>,
<a class="link" href="../../reference/basic_socket/close.html" title="basic_socket::close">ip::tcp::socket::close()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_socket/close.html" title="basic_socket::close">ip::udp::socket::close()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/close.html" title="basic_socket::close">basic_socket::close()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">connect()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/connect.html" title="basic_socket::connect">ip::tcp::socket::connect()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_socket/connect.html" title="basic_socket::connect">ip::udp::socket::connect()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/connect.html" title="basic_socket::connect">basic_socket::connect()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">getaddrinfo()</code>, <code class="computeroutput">gethostbyaddr()</code>, <code class="computeroutput">gethostbyname()</code>,
<code class="computeroutput">getnameinfo()</code>, <code class="computeroutput">getservbyname()</code>, <code class="computeroutput">getservbyport()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/ip__basic_resolver/resolve.html" title="ip::basic_resolver::resolve">ip::tcp::resolver::resolve()</a>,
<a class="link" href="../../reference/ip__basic_resolver/async_resolve.html" title="ip::basic_resolver::async_resolve">ip::tcp::resolver::async_resolve()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/ip__basic_resolver/resolve.html" title="ip::basic_resolver::resolve">ip::udp::resolver::resolve()</a>,
<a class="link" href="../../reference/ip__basic_resolver/async_resolve.html" title="ip::basic_resolver::async_resolve">ip::udp::resolver::async_resolve()</a>
</p>
<p>
<a class="link" href="../../reference/ip__basic_resolver/resolve.html" title="ip::basic_resolver::resolve">ip::basic_resolver::resolve()</a>,
<a class="link" href="../../reference/ip__basic_resolver/async_resolve.html" title="ip::basic_resolver::async_resolve">ip::basic_resolver::async_resolve()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">gethostname()</code>
</p>
</td>
<td>
<p>
<a class="link" href="../../reference/ip__host_name.html" title="ip::host_name">ip::host_name()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">getpeername()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/remote_endpoint.html" title="basic_socket::remote_endpoint">ip::tcp::socket::remote_endpoint()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_socket/remote_endpoint.html" title="basic_socket::remote_endpoint">ip::udp::socket::remote_endpoint()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/remote_endpoint.html" title="basic_socket::remote_endpoint">basic_socket::remote_endpoint()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">getsockname()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/local_endpoint.html" title="basic_socket::local_endpoint">ip::tcp::acceptor::local_endpoint()</a>,
<a class="link" href="../../reference/basic_socket/local_endpoint.html" title="basic_socket::local_endpoint">ip::tcp::socket::local_endpoint()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_socket/local_endpoint.html" title="basic_socket::local_endpoint">ip::udp::socket::local_endpoint()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/local_endpoint.html" title="basic_socket::local_endpoint">basic_socket::local_endpoint()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">getsockopt()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/get_option.html" title="basic_socket::get_option">ip::tcp::acceptor::get_option()</a>,
<a class="link" href="../../reference/basic_socket/get_option.html" title="basic_socket::get_option">ip::tcp::socket::get_option()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_socket/get_option.html" title="basic_socket::get_option">ip::udp::socket::get_option()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/get_option.html" title="basic_socket::get_option">basic_socket::get_option()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">inet_addr()</code>, <code class="computeroutput">inet_aton()</code>, <code class="computeroutput">inet_pton()</code>
</p>
</td>
<td>
<p>
<a class="link" href="../../reference/ip__address/from_string.html" title="ip::address::from_string">ip::address::from_string()</a>,
<a class="link" href="../../reference/ip__address/from_string.html" title="ip::address::from_string">ip::address_v4::from_string()</a>,
<a class="link" href="../../reference/ip__address/from_string.html" title="ip::address::from_string">ip_address_v6::from_string()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">inet_ntoa()</code>, <code class="computeroutput">inet_ntop()</code>
</p>
</td>
<td>
<p>
<a class="link" href="../../reference/ip__address/to_string.html" title="ip::address::to_string">ip::address::to_string()</a>,
<a class="link" href="../../reference/ip__address/to_string.html" title="ip::address::to_string">ip::address_v4::to_string()</a>,
<a class="link" href="../../reference/ip__address/to_string.html" title="ip::address::to_string">ip_address_v6::to_string()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">ioctl()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/io_control.html" title="basic_socket::io_control">ip::tcp::socket::io_control()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_socket/io_control.html" title="basic_socket::io_control">ip::udp::socket::io_control()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/io_control.html" title="basic_socket::io_control">basic_socket::io_control()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">listen()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket_acceptor/listen.html" title="basic_socket_acceptor::listen">ip::tcp::acceptor::listen()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket_acceptor/listen.html" title="basic_socket_acceptor::listen">basic_socket_acceptor::listen()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">poll()</code>, <code class="computeroutput">select()</code>, <code class="computeroutput">pselect()</code>
</p>
</td>
<td>
<p>
<a class="link" href="../../reference/io_context/run.html" title="io_context::run">io_context::run()</a>,
<a class="link" href="../../reference/io_context/run_one.html" title="io_context::run_one">io_context::run_one()</a>,
<a class="link" href="../../reference/io_context/poll.html" title="io_context::poll">io_context::poll()</a>,
<a class="link" href="../../reference/io_context/poll_one.html" title="io_context::poll_one">io_context::poll_one()</a>
</p>
<p>
Note: in conjunction with asynchronous operations.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">readv()</code>, <code class="computeroutput">recv()</code>, <code class="computeroutput">read()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_stream_socket/read_some.html" title="basic_stream_socket::read_some">ip::tcp::socket::read_some()</a>,
<a class="link" href="../../reference/basic_stream_socket/async_read_some.html" title="basic_stream_socket::async_read_some">ip::tcp::socket::async_read_some()</a>,
<a class="link" href="../../reference/basic_stream_socket/receive.html" title="basic_stream_socket::receive">ip::tcp::socket::receive()</a>,
<a class="link" href="../../reference/basic_stream_socket/async_receive.html" title="basic_stream_socket::async_receive">ip::tcp::socket::async_receive()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_datagram_socket/receive.html" title="basic_datagram_socket::receive">ip::udp::socket::receive()</a>,
<a class="link" href="../../reference/basic_datagram_socket/async_receive.html" title="basic_datagram_socket::async_receive">ip::udp::socket::async_receive()</a>
</p>
<p>
<a class="link" href="../../reference/basic_stream_socket/read_some.html" title="basic_stream_socket::read_some">basic_stream_socket::read_some()</a>,
<a class="link" href="../../reference/basic_stream_socket/async_read_some.html" title="basic_stream_socket::async_read_some">basic_stream_socket::async_read_some()</a>,
<a class="link" href="../../reference/basic_stream_socket/receive.html" title="basic_stream_socket::receive">basic_stream_socket::receive()</a>,
<a class="link" href="../../reference/basic_stream_socket/async_receive.html" title="basic_stream_socket::async_receive">basic_stream_socket::async_receive()</a>,
<a class="link" href="../../reference/basic_datagram_socket/receive.html" title="basic_datagram_socket::receive">basic_datagram_socket::receive()</a>,
<a class="link" href="../../reference/basic_datagram_socket/async_receive.html" title="basic_datagram_socket::async_receive">basic_datagram_socket::async_receive()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">recvfrom()</code>
</p>
</td>
<td>
<p>
For UDP: <a class="link" href="../../reference/basic_datagram_socket/receive_from.html" title="basic_datagram_socket::receive_from">ip::udp::socket::receive_from()</a>,
<a class="link" href="../../reference/basic_datagram_socket/async_receive_from.html" title="basic_datagram_socket::async_receive_from">ip::udp::socket::async_receive_from()</a>
</p>
<p>
<a class="link" href="../../reference/basic_datagram_socket/receive_from.html" title="basic_datagram_socket::receive_from">basic_datagram_socket::receive_from()</a>,
<a class="link" href="../../reference/basic_datagram_socket/async_receive_from.html" title="basic_datagram_socket::async_receive_from">basic_datagram_socket::async_receive_from()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">send()</code>, <code class="computeroutput">write()</code>, <code class="computeroutput">writev()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_stream_socket/write_some.html" title="basic_stream_socket::write_some">ip::tcp::socket::write_some()</a>,
<a class="link" href="../../reference/basic_stream_socket/async_write_some.html" title="basic_stream_socket::async_write_some">ip::tcp::socket::async_write_some()</a>,
<a class="link" href="../../reference/basic_stream_socket/send.html" title="basic_stream_socket::send">ip::tcp::socket::send()</a>,
<a class="link" href="../../reference/basic_stream_socket/async_send.html" title="basic_stream_socket::async_send">ip::tcp::socket::async_send()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_datagram_socket/send.html" title="basic_datagram_socket::send">ip::udp::socket::send()</a>,
<a class="link" href="../../reference/basic_datagram_socket/async_send.html" title="basic_datagram_socket::async_send">ip::udp::socket::async_send()</a>
</p>
<p>
<a class="link" href="../../reference/basic_stream_socket/write_some.html" title="basic_stream_socket::write_some">basic_stream_socket::write_some()</a>,
<a class="link" href="../../reference/basic_stream_socket/async_write_some.html" title="basic_stream_socket::async_write_some">basic_stream_socket::async_write_some()</a>,
<a class="link" href="../../reference/basic_stream_socket/send.html" title="basic_stream_socket::send">basic_stream_socket::send()</a>,
<a class="link" href="../../reference/basic_stream_socket/async_send.html" title="basic_stream_socket::async_send">basic_stream_socket::async_send()</a>,
<a class="link" href="../../reference/basic_datagram_socket/send.html" title="basic_datagram_socket::send">basic_datagram_socket::send()</a>,
<a class="link" href="../../reference/basic_datagram_socket/async_send.html" title="basic_datagram_socket::async_send">basic_datagram_socket::async_send()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">sendto()</code>
</p>
</td>
<td>
<p>
For UDP: <a class="link" href="../../reference/basic_datagram_socket/send_to.html" title="basic_datagram_socket::send_to">ip::udp::socket::send_to()</a>,
<a class="link" href="../../reference/basic_datagram_socket/async_send_to.html" title="basic_datagram_socket::async_send_to">ip::udp::socket::async_send_to()</a>
</p>
<p>
<a class="link" href="../../reference/basic_datagram_socket/send_to.html" title="basic_datagram_socket::send_to">basic_datagram_socket::send_to()</a>,
<a class="link" href="../../reference/basic_datagram_socket/async_send_to.html" title="basic_datagram_socket::async_send_to">basic_datagram_socket::async_send_to()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">setsockopt()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/set_option.html" title="basic_socket::set_option">ip::tcp::acceptor::set_option()</a>,
<a class="link" href="../../reference/basic_socket/set_option.html" title="basic_socket::set_option">ip::tcp::socket::set_option()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_socket/set_option.html" title="basic_socket::set_option">ip::udp::socket::set_option()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/set_option.html" title="basic_socket::set_option">basic_socket::set_option()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">shutdown()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/shutdown.html" title="basic_socket::shutdown">ip::tcp::socket::shutdown()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_socket/shutdown.html" title="basic_socket::shutdown">ip::udp::socket::shutdown()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/shutdown.html" title="basic_socket::shutdown">basic_socket::shutdown()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">sockatmark()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/at_mark.html" title="basic_socket::at_mark">ip::tcp::socket::at_mark()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/at_mark.html" title="basic_socket::at_mark">basic_socket::at_mark()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">socket()</code>
</p>
</td>
<td>
<p>
For TCP: <a class="link" href="../../reference/basic_socket/open.html" title="basic_socket::open">ip::tcp::acceptor::open()</a>,
<a class="link" href="../../reference/basic_socket/open.html" title="basic_socket::open">ip::tcp::socket::open()</a>
</p>
<p>
For UDP: <a class="link" href="../../reference/basic_socket/open.html" title="basic_socket::open">ip::udp::socket::open()</a>
</p>
<p>
<a class="link" href="../../reference/basic_socket/open.html" title="basic_socket::open">basic_socket::open()</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput">socketpair()</code>
</p>
</td>
<td>
<p>
<a class="link" href="../../reference/local__connect_pair.html" title="local::connect_pair">local::connect_pair()</a>
</p>
<p>
Note: POSIX operating systems only.
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
Kohlhoff<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="iostreams.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../networking.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="../timers.html"><img src="../../../next.png" alt="Next"></a>
</div>
</body>
</html>
@@ -0,0 +1,112 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Socket Iostreams</title>
<link rel="stylesheet" href="../../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../../index.html" title="Asio">
<link rel="up" href="../networking.html" title="Networking">
<link rel="prev" href="other_protocols.html" title="Support for Other Protocols">
<link rel="next" href="bsd_sockets.html" title="The BSD Socket API and Asio">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="asio C++ library" width="250" height="60" src="../../../asio.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="other_protocols.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../networking.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="bsd_sockets.html"><img src="../../../next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="asio.overview.networking.iostreams"></a><a class="link" href="iostreams.html" title="Socket Iostreams">Socket Iostreams</a>
</h4></div></div></div>
<p>
Asio includes classes that implement iostreams on top of sockets. These
hide away the complexities associated with endpoint resolution, protocol
independence, etc. To create a connection one might simply write:
</p>
<pre class="programlisting">ip::tcp::iostream stream("www.boost.org", "http");
if (!stream)
{
// Can't connect.
}
</pre>
<p>
The iostream class can also be used in conjunction with an acceptor to
create simple servers. For example:
</p>
<pre class="programlisting">io_context ioc;
ip::tcp::endpoint endpoint(tcp::v4(), 80);
ip::tcp::acceptor acceptor(ios, endpoint);
for (;;)
{
ip::tcp::iostream stream;
acceptor.accept(stream.socket());
...
}
</pre>
<p>
Timeouts may be set by calling <code class="computeroutput">expires_at()</code> or <code class="computeroutput">expires_from_now()</code>
to establish a deadline. Any socket operations that occur past the deadline
will put the iostream into a "bad" state.
</p>
<p>
For example, a simple client program like this:
</p>
<pre class="programlisting">ip::tcp::iostream stream;
stream.expires_from_now(boost::posix_time::seconds(60));
stream.connect("www.boost.org", "http");
stream &lt;&lt; "GET /LICENSE_1_0.txt HTTP/1.0\r\n";
stream &lt;&lt; "Host: www.boost.org\r\n";
stream &lt;&lt; "Accept: */*\r\n";
stream &lt;&lt; "Connection: close\r\n\r\n";
stream.flush();
std::cout &lt;&lt; stream.rdbuf();
</pre>
<p>
will fail if all the socket operations combined take longer than 60 seconds.
</p>
<p>
If an error does occur, the iostream's <code class="computeroutput">error()</code> member function
may be used to retrieve the error code from the most recent system call:
</p>
<pre class="programlisting">if (!stream)
{
std::cout &lt;&lt; "Error: " &lt;&lt; stream.error().message() &lt;&lt; "\n";
}
</pre>
<h6>
<a name="asio.overview.networking.iostreams.h0"></a>
<span><a name="asio.overview.networking.iostreams.see_also"></a></span><a class="link" href="iostreams.html#asio.overview.networking.iostreams.see_also">See
Also</a>
</h6>
<p>
<a class="link" href="../../reference/ip__tcp/iostream.html" title="ip::tcp::iostream">ip::tcp::iostream</a>,
<a class="link" href="../../reference/basic_socket_iostream.html" title="basic_socket_iostream">basic_socket_iostream</a>,
<a class="link" href="../../examples/cpp03_examples.html#asio.examples.cpp03_examples.iostreams">iostreams examples</a>.
</p>
<h6>
<a name="asio.overview.networking.iostreams.h1"></a>
<span><a name="asio.overview.networking.iostreams.notes"></a></span><a class="link" href="iostreams.html#asio.overview.networking.iostreams.notes">Notes</a>
</h6>
<p>
These iostream templates only support <code class="computeroutput">char</code>, not <code class="computeroutput">wchar_t</code>,
and do not perform any code conversion.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
Kohlhoff<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="other_protocols.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../networking.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="bsd_sockets.html"><img src="../../../next.png" alt="Next"></a>
</div>
</body>
</html>
@@ -0,0 +1,152 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Support for Other Protocols</title>
<link rel="stylesheet" href="../../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../../index.html" title="Asio">
<link rel="up" href="../networking.html" title="Networking">
<link rel="prev" href="protocols.html" title="TCP, UDP and ICMP">
<link rel="next" href="iostreams.html" title="Socket Iostreams">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="asio C++ library" width="250" height="60" src="../../../asio.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="protocols.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../networking.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="iostreams.html"><img src="../../../next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="asio.overview.networking.other_protocols"></a><a class="link" href="other_protocols.html" title="Support for Other Protocols">Support for
Other Protocols</a>
</h4></div></div></div>
<p>
Support for other socket protocols (such as Bluetooth or IRCOMM sockets)
can be added by implementing the <a class="link" href="../../reference/Protocol.html" title="Protocol requirements">protocol
type requirements</a>. However, in many cases these protocols may also
be used with Asio's generic protocol support. For this, Asio provides the
following four classes:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<a class="link" href="../../reference/generic__datagram_protocol.html" title="generic::datagram_protocol"><code class="computeroutput">generic::datagram_protocol</code></a>
</li>
<li class="listitem">
<a class="link" href="../../reference/generic__raw_protocol.html" title="generic::raw_protocol"><code class="computeroutput">generic::raw_protocol</code></a>
</li>
<li class="listitem">
<a class="link" href="../../reference/generic__seq_packet_protocol.html" title="generic::seq_packet_protocol"><code class="computeroutput">generic::seq_packet_protocol</code></a>
</li>
<li class="listitem">
<a class="link" href="../../reference/generic__stream_protocol.html" title="generic::stream_protocol"><code class="computeroutput">generic::stream_protocol</code></a>
</li>
</ul></div>
<p>
These classes implement the <a class="link" href="../../reference/Protocol.html" title="Protocol requirements">protocol
type requirements</a>, but allow the user to specify the address family
(e.g. <code class="computeroutput">AF_INET</code>) and protocol type (e.g. <code class="computeroutput">IPPROTO_TCP</code>)
at runtime. For example:
</p>
<pre class="programlisting">asio::generic::stream_protocol::socket my_socket(my_io_context);
my_socket.open(asio::generic::stream_protocol(AF_INET, IPPROTO_TCP));
...
</pre>
<p>
An endpoint class template, <a class="link" href="../../reference/generic__basic_endpoint.html" title="generic::basic_endpoint"><code class="computeroutput">asio::generic::basic_endpoint</code></a>,
is included to support these protocol classes. This endpoint can hold any
other endpoint type, provided its native representation fits into a <code class="computeroutput">sockaddr_storage</code>
object. This class will also convert from other types that implement the
<a class="link" href="../../reference/Endpoint.html" title="Endpoint requirements">endpoint</a> type requirements:
</p>
<pre class="programlisting">asio::ip::tcp::endpoint my_endpoint1 = ...;
asio::generic::stream_protocol::endpoint my_endpoint2(my_endpoint1);
</pre>
<p>
The conversion is implicit, so as to support the following use cases:
</p>
<pre class="programlisting">asio::generic::stream_protocol::socket my_socket(my_io_context);
asio::ip::tcp::endpoint my_endpoint = ...;
my_socket.connect(my_endpoint);
</pre>
<h6>
<a name="asio.overview.networking.other_protocols.h0"></a>
<span><a name="asio.overview.networking.other_protocols.c__11_move_construction"></a></span><a class="link" href="other_protocols.html#asio.overview.networking.other_protocols.c__11_move_construction">C++11
Move Construction</a>
</h6>
<p>
When using C++11, it is possible to perform move construction from a socket
(or acceptor) object to convert to the more generic protocol's socket (or
acceptor) type. If the protocol conversion is valid:
</p>
<pre class="programlisting">Protocol1 p1 = ...;
Protocol2 p2(p1);
</pre>
<p>
then the corresponding socket conversion is allowed:
</p>
<pre class="programlisting">Protocol1::socket my_socket1(my_io_context);
...
Protocol2::socket my_socket2(std::move(my_socket1));
</pre>
<p>
For example, one possible conversion is from a TCP socket to a generic
stream-oriented socket:
</p>
<pre class="programlisting">asio::ip::tcp::socket my_socket1(my_io_context);
...
asio::generic::stream_protocol::socket my_socket2(std::move(my_socket1));
</pre>
<p>
These conversions are also available for move-assignment.
</p>
<p>
These conversions are not limited to the above generic protocol classes.
User-defined protocols may take advantage of this feature by similarly
ensuring the conversion from <code class="computeroutput">Protocol1</code> to <code class="computeroutput">Protocol2</code>
is valid, as above.
</p>
<h6>
<a name="asio.overview.networking.other_protocols.h1"></a>
<span><a name="asio.overview.networking.other_protocols.accepting_generic_sockets"></a></span><a class="link" href="other_protocols.html#asio.overview.networking.other_protocols.accepting_generic_sockets">Accepting
Generic Sockets</a>
</h6>
<p>
As a convenience, a socket acceptor's <code class="computeroutput">accept()</code> and <code class="computeroutput">async_accept()</code>
functions can directly accept into a different protocol's socket type,
provided the corresponding protocol conversion is valid. For example, the
following is supported because the protocol <code class="computeroutput">asio::ip::tcp</code>
is convertible to <code class="computeroutput">asio::generic::stream_protocol</code>:
</p>
<pre class="programlisting">asio::ip::tcp::acceptor my_acceptor(my_io_context);
...
asio::generic::stream_protocol::socket my_socket(my_io_context);
my_acceptor.accept(my_socket);
</pre>
<h6>
<a name="asio.overview.networking.other_protocols.h2"></a>
<span><a name="asio.overview.networking.other_protocols.see_also"></a></span><a class="link" href="other_protocols.html#asio.overview.networking.other_protocols.see_also">See
Also</a>
</h6>
<p>
<a class="link" href="../../reference/generic__datagram_protocol.html" title="generic::datagram_protocol"><code class="computeroutput">generic::datagram_protocol</code></a>,
<a class="link" href="../../reference/generic__raw_protocol.html" title="generic::raw_protocol"><code class="computeroutput">generic::raw_protocol</code></a>,
<a class="link" href="../../reference/generic__seq_packet_protocol.html" title="generic::seq_packet_protocol"><code class="computeroutput">generic::seq_packet_protocol</code></a>,
<a class="link" href="../../reference/generic__stream_protocol.html" title="generic::stream_protocol"><code class="computeroutput">generic::stream_protocol</code></a>,
<a class="link" href="../../reference/Protocol.html" title="Protocol requirements">protocol type requirements</a>.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
Kohlhoff<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="protocols.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../networking.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="iostreams.html"><img src="../../../next.png" alt="Next"></a>
</div>
</body>
</html>
@@ -0,0 +1,204 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TCP, UDP and ICMP</title>
<link rel="stylesheet" href="../../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../../index.html" title="Asio">
<link rel="up" href="../networking.html" title="Networking">
<link rel="prev" href="../networking.html" title="Networking">
<link rel="next" href="other_protocols.html" title="Support for Other Protocols">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="asio C++ library" width="250" height="60" src="../../../asio.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../networking.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../networking.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="other_protocols.html"><img src="../../../next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="asio.overview.networking.protocols"></a><a class="link" href="protocols.html" title="TCP, UDP and ICMP">TCP, UDP and ICMP</a>
</h4></div></div></div>
<p>
Asio provides off-the-shelf support for the internet protocols TCP, UDP
and ICMP.
</p>
<h6>
<a name="asio.overview.networking.protocols.h0"></a>
<span><a name="asio.overview.networking.protocols.tcp_clients"></a></span><a class="link" href="protocols.html#asio.overview.networking.protocols.tcp_clients">TCP
Clients</a>
</h6>
<p>
Hostname resolution is performed using a resolver, where host and service
names are looked up and converted into one or more endpoints:
</p>
<pre class="programlisting">ip::tcp::resolver resolver(my_io_context);
ip::tcp::resolver::query query("www.boost.org", "http");
ip::tcp::resolver::iterator iter = resolver.resolve(query);
ip::tcp::resolver::iterator end; // End marker.
while (iter != end)
{
ip::tcp::endpoint endpoint = *iter++;
std::cout &lt;&lt; endpoint &lt;&lt; std::endl;
}
</pre>
<p>
The list of endpoints obtained above could contain both IPv4 and IPv6 endpoints,
so a program should try each of them until it finds one that works. This
keeps the client program independent of a specific IP version.
</p>
<p>
To simplify the development of protocol-independent programs, TCP clients
may establish connections using the free functions <a class="link" href="../../reference/connect.html" title="connect">connect()</a>
and <a class="link" href="../../reference/async_connect.html" title="async_connect">async_connect()</a>.
These operations try each endpoint in a list until the socket is successfully
connected. For example, a single call:
</p>
<pre class="programlisting">ip::tcp::socket socket(my_io_context);
asio::connect(socket, resolver.resolve(query));
</pre>
<p>
will synchronously try all endpoints until one is successfully connected.
Similarly, an asynchronous connect may be performed by writing:
</p>
<pre class="programlisting">asio::async_connect(socket_, iter,
boost::bind(&amp;client::handle_connect, this,
asio::placeholders::error));
// ...
void handle_connect(const error_code&amp; error)
{
if (!error)
{
// Start read or write operations.
}
else
{
// Handle error.
}
}
</pre>
<p>
When a specific endpoint is available, a socket can be created and connected:
</p>
<pre class="programlisting">ip::tcp::socket socket(my_io_context);
socket.connect(endpoint);
</pre>
<p>
Data may be read from or written to a connected TCP socket using the <a class="link" href="../../reference/basic_stream_socket/receive.html" title="basic_stream_socket::receive">receive()</a>,
<a class="link" href="../../reference/basic_stream_socket/async_receive.html" title="basic_stream_socket::async_receive">async_receive()</a>,
<a class="link" href="../../reference/basic_stream_socket/send.html" title="basic_stream_socket::send">send()</a> or
<a class="link" href="../../reference/basic_stream_socket/async_send.html" title="basic_stream_socket::async_send">async_send()</a>
member functions. However, as these could result in <a class="link" href="../core/streams.html" title="Streams, Short Reads and Short Writes">short
writes or reads</a>, an application will typically use the following
operations instead: <a class="link" href="../../reference/read.html" title="read">read()</a>,
<a class="link" href="../../reference/async_read.html" title="async_read">async_read()</a>, <a class="link" href="../../reference/write.html" title="write">write()</a>
and <a class="link" href="../../reference/async_write.html" title="async_write">async_write()</a>.
</p>
<h6>
<a name="asio.overview.networking.protocols.h1"></a>
<span><a name="asio.overview.networking.protocols.tcp_servers"></a></span><a class="link" href="protocols.html#asio.overview.networking.protocols.tcp_servers">TCP
Servers</a>
</h6>
<p>
A program uses an acceptor to accept incoming TCP connections:
</p>
<pre class="programlisting">ip::tcp::acceptor acceptor(my_io_context, my_endpoint);
...
ip::tcp::socket socket(my_io_context);
acceptor.accept(socket);
</pre>
<p>
After a socket has been successfully accepted, it may be read from or written
to as illustrated for TCP clients above.
</p>
<h6>
<a name="asio.overview.networking.protocols.h2"></a>
<span><a name="asio.overview.networking.protocols.udp"></a></span><a class="link" href="protocols.html#asio.overview.networking.protocols.udp">UDP</a>
</h6>
<p>
UDP hostname resolution is also performed using a resolver:
</p>
<pre class="programlisting">ip::udp::resolver resolver(my_io_context);
ip::udp::resolver::query query("localhost", "daytime");
ip::udp::resolver::iterator iter = resolver.resolve(query);
...
</pre>
<p>
A UDP socket is typically bound to a local endpoint. The following code
will create an IP version 4 UDP socket and bind it to the "any"
address on port <code class="computeroutput">12345</code>:
</p>
<pre class="programlisting">ip::udp::endpoint endpoint(ip::udp::v4(), 12345);
ip::udp::socket socket(my_io_context, endpoint);
</pre>
<p>
Data may be read from or written to an unconnected UDP socket using the
<a class="link" href="../../reference/basic_datagram_socket/receive_from.html" title="basic_datagram_socket::receive_from">receive_from()</a>,
<a class="link" href="../../reference/basic_datagram_socket/async_receive_from.html" title="basic_datagram_socket::async_receive_from">async_receive_from()</a>,
<a class="link" href="../../reference/basic_datagram_socket/send_to.html" title="basic_datagram_socket::send_to">send_to()</a>
or <a class="link" href="../../reference/basic_datagram_socket/async_send_to.html" title="basic_datagram_socket::async_send_to">async_send_to()</a>
member functions. For a connected UDP socket, use the <a class="link" href="../../reference/basic_datagram_socket/receive.html" title="basic_datagram_socket::receive">receive()</a>,
<a class="link" href="../../reference/basic_datagram_socket/async_receive.html" title="basic_datagram_socket::async_receive">async_receive()</a>,
<a class="link" href="../../reference/basic_datagram_socket/send.html" title="basic_datagram_socket::send">send()</a>
or <a class="link" href="../../reference/basic_datagram_socket/async_send.html" title="basic_datagram_socket::async_send">async_send()</a>
member functions.
</p>
<h6>
<a name="asio.overview.networking.protocols.h3"></a>
<span><a name="asio.overview.networking.protocols.icmp"></a></span><a class="link" href="protocols.html#asio.overview.networking.protocols.icmp">ICMP</a>
</h6>
<p>
As with TCP and UDP, ICMP hostname resolution is performed using a resolver:
</p>
<pre class="programlisting">ip::icmp::resolver resolver(my_io_context);
ip::icmp::resolver::query query("localhost", "");
ip::icmp::resolver::iterator iter = resolver.resolve(query);
...
</pre>
<p>
An ICMP socket may be bound to a local endpoint. The following code will
create an IP version 6 ICMP socket and bind it to the "any" address:
</p>
<pre class="programlisting">ip::icmp::endpoint endpoint(ip::icmp::v6(), 0);
ip::icmp::socket socket(my_io_context, endpoint);
</pre>
<p>
The port number is not used for ICMP.
</p>
<p>
Data may be read from or written to an unconnected ICMP socket using the
<a class="link" href="../../reference/basic_raw_socket/receive_from.html" title="basic_raw_socket::receive_from">receive_from()</a>,
<a class="link" href="../../reference/basic_raw_socket/async_receive_from.html" title="basic_raw_socket::async_receive_from">async_receive_from()</a>,
<a class="link" href="../../reference/basic_raw_socket/send_to.html" title="basic_raw_socket::send_to">send_to()</a>
or <a class="link" href="../../reference/basic_raw_socket/async_send_to.html" title="basic_raw_socket::async_send_to">async_send_to()</a>
member functions.
</p>
<h6>
<a name="asio.overview.networking.protocols.h4"></a>
<span><a name="asio.overview.networking.protocols.see_also"></a></span><a class="link" href="protocols.html#asio.overview.networking.protocols.see_also">See
Also</a>
</h6>
<p>
<a class="link" href="../../reference/ip__tcp.html" title="ip::tcp">ip::tcp</a>, <a class="link" href="../../reference/ip__udp.html" title="ip::udp">ip::udp</a>,
<a class="link" href="../../reference/ip__icmp.html" title="ip::icmp">ip::icmp</a>, <a class="link" href="../../tutorial/tutdaytime1.html" title="Daytime.1 - A synchronous TCP daytime client">daytime
protocol tutorials</a>, <a class="link" href="../../examples/cpp03_examples.html#asio.examples.cpp03_examples.icmp">ICMP
ping example</a>.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M.
Kohlhoff<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../networking.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../networking.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="other_protocols.html"><img src="../../../next.png" alt="Next"></a>
</div>
</body>
</html>