Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84312 - in trunk/libs/asio: doc doc/overview example/allocation example/buffers example/chat example/cpp03 example/cpp03/allocation example/cpp03/buffers example/cpp03/chat example/cpp03/echo example/cpp03/fork example/cpp03/http example/cpp03/icmp example/cpp03/invocation example/cpp03/iostreams example/cpp03/local example/cpp03/multicast example/cpp03/nonblocking example/cpp03/porthopper example/cpp03/serialization example/cpp03/services example/cpp03/socks4 example/cpp03/spawn example/cpp03/ssl example/cpp03/timeouts example/cpp03/timers example/cpp03/tutorial example/cpp03/windows example/cpp11 example/cpp11/allocation example/cpp11/buffers example/cpp11/chat example/cpp11/echo example/cpp11/http example/cpp11/http/server example/cpp11/spawn example/echo example/fork example/http example/icmp example/invocation example/iostreams example/local example/multicast example/nonblocking example/porthopper example/serialization example/services example/socks4 example/spawn example/ssl example/timeouts example/timers example/tutorial example/windows
From: chris_at_[hidden]
Date: 2013-05-16 22:25:15


Author: chris_kohlhoff
Date: 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
New Revision: 84312
URL: http://svn.boost.org/trac/boost/changeset/84312

Log:
Move existing examples into a C++03-specific directory, and add a new
directory for C++11-specific examples. A limited subset of the C++03
examples have been converted to their C++11 equivalents.

Added:
   trunk/libs/asio/example/cpp03/
   trunk/libs/asio/example/cpp03/allocation/
      - copied from r84311, /trunk/libs/asio/example/allocation/
   trunk/libs/asio/example/cpp03/buffers/
      - copied from r84311, /trunk/libs/asio/example/buffers/
   trunk/libs/asio/example/cpp03/chat/
      - copied from r84311, /trunk/libs/asio/example/chat/
   trunk/libs/asio/example/cpp03/echo/
      - copied from r84311, /trunk/libs/asio/example/echo/
   trunk/libs/asio/example/cpp03/fork/
      - copied from r84311, /trunk/libs/asio/example/fork/
   trunk/libs/asio/example/cpp03/http/
      - copied from r84311, /trunk/libs/asio/example/http/
   trunk/libs/asio/example/cpp03/icmp/
      - copied from r84311, /trunk/libs/asio/example/icmp/
   trunk/libs/asio/example/cpp03/invocation/
      - copied from r84311, /trunk/libs/asio/example/invocation/
   trunk/libs/asio/example/cpp03/iostreams/
      - copied from r84311, /trunk/libs/asio/example/iostreams/
   trunk/libs/asio/example/cpp03/local/
      - copied from r84311, /trunk/libs/asio/example/local/
   trunk/libs/asio/example/cpp03/multicast/
      - copied from r84311, /trunk/libs/asio/example/multicast/
   trunk/libs/asio/example/cpp03/nonblocking/
      - copied from r84311, /trunk/libs/asio/example/nonblocking/
   trunk/libs/asio/example/cpp03/porthopper/
      - copied from r84311, /trunk/libs/asio/example/porthopper/
   trunk/libs/asio/example/cpp03/serialization/
      - copied from r84311, /trunk/libs/asio/example/serialization/
   trunk/libs/asio/example/cpp03/services/
      - copied from r84311, /trunk/libs/asio/example/services/
   trunk/libs/asio/example/cpp03/socks4/
      - copied from r84311, /trunk/libs/asio/example/socks4/
   trunk/libs/asio/example/cpp03/spawn/
      - copied from r84311, /trunk/libs/asio/example/spawn/
   trunk/libs/asio/example/cpp03/ssl/
      - copied from r84311, /trunk/libs/asio/example/ssl/
   trunk/libs/asio/example/cpp03/timeouts/
      - copied from r84311, /trunk/libs/asio/example/timeouts/
   trunk/libs/asio/example/cpp03/timers/
      - copied from r84311, /trunk/libs/asio/example/timers/
   trunk/libs/asio/example/cpp03/tutorial/
      - copied from r84311, /trunk/libs/asio/example/tutorial/
   trunk/libs/asio/example/cpp03/windows/
      - copied from r84311, /trunk/libs/asio/example/windows/
   trunk/libs/asio/example/cpp11/
   trunk/libs/asio/example/cpp11/allocation/
   trunk/libs/asio/example/cpp11/allocation/Jamfile (contents, props changed)
   trunk/libs/asio/example/cpp11/allocation/Jamfile.v2 (contents, props changed)
   trunk/libs/asio/example/cpp11/allocation/server.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/buffers/
   trunk/libs/asio/example/cpp11/buffers/Jamfile (contents, props changed)
   trunk/libs/asio/example/cpp11/buffers/Jamfile.v2 (contents, props changed)
   trunk/libs/asio/example/cpp11/buffers/reference_counted.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/chat/
   trunk/libs/asio/example/cpp11/chat/Jamfile (contents, props changed)
   trunk/libs/asio/example/cpp11/chat/Jamfile.v2 (contents, props changed)
   trunk/libs/asio/example/cpp11/chat/chat_client.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/chat/chat_message.hpp (contents, props changed)
   trunk/libs/asio/example/cpp11/chat/chat_server.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/echo/
   trunk/libs/asio/example/cpp11/echo/Jamfile (contents, props changed)
   trunk/libs/asio/example/cpp11/echo/Jamfile.v2 (contents, props changed)
   trunk/libs/asio/example/cpp11/echo/async_tcp_echo_server.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/echo/async_udp_echo_server.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/echo/blocking_tcp_echo_client.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/echo/blocking_tcp_echo_server.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/echo/blocking_udp_echo_client.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/echo/blocking_udp_echo_server.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/
   trunk/libs/asio/example/cpp11/http/server/
   trunk/libs/asio/example/cpp11/http/server/Jamfile (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/Jamfile.v2 (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/connection.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/connection.hpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/connection_manager.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/connection_manager.hpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/header.hpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/main.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/mime_types.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/mime_types.hpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/reply.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/reply.hpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/request.hpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/request_handler.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/request_handler.hpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/request_parser.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/request_parser.hpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/server.cpp (contents, props changed)
   trunk/libs/asio/example/cpp11/http/server/server.hpp (contents, props changed)
   trunk/libs/asio/example/cpp11/spawn/
   trunk/libs/asio/example/cpp11/spawn/Jamfile.v2 (contents, props changed)
   trunk/libs/asio/example/cpp11/spawn/echo_server.cpp (contents, props changed)
Removed:
   trunk/libs/asio/example/allocation/
   trunk/libs/asio/example/buffers/
   trunk/libs/asio/example/chat/
   trunk/libs/asio/example/echo/
   trunk/libs/asio/example/fork/
   trunk/libs/asio/example/http/
   trunk/libs/asio/example/icmp/
   trunk/libs/asio/example/invocation/
   trunk/libs/asio/example/iostreams/
   trunk/libs/asio/example/local/
   trunk/libs/asio/example/multicast/
   trunk/libs/asio/example/nonblocking/
   trunk/libs/asio/example/porthopper/
   trunk/libs/asio/example/serialization/
   trunk/libs/asio/example/services/
   trunk/libs/asio/example/socks4/
   trunk/libs/asio/example/spawn/
   trunk/libs/asio/example/ssl/
   trunk/libs/asio/example/timeouts/
   trunk/libs/asio/example/timers/
   trunk/libs/asio/example/tutorial/
   trunk/libs/asio/example/windows/
Text files modified:
   trunk/libs/asio/doc/Jamfile.v2 | 11
   trunk/libs/asio/doc/examples.qbk | 341 ++++++++++++++++++++++++++-------------
   trunk/libs/asio/doc/overview/allocation.qbk | 3
   trunk/libs/asio/doc/overview/buffers.qbk | 3
   trunk/libs/asio/doc/overview/iostreams.qbk | 2
   trunk/libs/asio/doc/overview/line_based.qbk | 2
   trunk/libs/asio/doc/overview/posix.qbk | 7
   trunk/libs/asio/doc/overview/protocols.qbk | 2
   trunk/libs/asio/doc/overview/reactor.qbk | 2
   trunk/libs/asio/doc/overview/signals.qbk | 3
   trunk/libs/asio/doc/overview/ssl.qbk | 2
   trunk/libs/asio/doc/overview/strands.qbk | 2
   trunk/libs/asio/example/cpp03/echo/blocking_tcp_echo_server.cpp | 2
   trunk/libs/asio/example/cpp03/echo/blocking_udp_echo_server.cpp | 2
   14 files changed, 248 insertions(+), 136 deletions(-)

Modified: trunk/libs/asio/doc/Jamfile.v2
==============================================================================
--- trunk/libs/asio/doc/Jamfile.v2 (original)
+++ trunk/libs/asio/doc/Jamfile.v2 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -25,10 +25,13 @@
     <location>html/boost_asio
   ;
 
-local example-names = allocation buffers chat echo fork http/client http/server
- http/server2 http/server3 http/server4 icmp invocation iostreams local
- multicast nonblocking porthopper serialization services socks4 ssl timeouts
- timers windows ;
+local example-names = cpp03/allocation cpp03/buffers cpp03/chat cpp03/echo
+ cpp03/fork cpp03/http/client cpp03/http/server cpp03/http/server2
+ cpp03/http/server3 cpp03/http/server4 cpp03/icmp cpp03/invocation
+ cpp03/iostreams cpp03/local cpp03/multicast cpp03/nonblocking cpp03/porthopper
+ cpp03/serialization cpp03/services cpp03/socks4 cpp03/spawn cpp03/ssl
+ cpp03/timeouts cpp03/timers cpp03/windows cpp11/allocaton cpp11/buffers
+ cpp11/chat cpp11/echo cpp11/http/server cpp11/spawn ;
 
 for local l in $(example-names)
 {

Modified: trunk/libs/asio/doc/examples.qbk
==============================================================================
--- trunk/libs/asio/doc/examples.qbk (original)
+++ trunk/libs/asio/doc/examples.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -8,12 +8,24 @@
 [section:examples Examples]
 
 
+* [link boost_asio.examples.cpp03_examples C++03 Examples]: Illustrates the use of
+Boost.Asio using only C++03 language and library features. Where necessary, the
+examples make use of selected Boost C++ libraries.
+
+* [link boost_asio.examples.cpp11_examples C++11 Examples]: Contains a limited set of
+the C++03 Boost.Asio examples, updated to use only C++11 library and language
+facilities. These examples do not make direct use of Boost C++ libraries.
+
+
+[section:cpp03_examples C++03 Examples]
+
+
 [heading Allocation]
 
 This example shows how to customise the allocation of memory associated with
 asynchronous operations.
 
-* [@boost_asio/example/allocation/server.cpp]
+* [@boost_asio/example/cpp03/allocation/server.cpp]
 
 
 [heading Buffers]
@@ -21,7 +33,7 @@
 This example demonstrates how to create reference counted buffers that can be
 used with socket read and write operations.
 
-* [@boost_asio/example/buffers/reference_counted.cpp]
+* [@boost_asio/example/cpp03/buffers/reference_counted.cpp]
 
 
 [heading Chat]
@@ -29,15 +41,15 @@
 This example implements a chat server and client. The programs use a custom
 protocol with a fixed length message header and variable length message body.
 
-* [@boost_asio/example/chat/chat_message.hpp]
-* [@boost_asio/example/chat/chat_client.cpp]
-* [@boost_asio/example/chat/chat_server.cpp]
+* [@boost_asio/example/cpp03/chat/chat_message.hpp]
+* [@boost_asio/example/cpp03/chat/chat_client.cpp]
+* [@boost_asio/example/cpp03/chat/chat_server.cpp]
 
 The following POSIX-specific chat client demonstrates how to use the
 [link boost_asio.reference.posix__stream_descriptor posix::stream_descriptor] class to
 perform console input and output.
 
-* [@boost_asio/example/chat/posix_chat_client.cpp]
+* [@boost_asio/example/cpp03/chat/posix_chat_client.cpp]
 
 
 [heading Echo]
@@ -45,12 +57,12 @@
 A collection of simple clients and servers, showing the use of both synchronous
 and asynchronous operations.
 
-* [@boost_asio/example/echo/async_tcp_echo_server.cpp]
-* [@boost_asio/example/echo/async_udp_echo_server.cpp]
-* [@boost_asio/example/echo/blocking_tcp_echo_client.cpp]
-* [@boost_asio/example/echo/blocking_tcp_echo_server.cpp]
-* [@boost_asio/example/echo/blocking_udp_echo_client.cpp]
-* [@boost_asio/example/echo/blocking_udp_echo_server.cpp]
+* [@boost_asio/example/cpp03/echo/async_tcp_echo_server.cpp]
+* [@boost_asio/example/cpp03/echo/async_udp_echo_server.cpp]
+* [@boost_asio/example/cpp03/echo/blocking_tcp_echo_client.cpp]
+* [@boost_asio/example/cpp03/echo/blocking_tcp_echo_server.cpp]
+* [@boost_asio/example/cpp03/echo/blocking_udp_echo_client.cpp]
+* [@boost_asio/example/cpp03/echo/blocking_udp_echo_server.cpp]
 
 
 [heading Fork]
@@ -59,12 +71,12 @@
 `fork()` system call. The first example illustrates the steps required to start
 a daemon process:
 
-* [@boost_asio/example/fork/daemon.cpp]
+* [@boost_asio/example/cpp03/fork/daemon.cpp]
 
 The second example demonstrates how it is possible to fork a process from
 within a completion handler.
 
-* [@boost_asio/example/fork/process_per_connection.cpp]
+* [@boost_asio/example/cpp03/fork/process_per_connection.cpp]
 
 
 [heading HTTP Client]
@@ -73,8 +85,8 @@
 to use the [link boost_asio.reference.read_until read_until] and [link
 boost_asio.reference.async_read_until async_read_until] functions.
 
-* [@boost_asio/example/http/client/sync_client.cpp]
-* [@boost_asio/example/http/client/async_client.cpp]
+* [@boost_asio/example/cpp03/http/client/sync_client.cpp]
+* [@boost_asio/example/cpp03/http/client/async_client.cpp]
 
 
 [heading HTTP Server]
@@ -83,98 +95,98 @@
 implementation of HTTP 1.0. It demonstrates how to perform a clean shutdown by
 cancelling all outstanding asynchronous operations.
 
-* [@boost_asio/example/http/server/connection.cpp]
-* [@boost_asio/example/http/server/connection.hpp]
-* [@boost_asio/example/http/server/connection_manager.cpp]
-* [@boost_asio/example/http/server/connection_manager.hpp]
-* [@boost_asio/example/http/server/header.hpp]
-* [@boost_asio/example/http/server/main.cpp]
-* [@boost_asio/example/http/server/mime_types.cpp]
-* [@boost_asio/example/http/server/mime_types.hpp]
-* [@boost_asio/example/http/server/reply.cpp]
-* [@boost_asio/example/http/server/reply.hpp]
-* [@boost_asio/example/http/server/request.hpp]
-* [@boost_asio/example/http/server/request_handler.cpp]
-* [@boost_asio/example/http/server/request_handler.hpp]
-* [@boost_asio/example/http/server/request_parser.cpp]
-* [@boost_asio/example/http/server/request_parser.hpp]
-* [@boost_asio/example/http/server/server.cpp]
-* [@boost_asio/example/http/server/server.hpp]
+* [@boost_asio/example/cpp03/http/server/connection.cpp]
+* [@boost_asio/example/cpp03/http/server/connection.hpp]
+* [@boost_asio/example/cpp03/http/server/connection_manager.cpp]
+* [@boost_asio/example/cpp03/http/server/connection_manager.hpp]
+* [@boost_asio/example/cpp03/http/server/header.hpp]
+* [@boost_asio/example/cpp03/http/server/main.cpp]
+* [@boost_asio/example/cpp03/http/server/mime_types.cpp]
+* [@boost_asio/example/cpp03/http/server/mime_types.hpp]
+* [@boost_asio/example/cpp03/http/server/reply.cpp]
+* [@boost_asio/example/cpp03/http/server/reply.hpp]
+* [@boost_asio/example/cpp03/http/server/request.hpp]
+* [@boost_asio/example/cpp03/http/server/request_handler.cpp]
+* [@boost_asio/example/cpp03/http/server/request_handler.hpp]
+* [@boost_asio/example/cpp03/http/server/request_parser.cpp]
+* [@boost_asio/example/cpp03/http/server/request_parser.hpp]
+* [@boost_asio/example/cpp03/http/server/server.cpp]
+* [@boost_asio/example/cpp03/http/server/server.hpp]
 
 
 [heading HTTP Server 2]
 
 An HTTP server using an io_service-per-CPU design.
 
-* [@boost_asio/example/http/server2/connection.cpp]
-* [@boost_asio/example/http/server2/connection.hpp]
-* [@boost_asio/example/http/server2/header.hpp]
-* [@boost_asio/example/http/server2/io_service_pool.cpp]
-* [@boost_asio/example/http/server2/io_service_pool.hpp]
-* [@boost_asio/example/http/server2/main.cpp]
-* [@boost_asio/example/http/server2/mime_types.cpp]
-* [@boost_asio/example/http/server2/mime_types.hpp]
-* [@boost_asio/example/http/server2/reply.cpp]
-* [@boost_asio/example/http/server2/reply.hpp]
-* [@boost_asio/example/http/server2/request.hpp]
-* [@boost_asio/example/http/server2/request_handler.cpp]
-* [@boost_asio/example/http/server2/request_handler.hpp]
-* [@boost_asio/example/http/server2/request_parser.cpp]
-* [@boost_asio/example/http/server2/request_parser.hpp]
-* [@boost_asio/example/http/server2/server.cpp]
-* [@boost_asio/example/http/server2/server.hpp]
+* [@boost_asio/example/cpp03/http/server2/connection.cpp]
+* [@boost_asio/example/cpp03/http/server2/connection.hpp]
+* [@boost_asio/example/cpp03/http/server2/header.hpp]
+* [@boost_asio/example/cpp03/http/server2/io_service_pool.cpp]
+* [@boost_asio/example/cpp03/http/server2/io_service_pool.hpp]
+* [@boost_asio/example/cpp03/http/server2/main.cpp]
+* [@boost_asio/example/cpp03/http/server2/mime_types.cpp]
+* [@boost_asio/example/cpp03/http/server2/mime_types.hpp]
+* [@boost_asio/example/cpp03/http/server2/reply.cpp]
+* [@boost_asio/example/cpp03/http/server2/reply.hpp]
+* [@boost_asio/example/cpp03/http/server2/request.hpp]
+* [@boost_asio/example/cpp03/http/server2/request_handler.cpp]
+* [@boost_asio/example/cpp03/http/server2/request_handler.hpp]
+* [@boost_asio/example/cpp03/http/server2/request_parser.cpp]
+* [@boost_asio/example/cpp03/http/server2/request_parser.hpp]
+* [@boost_asio/example/cpp03/http/server2/server.cpp]
+* [@boost_asio/example/cpp03/http/server2/server.hpp]
 
 
 [heading HTTP Server 3]
 
 An HTTP server using a single io_service and a thread pool calling `io_service::run()`.
 
-* [@boost_asio/example/http/server3/connection.cpp]
-* [@boost_asio/example/http/server3/connection.hpp]
-* [@boost_asio/example/http/server3/header.hpp]
-* [@boost_asio/example/http/server3/main.cpp]
-* [@boost_asio/example/http/server3/mime_types.cpp]
-* [@boost_asio/example/http/server3/mime_types.hpp]
-* [@boost_asio/example/http/server3/reply.cpp]
-* [@boost_asio/example/http/server3/reply.hpp]
-* [@boost_asio/example/http/server3/request.hpp]
-* [@boost_asio/example/http/server3/request_handler.cpp]
-* [@boost_asio/example/http/server3/request_handler.hpp]
-* [@boost_asio/example/http/server3/request_parser.cpp]
-* [@boost_asio/example/http/server3/request_parser.hpp]
-* [@boost_asio/example/http/server3/server.cpp]
-* [@boost_asio/example/http/server3/server.hpp]
+* [@boost_asio/example/cpp03/http/server3/connection.cpp]
+* [@boost_asio/example/cpp03/http/server3/connection.hpp]
+* [@boost_asio/example/cpp03/http/server3/header.hpp]
+* [@boost_asio/example/cpp03/http/server3/main.cpp]
+* [@boost_asio/example/cpp03/http/server3/mime_types.cpp]
+* [@boost_asio/example/cpp03/http/server3/mime_types.hpp]
+* [@boost_asio/example/cpp03/http/server3/reply.cpp]
+* [@boost_asio/example/cpp03/http/server3/reply.hpp]
+* [@boost_asio/example/cpp03/http/server3/request.hpp]
+* [@boost_asio/example/cpp03/http/server3/request_handler.cpp]
+* [@boost_asio/example/cpp03/http/server3/request_handler.hpp]
+* [@boost_asio/example/cpp03/http/server3/request_parser.cpp]
+* [@boost_asio/example/cpp03/http/server3/request_parser.hpp]
+* [@boost_asio/example/cpp03/http/server3/server.cpp]
+* [@boost_asio/example/cpp03/http/server3/server.hpp]
 
 
 [heading HTTP Server 4]
 
 A single-threaded HTTP server implemented using stackless coroutines.
 
-* [@boost_asio/example/http/server4/coroutine.hpp]
-* [@boost_asio/example/http/server4/file_handler.cpp]
-* [@boost_asio/example/http/server4/file_handler.hpp]
-* [@boost_asio/example/http/server4/header.hpp]
-* [@boost_asio/example/http/server4/main.cpp]
-* [@boost_asio/example/http/server4/mime_types.cpp]
-* [@boost_asio/example/http/server4/mime_types.hpp]
-* [@boost_asio/example/http/server4/reply.cpp]
-* [@boost_asio/example/http/server4/reply.hpp]
-* [@boost_asio/example/http/server4/request.hpp]
-* [@boost_asio/example/http/server4/request_parser.cpp]
-* [@boost_asio/example/http/server4/request_parser.hpp]
-* [@boost_asio/example/http/server4/server.cpp]
-* [@boost_asio/example/http/server4/server.hpp]
-* [@boost_asio/example/http/server4/unyield.hpp]
-* [@boost_asio/example/http/server4/yield.hpp]
+* [@boost_asio/example/cpp03/http/server4/coroutine.hpp]
+* [@boost_asio/example/cpp03/http/server4/file_handler.cpp]
+* [@boost_asio/example/cpp03/http/server4/file_handler.hpp]
+* [@boost_asio/example/cpp03/http/server4/header.hpp]
+* [@boost_asio/example/cpp03/http/server4/main.cpp]
+* [@boost_asio/example/cpp03/http/server4/mime_types.cpp]
+* [@boost_asio/example/cpp03/http/server4/mime_types.hpp]
+* [@boost_asio/example/cpp03/http/server4/reply.cpp]
+* [@boost_asio/example/cpp03/http/server4/reply.hpp]
+* [@boost_asio/example/cpp03/http/server4/request.hpp]
+* [@boost_asio/example/cpp03/http/server4/request_parser.cpp]
+* [@boost_asio/example/cpp03/http/server4/request_parser.hpp]
+* [@boost_asio/example/cpp03/http/server4/server.cpp]
+* [@boost_asio/example/cpp03/http/server4/server.hpp]
+* [@boost_asio/example/cpp03/http/server4/unyield.hpp]
+* [@boost_asio/example/cpp03/http/server4/yield.hpp]
 
 
 [heading ICMP]
 
 This example shows how to use raw sockets with ICMP to ping a remote host.
 
-* [@boost_asio/example/icmp/ping.cpp]
-* [@boost_asio/example/icmp/ipv4_header.hpp]
-* [@boost_asio/example/icmp/icmp_header.hpp]
+* [@boost_asio/example/cpp03/icmp/ping.cpp]
+* [@boost_asio/example/cpp03/icmp/ipv4_header.hpp]
+* [@boost_asio/example/cpp03/icmp/icmp_header.hpp]
 
 
 [heading Invocation]
@@ -182,7 +194,7 @@
 This example shows how to customise handler invocation. Completion handlers are
 added to a priority queue rather than executed immediately.
 
-* [@boost_asio/example/invocation/prioritised_handlers.cpp]
+* [@boost_asio/example/cpp03/invocation/prioritised_handlers.cpp]
 
 
 [heading Iostreams]
@@ -190,9 +202,9 @@
 Two examples showing how to use [link boost_asio.reference.ip__tcp.iostream
 ip::tcp::iostream].
 
-* [@boost_asio/example/iostreams/daytime_client.cpp]
-* [@boost_asio/example/iostreams/daytime_server.cpp]
-* [@boost_asio/example/iostreams/http_client.cpp]
+* [@boost_asio/example/cpp03/iostreams/daytime_client.cpp]
+* [@boost_asio/example/cpp03/iostreams/daytime_server.cpp]
+* [@boost_asio/example/cpp03/iostreams/http_client.cpp]
 
 
 [heading Multicast]
@@ -200,8 +212,8 @@
 An example showing the use of multicast to transmit packets to a group of
 subscribers.
 
-* [@boost_asio/example/multicast/receiver.cpp]
-* [@boost_asio/example/multicast/sender.cpp]
+* [@boost_asio/example/cpp03/multicast/receiver.cpp]
+* [@boost_asio/example/cpp03/multicast/sender.cpp]
 
 
 [heading Serialization]
@@ -209,10 +221,10 @@
 This example shows how Boost.Serialization can be used with asio to encode and
 decode structures for transmission over a socket.
 
-* [@boost_asio/example/serialization/client.cpp]
-* [@boost_asio/example/serialization/connection.hpp]
-* [@boost_asio/example/serialization/server.cpp]
-* [@boost_asio/example/serialization/stock.hpp]
+* [@boost_asio/example/cpp03/serialization/client.cpp]
+* [@boost_asio/example/cpp03/serialization/connection.hpp]
+* [@boost_asio/example/cpp03/serialization/server.cpp]
+* [@boost_asio/example/cpp03/serialization/stock.hpp]
 
 
 [heading Services]
@@ -222,12 +234,12 @@
 how to use a custom service with [link
 boost_asio.reference.basic_stream_socket basic_stream_socket<>].
 
-* [@boost_asio/example/services/basic_logger.hpp]
-* [@boost_asio/example/services/daytime_client.cpp]
-* [@boost_asio/example/services/logger.hpp]
-* [@boost_asio/example/services/logger_service.cpp]
-* [@boost_asio/example/services/logger_service.hpp]
-* [@boost_asio/example/services/stream_socket_service.hpp]
+* [@boost_asio/example/cpp03/services/basic_logger.hpp]
+* [@boost_asio/example/cpp03/services/daytime_client.cpp]
+* [@boost_asio/example/cpp03/services/logger.hpp]
+* [@boost_asio/example/cpp03/services/logger_service.cpp]
+* [@boost_asio/example/cpp03/services/logger_service.hpp]
+* [@boost_asio/example/cpp03/services/stream_socket_service.hpp]
 
 
 [heading SOCKS 4]
@@ -235,8 +247,8 @@
 Example client program implementing the SOCKS 4 protocol for communication via
 a proxy.
 
-* [@boost_asio/example/socks4/sync_client.cpp]
-* [@boost_asio/example/socks4/socks4.hpp]
+* [@boost_asio/example/cpp03/socks4/sync_client.cpp]
+* [@boost_asio/example/cpp03/socks4/socks4.hpp]
 
 
 [heading SSL]
@@ -244,8 +256,8 @@
 Example client and server programs showing the use of the [link
 boost_asio.reference.ssl__stream ssl::stream<>] template with asynchronous operations.
 
-* [@boost_asio/example/ssl/client.cpp]
-* [@boost_asio/example/ssl/server.cpp]
+* [@boost_asio/example/cpp03/ssl/client.cpp]
+* [@boost_asio/example/cpp03/ssl/server.cpp]
 
 
 [heading Timeouts]
@@ -253,18 +265,18 @@
 A collection of examples showing how to cancel long running asynchronous
 operations after a period of time.
 
-* [@boost_asio/example/timeouts/async_tcp_client.cpp]
-* [@boost_asio/example/timeouts/blocking_tcp_client.cpp]
-* [@boost_asio/example/timeouts/blocking_udp_client.cpp]
-* [@boost_asio/example/timeouts/server.cpp]
+* [@boost_asio/example/cpp03/timeouts/async_tcp_client.cpp]
+* [@boost_asio/example/cpp03/timeouts/blocking_tcp_client.cpp]
+* [@boost_asio/example/cpp03/timeouts/blocking_udp_client.cpp]
+* [@boost_asio/example/cpp03/timeouts/server.cpp]
 
 
 [heading Timers]
 
 Examples showing how to customise deadline_timer using different time types.
 
-* [@boost_asio/example/timers/tick_count_timer.cpp]
-* [@boost_asio/example/timers/time_t_timer.cpp]
+* [@boost_asio/example/cpp03/timers/tick_count_timer.cpp]
+* [@boost_asio/example/cpp03/timers/time_t_timer.cpp]
 
 
 [heading Porthopper]
@@ -272,9 +284,9 @@
 Example illustrating mixed synchronous and asynchronous operations, and how to
 use Boost.Lambda with Boost.Asio.
 
-* [@boost_asio/example/porthopper/protocol.hpp]
-* [@boost_asio/example/porthopper/client.cpp]
-* [@boost_asio/example/porthopper/server.cpp]
+* [@boost_asio/example/cpp03/porthopper/protocol.hpp]
+* [@boost_asio/example/cpp03/porthopper/client.cpp]
+* [@boost_asio/example/cpp03/porthopper/server.cpp]
 
 
 [heading Nonblocking]
@@ -282,16 +294,26 @@
 Example demonstrating reactor-style operations for integrating a third-party
 library that wants to perform the I/O operations itself.
 
-* [@boost_asio/example/nonblocking/third_party_lib.cpp]
+* [@boost_asio/example/cpp03/nonblocking/third_party_lib.cpp]
+
+
+[heading Spawn]
+
+Example of using the boost::asio::spawn() function, a wrapper around the
+[@http://www.boost.org/doc/libs/release/libs/coroutine/index.html Boost.Coroutine]
+library, to implement a chain of asynchronous operations using stackful
+coroutines.
+
+* [@boost_asio/example/cpp03/spawn/echo_server.cpp]
 
 
 [heading UNIX Domain Sockets]
 
 Examples showing how to use UNIX domain (local) sockets.
 
-* [@boost_asio/example/local/connect_pair.cpp]
-* [@boost_asio/example/local/stream_server.cpp]
-* [@boost_asio/example/local/stream_client.cpp]
+* [@boost_asio/example/cpp03/local/connect_pair.cpp]
+* [@boost_asio/example/cpp03/local/stream_server.cpp]
+* [@boost_asio/example/cpp03/local/stream_client.cpp]
 
 
 [heading Windows]
@@ -299,7 +321,90 @@
 An example showing how to use the Windows-specific function `TransmitFile`
 with Boost.Asio.
 
-* [@boost_asio/example/windows/transmit_file.cpp]
+* [@boost_asio/example/cpp03/windows/transmit_file.cpp]
+
+
+[endsect]
+
+
+[section:cpp11_examples C++11 Examples]
+
+
+[heading Allocation]
+
+This example shows how to customise the allocation of memory associated with
+asynchronous operations.
+
+* [@boost_asio/example/cpp11/allocation/server.cpp]
+
+
+[heading Buffers]
+
+This example demonstrates how to create reference counted buffers that can be
+used with socket read and write operations.
+
+* [@boost_asio/example/cpp11/buffers/reference_counted.cpp]
+
+
+[heading Chat]
+
+This example implements a chat server and client. The programs use a custom
+protocol with a fixed length message header and variable length message body.
+
+* [@boost_asio/example/cpp11/chat/chat_message.hpp]
+* [@boost_asio/example/cpp11/chat/chat_client.cpp]
+* [@boost_asio/example/cpp11/chat/chat_server.cpp]
+
+
+[heading Echo]
+
+A collection of simple clients and servers, showing the use of both synchronous
+and asynchronous operations.
+
+* [@boost_asio/example/cpp11/echo/async_tcp_echo_server.cpp]
+* [@boost_asio/example/cpp11/echo/async_udp_echo_server.cpp]
+* [@boost_asio/example/cpp11/echo/blocking_tcp_echo_client.cpp]
+* [@boost_asio/example/cpp11/echo/blocking_tcp_echo_server.cpp]
+* [@boost_asio/example/cpp11/echo/blocking_udp_echo_client.cpp]
+* [@boost_asio/example/cpp11/echo/blocking_udp_echo_server.cpp]
+
+
+[heading HTTP Server]
+
+This example illustrates the use of asio in a simple single-threaded server
+implementation of HTTP 1.0. It demonstrates how to perform a clean shutdown by
+cancelling all outstanding asynchronous operations.
+
+* [@boost_asio/example/cpp11/http/server/connection.cpp]
+* [@boost_asio/example/cpp11/http/server/connection.hpp]
+* [@boost_asio/example/cpp11/http/server/connection_manager.cpp]
+* [@boost_asio/example/cpp11/http/server/connection_manager.hpp]
+* [@boost_asio/example/cpp11/http/server/header.hpp]
+* [@boost_asio/example/cpp11/http/server/main.cpp]
+* [@boost_asio/example/cpp11/http/server/mime_types.cpp]
+* [@boost_asio/example/cpp11/http/server/mime_types.hpp]
+* [@boost_asio/example/cpp11/http/server/reply.cpp]
+* [@boost_asio/example/cpp11/http/server/reply.hpp]
+* [@boost_asio/example/cpp11/http/server/request.hpp]
+* [@boost_asio/example/cpp11/http/server/request_handler.cpp]
+* [@boost_asio/example/cpp11/http/server/request_handler.hpp]
+* [@boost_asio/example/cpp11/http/server/request_parser.cpp]
+* [@boost_asio/example/cpp11/http/server/request_parser.hpp]
+* [@boost_asio/example/cpp11/http/server/server.cpp]
+* [@boost_asio/example/cpp11/http/server/server.hpp]
+
+
+[heading Spawn]
+
+Example of using the boost::asio::spawn() function, a wrapper around the
+[@http://www.boost.org/doc/libs/release/libs/coroutine/index.html Boost.Coroutine]
+library, to implement a chain of asynchronous operations using stackful
+coroutines.
+
+* [@boost_asio/example/cpp11/spawn/echo_server.cpp]
+
+
+[endsect]
 
 
 [endsect]

Modified: trunk/libs/asio/doc/overview/allocation.qbk
==============================================================================
--- trunk/libs/asio/doc/overview/allocation.qbk (original)
+++ trunk/libs/asio/doc/overview/allocation.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -52,6 +52,7 @@
 
 [link boost_asio.reference.asio_handler_allocate asio_handler_allocate],
 [link boost_asio.reference.asio_handler_deallocate asio_handler_deallocate],
-[link boost_asio.examples.allocation custom memory allocation example].
+[link boost_asio.examples.cpp03_examples.allocation custom memory allocation example (C++03)],
+[link boost_asio.examples.cpp11_examples.allocation custom memory allocation example (C++11)].
 
 [endsect]

Modified: trunk/libs/asio/doc/overview/buffers.qbk
==============================================================================
--- trunk/libs/asio/doc/overview/buffers.qbk (original)
+++ trunk/libs/asio/doc/overview/buffers.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -157,6 +157,7 @@
 [link boost_asio.reference.streambuf streambuf],
 [link boost_asio.reference.ConstBufferSequence ConstBufferSequence],
 [link boost_asio.reference.MutableBufferSequence MutableBufferSequence],
-[link boost_asio.examples.buffers buffers example].
+[link boost_asio.examples.cpp03_examples.buffers buffers example (C++03)],
+[link boost_asio.examples.cpp11_examples.buffers buffers example (c++11)].
 
 [endsect]

Modified: trunk/libs/asio/doc/overview/iostreams.qbk
==============================================================================
--- trunk/libs/asio/doc/overview/iostreams.qbk (original)
+++ trunk/libs/asio/doc/overview/iostreams.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -62,7 +62,7 @@
 
 [link boost_asio.reference.ip__tcp.iostream ip::tcp::iostream],
 [link boost_asio.reference.basic_socket_iostream basic_socket_iostream],
-[link boost_asio.examples.iostreams iostreams examples].
+[link boost_asio.examples.cpp03_examples.iostreams iostreams examples].
 
 [heading Notes]
 

Modified: trunk/libs/asio/doc/overview/line_based.qbk
==============================================================================
--- trunk/libs/asio/doc/overview/line_based.qbk (original)
+++ trunk/libs/asio/doc/overview/line_based.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -113,6 +113,6 @@
 [link boost_asio.reference.is_match_condition is_match_condition],
 [link boost_asio.reference.read_until read_until()],
 [link boost_asio.reference.streambuf streambuf],
-[link boost_asio.examples.http_client HTTP client example].
+[link boost_asio.examples.cpp03_examples.http_client HTTP client example].
 
 [endsect]

Modified: trunk/libs/asio/doc/overview/posix.qbk
==============================================================================
--- trunk/libs/asio/doc/overview/posix.qbk (original)
+++ trunk/libs/asio/doc/overview/posix.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -61,7 +61,7 @@
 [link boost_asio.reference.local__stream_protocol.endpoint local::stream_protocol::endpoint],
 [link boost_asio.reference.local__stream_protocol.iostream local::stream_protocol::iostream],
 [link boost_asio.reference.local__stream_protocol.socket local::stream_protocol::socket],
-[link boost_asio.examples.unix_domain_sockets UNIX domain sockets examples].
+[link boost_asio.examples.cpp03_examples.unix_domain_sockets UNIX domain sockets examples].
 
 [heading Notes]
 
@@ -95,7 +95,8 @@
 [link boost_asio.reference.posix__stream_descriptor posix::stream_descriptor],
 [link boost_asio.reference.posix__basic_stream_descriptor posix::basic_stream_descriptor],
 [link boost_asio.reference.posix__stream_descriptor_service posix::stream_descriptor_service],
-[link boost_asio.examples.chat Chat example].
+[link boost_asio.examples.cpp03_examples.chat Chat example (C++03)],
+[link boost_asio.examples.cpp11_examples.chat Chat example (C++11)].
 
 [heading Notes]
 
@@ -138,7 +139,7 @@
 [link boost_asio.reference.io_service.notify_fork io_service::notify_fork()],
 [link boost_asio.reference.io_service.fork_event io_service::fork_event],
 [link boost_asio.reference.io_service__service.fork_service io_service::service::fork_service()],
-[link boost_asio.examples.fork Fork examples].
+[link boost_asio.examples.cpp03_examples.fork Fork examples].
 
 [endsect]
 

Modified: trunk/libs/asio/doc/overview/protocols.qbk
==============================================================================
--- trunk/libs/asio/doc/overview/protocols.qbk (original)
+++ trunk/libs/asio/doc/overview/protocols.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -150,6 +150,6 @@
 [link boost_asio.reference.ip__udp ip::udp],
 [link boost_asio.reference.ip__icmp ip::icmp],
 [link boost_asio.tutorial.tutdaytime1 daytime protocol tutorials],
-[link boost_asio.examples.icmp ICMP ping example].
+[link boost_asio.examples.cpp03_examples.icmp ICMP ping example].
 
 [endsect]

Modified: trunk/libs/asio/doc/overview/reactor.qbk
==============================================================================
--- trunk/libs/asio/doc/overview/reactor.qbk (original)
+++ trunk/libs/asio/doc/overview/reactor.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -39,6 +39,6 @@
 [link boost_asio.reference.null_buffers null_buffers],
 [link boost_asio.reference.basic_socket.non_blocking basic_socket::non_blocking()],
 [link boost_asio.reference.basic_socket.native_non_blocking basic_socket::native_non_blocking()],
-[link boost_asio.examples.nonblocking nonblocking example].
+[link boost_asio.examples.cpp03_examples.nonblocking nonblocking example].
 
 [endsect]

Modified: trunk/libs/asio/doc/overview/signals.qbk
==============================================================================
--- trunk/libs/asio/doc/overview/signals.qbk (original)
+++ trunk/libs/asio/doc/overview/signals.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -38,6 +38,7 @@
 [heading See Also]
 
 [link boost_asio.reference.signal_set signal_set],
-[link boost_asio.examples.http_server HTTP server example].
+[link boost_asio.examples.cpp03_examples.http_server HTTP server example (C++03)],
+[link boost_asio.examples.cpp11_examples.http_server HTTP server example (C++11)].
 
 [endsect]

Modified: trunk/libs/asio/doc/overview/ssl.qbk
==============================================================================
--- trunk/libs/asio/doc/overview/ssl.qbk (original)
+++ trunk/libs/asio/doc/overview/ssl.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -110,7 +110,7 @@
 [link boost_asio.reference.ssl__context ssl::context],
 [link boost_asio.reference.ssl__rfc2818_verification ssl::rfc2818_verification],
 [link boost_asio.reference.ssl__stream ssl::stream],
-[link boost_asio.examples.ssl SSL example].
+[link boost_asio.examples.cpp03_examples.ssl SSL example].
 
 [heading Notes]
 

Modified: trunk/libs/asio/doc/overview/strands.qbk
==============================================================================
--- trunk/libs/asio/doc/overview/strands.qbk (original)
+++ trunk/libs/asio/doc/overview/strands.qbk 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -57,6 +57,6 @@
 
 [link boost_asio.reference.io_service__strand io_service::strand],
 [link boost_asio.tutorial.tuttimer5 tutorial Timer.5],
-[link boost_asio.examples.http_server_3 HTTP server 3 example].
+[link boost_asio.examples.cpp03_examples.http_server_3 HTTP server 3 example].
 
 [endsect]

Modified: trunk/libs/asio/example/cpp03/echo/blocking_tcp_echo_server.cpp
==============================================================================
--- /trunk/libs/asio/example/echo/blocking_tcp_echo_server.cpp (original)
+++ trunk/libs/asio/example/cpp03/echo/blocking_tcp_echo_server.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -45,7 +45,7 @@
   }
 }
 
-void server(boost::asio::io_service& io_service, short port)
+void server(boost::asio::io_service& io_service, unsigned short port)
 {
   tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
   for (;;)

Modified: trunk/libs/asio/example/cpp03/echo/blocking_udp_echo_server.cpp
==============================================================================
--- /trunk/libs/asio/example/echo/blocking_udp_echo_server.cpp (original)
+++ trunk/libs/asio/example/cpp03/echo/blocking_udp_echo_server.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -16,7 +16,7 @@
 
 enum { max_length = 1024 };
 
-void server(boost::asio::io_service& io_service, short port)
+void server(boost::asio::io_service& io_service, unsigned short port)
 {
   udp::socket sock(io_service, udp::endpoint(udp::v4(), port));
   for (;;)

Added: trunk/libs/asio/example/cpp11/allocation/Jamfile
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/allocation/Jamfile 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,33 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+subproject libs/asio/example/allocation ;
+
+project boost : $(BOOST_ROOT) ;
+
+if $(UNIX)
+{
+ switch $(JAMUNAME)
+ {
+ case SunOS* :
+ {
+ SOCKET_LIBS = <find-library>socket <find-library>nsl ;
+ }
+ }
+}
+
+exe server
+ : <lib>@boost/libs/system/build/boost_system
+ server.cpp
+ : <include>$(BOOST_ROOT)
+ <include>../../../..
+ <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <mingw><*><find-library>ws2_32
+ <mingw><*><find-library>mswsock
+ $(SOCKET_LIBS)
+ ;

Added: trunk/libs/asio/example/cpp11/allocation/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/allocation/Jamfile.v2 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+import os ;
+
+if [ os.name ] = SOLARIS
+{
+ lib socket ;
+ lib nsl ;
+}
+else if [ os.name ] = NT
+{
+ lib ws2_32 ;
+ lib mswsock ;
+}
+else if [ os.name ] = HPUX
+{
+ lib ipv6 ;
+}
+
+exe server
+ : server.cpp
+ /boost/system//boost_system
+ : <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <os>SOLARIS:<library>socket
+ <os>SOLARIS:<library>nsl
+ <os>NT:<define>_WIN32_WINNT=0x0501
+ <os>NT,<toolset>gcc:<library>ws2_32
+ <os>NT,<toolset>gcc:<library>mswsock
+ <os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
+ <os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
+ <os>HPUX:<library>ipv6
+ ;

Added: trunk/libs/asio/example/cpp11/allocation/server.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/allocation/server.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,215 @@
+//
+// server.cpp
+// ~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <array>
+#include <cstdlib>
+#include <iostream>
+#include <memory>
+#include <type_traits>
+#include <utility>
+#include <boost/asio.hpp>
+
+using boost::asio::ip::tcp;
+
+// Class to manage the memory to be used for handler-based custom allocation.
+// It contains a single block of memory which may be returned for allocation
+// requests. If the memory is in use when an allocation request is made, the
+// allocator delegates allocation to the global heap.
+class handler_allocator
+{
+public:
+ handler_allocator()
+ : in_use_(false)
+ {
+ }
+
+ handler_allocator(const handler_allocator&) = delete;
+ handler_allocator& operator=(const handler_allocator&) = delete;
+
+ void* allocate(std::size_t size)
+ {
+ if (!in_use_ && size < sizeof(storage_))
+ {
+ in_use_ = true;
+ return &storage_;
+ }
+ else
+ {
+ return ::operator new(size);
+ }
+ }
+
+ void deallocate(void* pointer)
+ {
+ if (pointer == &storage_)
+ {
+ in_use_ = false;
+ }
+ else
+ {
+ ::operator delete(pointer);
+ }
+ }
+
+private:
+ // Storage space used for handler-based custom memory allocation.
+ typename std::aligned_storage<1024>::type storage_;
+
+ // Whether the handler-based custom allocation storage has been used.
+ bool in_use_;
+};
+
+// Wrapper class template for handler objects to allow handler memory
+// allocation to be customised. Calls to operator() are forwarded to the
+// encapsulated handler.
+template <typename Handler>
+class custom_alloc_handler
+{
+public:
+ custom_alloc_handler(handler_allocator& a, Handler h)
+ : allocator_(a),
+ handler_(h)
+ {
+ }
+
+ template <typename ...Args>
+ void operator()(Args&&... args)
+ {
+ handler_(std::forward<Args>(args)...);
+ }
+
+ friend void* asio_handler_allocate(std::size_t size,
+ custom_alloc_handler<Handler>* this_handler)
+ {
+ return this_handler->allocator_.allocate(size);
+ }
+
+ friend void asio_handler_deallocate(void* pointer, std::size_t /*size*/,
+ custom_alloc_handler<Handler>* this_handler)
+ {
+ this_handler->allocator_.deallocate(pointer);
+ }
+
+private:
+ handler_allocator& allocator_;
+ Handler handler_;
+};
+
+// Helper function to wrap a handler object to add custom allocation.
+template <typename Handler>
+inline custom_alloc_handler<Handler> make_custom_alloc_handler(
+ handler_allocator& a, Handler h)
+{
+ return custom_alloc_handler<Handler>(a, h);
+}
+
+class session
+ : public std::enable_shared_from_this<session>
+{
+public:
+ session(tcp::socket socket)
+ : socket_(std::move(socket))
+ {
+ }
+
+ void start()
+ {
+ do_read();
+ }
+
+private:
+ void do_read()
+ {
+ auto self(shared_from_this());
+ socket_.async_read_some(boost::asio::buffer(data_),
+ make_custom_alloc_handler(allocator_,
+ [this, self](boost::system::error_code ec, std::size_t length)
+ {
+ if (!ec)
+ {
+ do_write(length);
+ }
+ }));
+ }
+
+ void do_write(std::size_t length)
+ {
+ auto self(shared_from_this());
+ boost::asio::async_write(socket_, boost::asio::buffer(data_, length),
+ make_custom_alloc_handler(allocator_,
+ [this, self](boost::system::error_code ec, std::size_t /*length*/)
+ {
+ if (!ec)
+ {
+ do_read();
+ }
+ }));
+ }
+
+ // The socket used to communicate with the client.
+ tcp::socket socket_;
+
+ // Buffer used to store data received from the client.
+ std::array<char, 1024> data_;
+
+ // The allocator to use for handler-based custom memory allocation.
+ handler_allocator allocator_;
+};
+
+class server
+{
+public:
+ server(boost::asio::io_service& io_service, short port)
+ : acceptor_(io_service, tcp::endpoint(tcp::v4(), port)),
+ socket_(io_service)
+ {
+ do_accept();
+ }
+
+private:
+ void do_accept()
+ {
+ acceptor_.async_accept(socket_,
+ [this](boost::system::error_code ec)
+ {
+ if (!ec)
+ {
+ std::make_shared<session>(std::move(socket_))->start();
+ }
+
+ do_accept();
+ });
+ }
+
+ tcp::acceptor acceptor_;
+ tcp::socket socket_;
+};
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 2)
+ {
+ std::cerr << "Usage: server <port>\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+ server s(io_service, std::atoi(argv[1]));
+ io_service.run();
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/buffers/Jamfile
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/buffers/Jamfile 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,33 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+subproject libs/asio/example/buffers ;
+
+project boost : $(BOOST_ROOT) ;
+
+if $(UNIX)
+{
+ switch $(JAMUNAME)
+ {
+ case SunOS* :
+ {
+ SOCKET_LIBS = <find-library>socket <find-library>nsl ;
+ }
+ }
+}
+
+exe server
+ : <lib>@boost/libs/system/build/boost_system
+ reference_counted.cpp
+ : <include>$(BOOST_ROOT)
+ <include>../../../..
+ <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <mingw><*><find-library>ws2_32
+ <mingw><*><find-library>mswsock
+ $(SOCKET_LIBS)
+ ;

Added: trunk/libs/asio/example/cpp11/buffers/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/buffers/Jamfile.v2 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+import os ;
+
+if [ os.name ] = SOLARIS
+{
+ lib socket ;
+ lib nsl ;
+}
+else if [ os.name ] = NT
+{
+ lib ws2_32 ;
+ lib mswsock ;
+}
+else if [ os.name ] = HPUX
+{
+ lib ipv6 ;
+}
+
+exe server
+ : reference_counted.cpp
+ /boost/system//boost_system
+ : <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <os>SOLARIS:<library>socket
+ <os>SOLARIS:<library>nsl
+ <os>NT:<define>_WIN32_WINNT=0x0501
+ <os>NT,<toolset>gcc:<library>ws2_32
+ <os>NT,<toolset>gcc:<library>mswsock
+ <os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
+ <os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
+ <os>HPUX:<library>ipv6
+ ;

Added: trunk/libs/asio/example/cpp11/buffers/reference_counted.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/buffers/reference_counted.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,123 @@
+//
+// reference_counted.cpp
+// ~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <boost/asio.hpp>
+#include <iostream>
+#include <memory>
+#include <utility>
+#include <vector>
+
+using boost::asio::ip::tcp;
+
+// A reference-counted non-modifiable buffer class.
+class shared_const_buffer
+{
+public:
+ // Construct from a std::string.
+ explicit shared_const_buffer(const std::string& data)
+ : data_(new std::vector<char>(data.begin(), data.end())),
+ buffer_(boost::asio::buffer(*data_))
+ {
+ }
+
+ // Implement the ConstBufferSequence requirements.
+ typedef boost::asio::const_buffer value_type;
+ typedef const boost::asio::const_buffer* const_iterator;
+ const boost::asio::const_buffer* begin() const { return &buffer_; }
+ const boost::asio::const_buffer* end() const { return &buffer_ + 1; }
+
+private:
+ std::shared_ptr<std::vector<char> > data_;
+ boost::asio::const_buffer buffer_;
+};
+
+class session
+ : public std::enable_shared_from_this<session>
+{
+public:
+ session(tcp::socket socket)
+ : socket_(std::move(socket))
+ {
+ }
+
+ void start()
+ {
+ do_write();
+ }
+
+private:
+ void do_write()
+ {
+ std::time_t now = std::time(0);
+ shared_const_buffer buffer(std::ctime(&now));
+
+ auto self(shared_from_this());
+ boost::asio::async_write(socket_, buffer,
+ [this, self](boost::system::error_code /*ec*/, std::size_t /*length*/)
+ {
+ });
+ }
+
+ // The socket used to communicate with the client.
+ tcp::socket socket_;
+};
+
+class server
+{
+public:
+ server(boost::asio::io_service& io_service, short port)
+ : acceptor_(io_service, tcp::endpoint(tcp::v4(), port)),
+ socket_(io_service)
+ {
+ do_accept();
+ }
+
+private:
+ void do_accept()
+ {
+ acceptor_.async_accept(socket_,
+ [this](boost::system::error_code ec)
+ {
+ if (!ec)
+ {
+ std::make_shared<session>(std::move(socket_))->start();
+ }
+
+ do_accept();
+ });
+ }
+
+ tcp::acceptor acceptor_;
+ tcp::socket socket_;
+};
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 2)
+ {
+ std::cerr << "Usage: reference_counted <port>\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+
+ server s(io_service, std::atoi(argv[1]));
+
+ io_service.run();
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/chat/Jamfile
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/chat/Jamfile 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+subproject libs/asio/example/chat ;
+
+project boost : $(BOOST_ROOT) ;
+
+if $(UNIX)
+{
+ switch $(JAMUNAME)
+ {
+ case SunOS* :
+ {
+ SOCKET_LIBS = <find-library>socket <find-library>nsl ;
+ }
+ }
+}
+
+exe chat_client
+ : <lib>@boost/libs/thread/build/boost_thread
+ <lib>@boost/libs/system/build/boost_system
+ chat_client.cpp
+ : <include>$(BOOST_ROOT)
+ <include>../../../..
+ <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <mingw><*><find-library>ws2_32
+ <mingw><*><find-library>mswsock
+ $(SOCKET_LIBS)
+ ;
+
+exe chat_server
+ : <lib>@boost/libs/thread/build/boost_thread
+ <lib>@boost/libs/system/build/boost_system
+ chat_server.cpp
+ : <include>$(BOOST_ROOT)
+ <include>../../../..
+ <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <mingw><*><find-library>ws2_32
+ <mingw><*><find-library>mswsock
+ $(SOCKET_LIBS)
+ ;

Added: trunk/libs/asio/example/cpp11/chat/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/chat/Jamfile.v2 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+import os ;
+
+if [ os.name ] = SOLARIS
+{
+ lib socket ;
+ lib nsl ;
+}
+else if [ os.name ] = NT
+{
+ lib ws2_32 ;
+ lib mswsock ;
+}
+else if [ os.name ] = HPUX
+{
+ lib ipv6 ;
+}
+
+project
+ : requirements
+ <library>/boost/system//boost_system
+ <library>/boost/thread//boost_thread
+ <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <os>SOLARIS:<library>socket
+ <os>SOLARIS:<library>nsl
+ <os>NT:<define>_WIN32_WINNT=0x0501
+ <os>NT,<toolset>gcc:<library>ws2_32
+ <os>NT,<toolset>gcc:<library>mswsock
+ <os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
+ <os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
+ <os>HPUX:<library>ipv6
+ ;
+
+exe chat_server : chat_server.cpp ;
+exe chat_client : chat_client.cpp ;

Added: trunk/libs/asio/example/cpp11/chat/chat_client.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/chat/chat_client.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,167 @@
+//
+// chat_client.cpp
+// ~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <cstdlib>
+#include <deque>
+#include <iostream>
+#include <thread>
+#include <boost/asio.hpp>
+#include "chat_message.hpp"
+
+using boost::asio::ip::tcp;
+
+typedef std::deque<chat_message> chat_message_queue;
+
+class chat_client
+{
+public:
+ chat_client(boost::asio::io_service& io_service,
+ tcp::resolver::iterator endpoint_iterator)
+ : io_service_(io_service),
+ socket_(io_service)
+ {
+ do_connect(endpoint_iterator);
+ }
+
+ void write(const chat_message& msg)
+ {
+ io_service_.post(
+ [this, msg]()
+ {
+ bool write_in_progress = !write_msgs_.empty();
+ write_msgs_.push_back(msg);
+ if (!write_in_progress)
+ {
+ do_write();
+ }
+ });
+ }
+
+ void close()
+ {
+ io_service_.post([this]() { socket_.close(); });
+ }
+
+private:
+ void do_connect(tcp::resolver::iterator endpoint_iterator)
+ {
+ boost::asio::async_connect(socket_, endpoint_iterator,
+ [this](boost::system::error_code ec, tcp::resolver::iterator)
+ {
+ if (!ec)
+ {
+ do_read_header();
+ }
+ });
+ }
+
+ void do_read_header()
+ {
+ boost::asio::async_read(socket_,
+ boost::asio::buffer(read_msg_.data(), chat_message::header_length),
+ [this](boost::system::error_code ec, std::size_t /*length*/)
+ {
+ if (!ec && read_msg_.decode_header())
+ {
+ do_read_body();
+ }
+ else
+ {
+ socket_.close();
+ }
+ });
+ }
+
+ void do_read_body()
+ {
+ boost::asio::async_read(socket_,
+ boost::asio::buffer(read_msg_.body(), read_msg_.body_length()),
+ [this](boost::system::error_code ec, std::size_t /*length*/)
+ {
+ if (!ec)
+ {
+ std::cout.write(read_msg_.body(), read_msg_.body_length());
+ std::cout << "\n";
+ do_read_header();
+ }
+ else
+ {
+ socket_.close();
+ }
+ });
+ }
+
+ void do_write()
+ {
+ boost::asio::async_write(socket_,
+ boost::asio::buffer(write_msgs_.front().data(),
+ write_msgs_.front().length()),
+ [this](boost::system::error_code ec, std::size_t /*length*/)
+ {
+ if (!ec)
+ {
+ write_msgs_.pop_front();
+ if (!write_msgs_.empty())
+ {
+ do_write();
+ }
+ }
+ else
+ {
+ socket_.close();
+ }
+ });
+ }
+
+private:
+ boost::asio::io_service& io_service_;
+ tcp::socket socket_;
+ chat_message read_msg_;
+ chat_message_queue write_msgs_;
+};
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 3)
+ {
+ std::cerr << "Usage: chat_client <host> <port>\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+
+ tcp::resolver resolver(io_service);
+ auto endpoint_iterator = resolver.resolve({ argv[1], argv[2] });
+ chat_client c(io_service, endpoint_iterator);
+
+ std::thread t([&io_service](){ io_service.run(); });
+
+ char line[chat_message::max_body_length + 1];
+ while (std::cin.getline(line, chat_message::max_body_length + 1))
+ {
+ chat_message msg;
+ msg.body_length(std::strlen(line));
+ std::memcpy(msg.body(), line, msg.body_length());
+ msg.encode_header();
+ c.write(msg);
+ }
+
+ c.close();
+ t.join();
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/chat/chat_message.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/chat/chat_message.hpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,91 @@
+//
+// chat_message.hpp
+// ~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef CHAT_MESSAGE_HPP
+#define CHAT_MESSAGE_HPP
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+class chat_message
+{
+public:
+ enum { header_length = 4 };
+ enum { max_body_length = 512 };
+
+ chat_message()
+ : body_length_(0)
+ {
+ }
+
+ const char* data() const
+ {
+ return data_;
+ }
+
+ char* data()
+ {
+ return data_;
+ }
+
+ std::size_t length() const
+ {
+ return header_length + body_length_;
+ }
+
+ const char* body() const
+ {
+ return data_ + header_length;
+ }
+
+ char* body()
+ {
+ return data_ + header_length;
+ }
+
+ std::size_t body_length() const
+ {
+ return body_length_;
+ }
+
+ void body_length(std::size_t new_length)
+ {
+ body_length_ = new_length;
+ if (body_length_ > max_body_length)
+ body_length_ = max_body_length;
+ }
+
+ bool decode_header()
+ {
+ char header[header_length + 1] = "";
+ std::strncat(header, data_, header_length);
+ body_length_ = std::atoi(header);
+ if (body_length_ > max_body_length)
+ {
+ body_length_ = 0;
+ return false;
+ }
+ return true;
+ }
+
+ void encode_header()
+ {
+ char header[header_length + 1] = "";
+ std::sprintf(header, "%4d", body_length_);
+ std::memcpy(data_, header, header_length);
+ }
+
+private:
+ char data_[header_length + max_body_length];
+ std::size_t body_length_;
+};
+
+#endif // CHAT_MESSAGE_HPP

Added: trunk/libs/asio/example/cpp11/chat/chat_server.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/chat/chat_server.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,229 @@
+//
+// chat_server.cpp
+// ~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <cstdlib>
+#include <deque>
+#include <iostream>
+#include <list>
+#include <memory>
+#include <set>
+#include <utility>
+#include <boost/asio.hpp>
+#include "chat_message.hpp"
+
+using boost::asio::ip::tcp;
+
+//----------------------------------------------------------------------
+
+typedef std::deque<chat_message> chat_message_queue;
+
+//----------------------------------------------------------------------
+
+class chat_participant
+{
+public:
+ virtual ~chat_participant() {}
+ virtual void deliver(const chat_message& msg) = 0;
+};
+
+typedef std::shared_ptr<chat_participant> chat_participant_ptr;
+
+//----------------------------------------------------------------------
+
+class chat_room
+{
+public:
+ void join(chat_participant_ptr participant)
+ {
+ participants_.insert(participant);
+ for (auto msg: recent_msgs_)
+ participant->deliver(msg);
+ }
+
+ void leave(chat_participant_ptr participant)
+ {
+ participants_.erase(participant);
+ }
+
+ void deliver(const chat_message& msg)
+ {
+ recent_msgs_.push_back(msg);
+ while (recent_msgs_.size() > max_recent_msgs)
+ recent_msgs_.pop_front();
+
+ for (auto participant: participants_)
+ participant->deliver(msg);
+ }
+
+private:
+ std::set<chat_participant_ptr> participants_;
+ enum { max_recent_msgs = 100 };
+ chat_message_queue recent_msgs_;
+};
+
+//----------------------------------------------------------------------
+
+class chat_session
+ : public chat_participant,
+ public std::enable_shared_from_this<chat_session>
+{
+public:
+ chat_session(tcp::socket socket, chat_room& room)
+ : socket_(std::move(socket)),
+ room_(room)
+ {
+ }
+
+ void start()
+ {
+ room_.join(shared_from_this());
+ do_read_header();
+ }
+
+ void deliver(const chat_message& msg)
+ {
+ bool write_in_progress = !write_msgs_.empty();
+ write_msgs_.push_back(msg);
+ if (!write_in_progress)
+ {
+ do_write();
+ }
+ }
+
+private:
+ void do_read_header()
+ {
+ auto self(shared_from_this());
+ boost::asio::async_read(socket_,
+ boost::asio::buffer(read_msg_.data(), chat_message::header_length),
+ [this, self](boost::system::error_code ec, std::size_t /*length*/)
+ {
+ if (!ec && read_msg_.decode_header())
+ {
+ do_read_body();
+ }
+ else
+ {
+ room_.leave(shared_from_this());
+ }
+ });
+ }
+
+ void do_read_body()
+ {
+ auto self(shared_from_this());
+ boost::asio::async_read(socket_,
+ boost::asio::buffer(read_msg_.body(), read_msg_.body_length()),
+ [this, self](boost::system::error_code ec, std::size_t /*length*/)
+ {
+ if (!ec)
+ {
+ room_.deliver(read_msg_);
+ do_read_header();
+ }
+ else
+ {
+ room_.leave(shared_from_this());
+ }
+ });
+ }
+
+ void do_write()
+ {
+ auto self(shared_from_this());
+ boost::asio::async_write(socket_,
+ boost::asio::buffer(write_msgs_.front().data(),
+ write_msgs_.front().length()),
+ [this, self](boost::system::error_code ec, std::size_t /*length*/)
+ {
+ if (!ec)
+ {
+ write_msgs_.pop_front();
+ if (!write_msgs_.empty())
+ {
+ do_write();
+ }
+ }
+ else
+ {
+ room_.leave(shared_from_this());
+ }
+ });
+ }
+
+ tcp::socket socket_;
+ chat_room& room_;
+ chat_message read_msg_;
+ chat_message_queue write_msgs_;
+};
+
+//----------------------------------------------------------------------
+
+class chat_server
+{
+public:
+ chat_server(boost::asio::io_service& io_service,
+ const tcp::endpoint& endpoint)
+ : acceptor_(io_service, endpoint),
+ socket_(io_service)
+ {
+ do_accept();
+ }
+
+private:
+ void do_accept()
+ {
+ acceptor_.async_accept(socket_,
+ [this](boost::system::error_code ec)
+ {
+ if (!ec)
+ {
+ std::make_shared<chat_session>(std::move(socket_), room_)->start();
+ }
+
+ do_accept();
+ });
+ }
+
+ tcp::acceptor acceptor_;
+ tcp::socket socket_;
+ chat_room room_;
+};
+
+//----------------------------------------------------------------------
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc < 2)
+ {
+ std::cerr << "Usage: chat_server <port> [<port> ...]\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+
+ std::list<chat_server> servers;
+ for (int i = 1; i < argc; ++i)
+ {
+ tcp::endpoint endpoint(tcp::v4(), std::atoi(argv[i]));
+ servers.emplace_back(io_service, endpoint);
+ }
+
+ io_service.run();
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/echo/Jamfile
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/echo/Jamfile 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,63 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+subproject libs/asio/example/echo ;
+
+project boost : $(BOOST_ROOT) ;
+
+if $(UNIX)
+{
+ switch $(JAMUNAME)
+ {
+ case SunOS* :
+ {
+ SOCKET_LIBS = <find-library>socket <find-library>nsl ;
+ }
+ }
+}
+
+template asio_echo_example
+ : <lib>@boost/libs/thread/build/boost_thread
+ <lib>@boost/libs/system/build/boost_system
+ : <include>$(BOOST_ROOT)
+ <include>../../../..
+ <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <mingw><*><find-library>ws2_32
+ <mingw><*><find-library>mswsock
+ $(SOCKET_LIBS)
+ ;
+
+exe async_tcp_echo_server
+ : <template>asio_echo_example
+ async_tcp_echo_server.cpp
+ ;
+
+exe async_udp_echo_server
+ : <template>asio_echo_example
+ async_udp_echo_server.cpp
+ ;
+
+exe blocking_tcp_echo_client
+ : <template>asio_echo_example
+ blocking_tcp_echo_client.cpp
+ ;
+
+exe blocking_tcp_echo_server
+ : <template>asio_echo_example
+ blocking_tcp_echo_server.cpp
+ ;
+
+exe blocking_udp_echo_client
+ : <template>asio_echo_example
+ blocking_udp_echo_client.cpp
+ ;
+
+exe blocking_udp_echo_server
+ : <template>asio_echo_example
+ blocking_udp_echo_server.cpp
+ ;

Added: trunk/libs/asio/example/cpp11/echo/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/echo/Jamfile.v2 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,46 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+import os ;
+
+if [ os.name ] = SOLARIS
+{
+ lib socket ;
+ lib nsl ;
+}
+else if [ os.name ] = NT
+{
+ lib ws2_32 ;
+ lib mswsock ;
+}
+else if [ os.name ] = HPUX
+{
+ lib ipv6 ;
+}
+
+project
+ : requirements
+ <library>/boost/system//boost_system
+ <library>/boost/thread//boost_thread
+ <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <os>SOLARIS:<library>socket
+ <os>SOLARIS:<library>nsl
+ <os>NT:<define>_WIN32_WINNT=0x0501
+ <os>NT,<toolset>gcc:<library>ws2_32
+ <os>NT,<toolset>gcc:<library>mswsock
+ <os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
+ <os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
+ <os>HPUX:<library>ipv6
+ ;
+
+exe async_tcp_echo_server : async_tcp_echo_server.cpp ;
+exe async_udp_echo_server : async_udp_echo_server.cpp ;
+exe blocking_tcp_echo_client : blocking_tcp_echo_client.cpp ;
+exe blocking_tcp_echo_server : blocking_tcp_echo_server.cpp ;
+exe blocking_udp_echo_client : blocking_udp_echo_client.cpp ;
+exe blocking_udp_echo_server : blocking_udp_echo_server.cpp ;

Added: trunk/libs/asio/example/cpp11/echo/async_tcp_echo_server.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/echo/async_tcp_echo_server.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,116 @@
+//
+// async_tcp_echo_server.cpp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <cstdlib>
+#include <iostream>
+#include <memory>
+#include <utility>
+#include <boost/asio.hpp>
+
+using boost::asio::ip::tcp;
+
+class session
+ : public std::enable_shared_from_this<session>
+{
+public:
+ session(tcp::socket socket)
+ : socket_(std::move(socket))
+ {
+ }
+
+ void start()
+ {
+ do_read();
+ }
+
+private:
+ void do_read()
+ {
+ auto self(shared_from_this());
+ socket_.async_read_some(boost::asio::buffer(data_, max_length),
+ [this, self](boost::system::error_code ec, std::size_t length)
+ {
+ if (!ec)
+ {
+ do_write(length);
+ }
+ });
+ }
+
+ void do_write(std::size_t length)
+ {
+ auto self(shared_from_this());
+ boost::asio::async_write(socket_, boost::asio::buffer(data_, length),
+ [this, self](boost::system::error_code ec, std::size_t /*length*/)
+ {
+ if (!ec)
+ {
+ do_read();
+ }
+ });
+ }
+
+ tcp::socket socket_;
+ enum { max_length = 1024 };
+ char data_[max_length];
+};
+
+class server
+{
+public:
+ server(boost::asio::io_service& io_service, short port)
+ : acceptor_(io_service, tcp::endpoint(tcp::v4(), port)),
+ socket_(io_service)
+ {
+ do_accept();
+ }
+
+private:
+ void do_accept()
+ {
+ acceptor_.async_accept(socket_,
+ [this](boost::system::error_code ec)
+ {
+ if (!ec)
+ {
+ std::make_shared<session>(std::move(socket_))->start();
+ }
+
+ do_accept();
+ });
+ }
+
+ tcp::acceptor acceptor_;
+ tcp::socket socket_;
+};
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 2)
+ {
+ std::cerr << "Usage: async_tcp_echo_server <port>\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+
+ server s(io_service, std::atoi(argv[1]));
+
+ io_service.run();
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/echo/async_udp_echo_server.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/echo/async_udp_echo_server.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,82 @@
+//
+// async_udp_echo_server.cpp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <cstdlib>
+#include <iostream>
+#include <boost/asio.hpp>
+
+using boost::asio::ip::udp;
+
+class server
+{
+public:
+ server(boost::asio::io_service& io_service, short port)
+ : socket_(io_service, udp::endpoint(udp::v4(), port))
+ {
+ do_receive();
+ }
+
+ void do_receive()
+ {
+ socket_.async_receive_from(
+ boost::asio::buffer(data_, max_length), sender_endpoint_,
+ [this](boost::system::error_code ec, std::size_t bytes_recvd)
+ {
+ if (!ec && bytes_recvd > 0)
+ {
+ do_send(bytes_recvd);
+ }
+ else
+ {
+ do_receive();
+ }
+ });
+ }
+
+ void do_send(std::size_t length)
+ {
+ socket_.async_send_to(
+ boost::asio::buffer(data_, length), sender_endpoint_,
+ [this](boost::system::error_code /*ec*/, std::size_t /*bytes_sent*/)
+ {
+ do_receive();
+ });
+ }
+
+private:
+ udp::socket socket_;
+ udp::endpoint sender_endpoint_;
+ enum { max_length = 1024 };
+ char data_[max_length];
+};
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 2)
+ {
+ std::cerr << "Usage: async_udp_echo_server <port>\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+
+ server s(io_service, std::atoi(argv[1]));
+
+ io_service.run();
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/echo/blocking_tcp_echo_client.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/echo/blocking_tcp_echo_client.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,55 @@
+//
+// blocking_tcp_echo_client.cpp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <boost/asio.hpp>
+
+using boost::asio::ip::tcp;
+
+enum { max_length = 1024 };
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 3)
+ {
+ std::cerr << "Usage: blocking_tcp_echo_client <host> <port>\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+
+ tcp::socket s(io_service);
+ tcp::resolver resolver(io_service);
+ boost::asio::connect(s, resolver.resolve({argv[1], argv[2]}));
+
+ std::cout << "Enter message: ";
+ char request[max_length];
+ std::cin.getline(request, max_length);
+ size_t request_length = std::strlen(request);
+ boost::asio::write(s, boost::asio::buffer(request, request_length));
+
+ char reply[max_length];
+ size_t reply_length = boost::asio::read(s,
+ boost::asio::buffer(reply, request_length));
+ std::cout << "Reply is: ";
+ std::cout.write(reply, reply_length);
+ std::cout << "\n";
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/echo/blocking_tcp_echo_server.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/echo/blocking_tcp_echo_server.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,76 @@
+//
+// blocking_tcp_echo_server.cpp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <cstdlib>
+#include <iostream>
+#include <thread>
+#include <utility>
+#include <boost/asio.hpp>
+
+using boost::asio::ip::tcp;
+
+const int max_length = 1024;
+
+void session(tcp::socket sock)
+{
+ try
+ {
+ for (;;)
+ {
+ char data[max_length];
+
+ boost::system::error_code error;
+ size_t length = sock.read_some(boost::asio::buffer(data), error);
+ if (error == boost::asio::error::eof)
+ break; // Connection closed cleanly by peer.
+ else if (error)
+ throw boost::system::system_error(error); // Some other error.
+
+ boost::asio::write(sock, boost::asio::buffer(data, length));
+ }
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception in thread: " << e.what() << "\n";
+ }
+}
+
+void server(boost::asio::io_service& io_service, unsigned short port)
+{
+ tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
+ for (;;)
+ {
+ tcp::socket sock(io_service);
+ a.accept(sock);
+ std::thread(session, std::move(sock)).detach();
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 2)
+ {
+ std::cerr << "Usage: blocking_tcp_echo_server <port>\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+
+ server(io_service, std::atoi(argv[1]));
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/echo/blocking_udp_echo_client.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/echo/blocking_udp_echo_client.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,57 @@
+//
+// blocking_udp_echo_client.cpp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <boost/asio.hpp>
+
+using boost::asio::ip::udp;
+
+enum { max_length = 1024 };
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 3)
+ {
+ std::cerr << "Usage: blocking_udp_echo_client <host> <port>\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+
+ udp::socket s(io_service, udp::endpoint(udp::v4(), 0));
+
+ udp::resolver resolver(io_service);
+ udp::endpoint endpoint = *resolver.resolve({udp::v4(), argv[1], argv[2]});
+
+ std::cout << "Enter message: ";
+ char request[max_length];
+ std::cin.getline(request, max_length);
+ size_t request_length = std::strlen(request);
+ s.send_to(boost::asio::buffer(request, request_length), endpoint);
+
+ char reply[max_length];
+ udp::endpoint sender_endpoint;
+ size_t reply_length = s.receive_from(
+ boost::asio::buffer(reply, max_length), sender_endpoint);
+ std::cout << "Reply is: ";
+ std::cout.write(reply, reply_length);
+ std::cout << "\n";
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/echo/blocking_udp_echo_server.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/echo/blocking_udp_echo_server.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,52 @@
+//
+// blocking_udp_echo_server.cpp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <cstdlib>
+#include <iostream>
+#include <boost/asio.hpp>
+
+using boost::asio::ip::udp;
+
+enum { max_length = 1024 };
+
+void server(boost::asio::io_service& io_service, unsigned short port)
+{
+ udp::socket sock(io_service, udp::endpoint(udp::v4(), port));
+ for (;;)
+ {
+ char data[max_length];
+ udp::endpoint sender_endpoint;
+ size_t length = sock.receive_from(
+ boost::asio::buffer(data, max_length), sender_endpoint);
+ sock.send_to(boost::asio::buffer(data, length), sender_endpoint);
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 2)
+ {
+ std::cerr << "Usage: blocking_udp_echo_server <port>\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+
+ server(io_service, std::atoi(argv[1]));
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/http/server/Jamfile
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/Jamfile 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,41 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+subproject libs/asio/example/http/server ;
+
+project boost : $(BOOST_ROOT) ;
+
+if $(UNIX)
+{
+ switch $(JAMUNAME)
+ {
+ case SunOS* :
+ {
+ SOCKET_LIBS = <find-library>socket <find-library>nsl ;
+ }
+ }
+}
+
+exe http_server
+ : <lib>@boost/libs/thread/build/boost_thread
+ <lib>@boost/libs/system/build/boost_system
+ connection.cpp
+ connection_manager.cpp
+ main.cpp
+ mime_types.cpp
+ reply.cpp
+ request_handler.cpp
+ request_parser.cpp
+ server.cpp
+ : <include>$(BOOST_ROOT)
+ <include>../../../../..
+ <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <mingw><*><find-library>ws2_32
+ <mingw><*><find-library>mswsock
+ $(SOCKET_LIBS)
+ ;

Added: trunk/libs/asio/example/cpp11/http/server/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/Jamfile.v2 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,46 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+import os ;
+
+if [ os.name ] = SOLARIS
+{
+ lib socket ;
+ lib nsl ;
+}
+else if [ os.name ] = NT
+{
+ lib ws2_32 ;
+ lib mswsock ;
+}
+else if [ os.name ] = HPUX
+{
+ lib ipv6 ;
+}
+
+exe server
+ : connection.cpp
+ connection_manager.cpp
+ main.cpp
+ mime_types.cpp
+ reply.cpp
+ request_handler.cpp
+ request_parser.cpp
+ server.cpp
+ /boost/system//boost_system
+ /boost/thread//boost_thread
+ : <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <os>SOLARIS:<library>socket
+ <os>SOLARIS:<library>nsl
+ <os>NT:<define>_WIN32_WINNT=0x0501
+ <os>NT,<toolset>gcc:<library>ws2_32
+ <os>NT,<toolset>gcc:<library>mswsock
+ <os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
+ <os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
+ <os>HPUX:<library>ipv6
+ ;

Added: trunk/libs/asio/example/cpp11/http/server/connection.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/connection.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,94 @@
+//
+// connection.cpp
+// ~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include "connection.hpp"
+#include <utility>
+#include <vector>
+#include "connection_manager.hpp"
+#include "request_handler.hpp"
+
+namespace http {
+namespace server {
+
+connection::connection(boost::asio::ip::tcp::socket socket,
+ connection_manager& manager, request_handler& handler)
+ : socket_(std::move(socket)),
+ connection_manager_(manager),
+ request_handler_(handler)
+{
+}
+
+void connection::start()
+{
+ do_read();
+}
+
+void connection::stop()
+{
+ socket_.close();
+}
+
+void connection::do_read()
+{
+ auto self(shared_from_this());
+ socket_.async_read_some(boost::asio::buffer(buffer_),
+ [this, self](boost::system::error_code ec, std::size_t bytes_transferred)
+ {
+ if (!ec)
+ {
+ request_parser::result_type result;
+ std::tie(result, std::ignore) = request_parser_.parse(
+ request_, buffer_.data(), buffer_.data() + bytes_transferred);
+
+ if (result == request_parser::good)
+ {
+ request_handler_.handle_request(request_, reply_);
+ do_write();
+ }
+ else if (result == request_parser::bad)
+ {
+ reply_ = reply::stock_reply(reply::bad_request);
+ do_write();
+ }
+ else
+ {
+ do_read();
+ }
+ }
+ else if (ec != boost::asio::error::operation_aborted)
+ {
+ connection_manager_.stop(shared_from_this());
+ }
+ });
+}
+
+void connection::do_write()
+{
+ auto self(shared_from_this());
+ boost::asio::async_write(socket_, reply_.to_buffers(),
+ [this, self](boost::system::error_code ec, std::size_t)
+ {
+ if (!ec)
+ {
+ // Initiate graceful connection closure.
+ boost::system::error_code ignored_ec;
+ socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both,
+ ignored_ec);
+ }
+
+ if (ec != boost::asio::error::operation_aborted)
+ {
+ connection_manager_.stop(shared_from_this());
+ }
+ });
+}
+
+} // namespace server
+} // namespace http

Added: trunk/libs/asio/example/cpp11/http/server/connection.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/connection.hpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,79 @@
+//
+// connection.hpp
+// ~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef HTTP_CONNECTION_HPP
+#define HTTP_CONNECTION_HPP
+
+#include <array>
+#include <memory>
+#include <boost/asio.hpp>
+#include "reply.hpp"
+#include "request.hpp"
+#include "request_handler.hpp"
+#include "request_parser.hpp"
+
+namespace http {
+namespace server {
+
+class connection_manager;
+
+/// Represents a single connection from a client.
+class connection
+ : public std::enable_shared_from_this<connection>
+{
+public:
+ connection(const connection&) = delete;
+ connection& operator=(const connection&) = delete;
+
+ /// Construct a connection with the given socket.
+ explicit connection(boost::asio::ip::tcp::socket socket,
+ connection_manager& manager, request_handler& handler);
+
+ /// Start the first asynchronous operation for the connection.
+ void start();
+
+ /// Stop all asynchronous operations associated with the connection.
+ void stop();
+
+private:
+ /// Perform an asynchronous read operation.
+ void do_read();
+
+ /// Perform an asynchronous write operation.
+ void do_write();
+
+ /// Socket for the connection.
+ boost::asio::ip::tcp::socket socket_;
+
+ /// The manager for this connection.
+ connection_manager& connection_manager_;
+
+ /// The handler used to process the incoming request.
+ request_handler& request_handler_;
+
+ /// Buffer for incoming data.
+ std::array<char, 8192> buffer_;
+
+ /// The incoming request.
+ request request_;
+
+ /// The parser for the incoming request.
+ request_parser request_parser_;
+
+ /// The reply to be sent back to the client.
+ reply reply_;
+};
+
+typedef std::shared_ptr<connection> connection_ptr;
+
+} // namespace server
+} // namespace http
+
+#endif // HTTP_CONNECTION_HPP

Added: trunk/libs/asio/example/cpp11/http/server/connection_manager.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/connection_manager.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,40 @@
+//
+// connection_manager.cpp
+// ~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include "connection_manager.hpp"
+
+namespace http {
+namespace server {
+
+connection_manager::connection_manager()
+{
+}
+
+void connection_manager::start(connection_ptr c)
+{
+ connections_.insert(c);
+ c->start();
+}
+
+void connection_manager::stop(connection_ptr c)
+{
+ connections_.erase(c);
+ c->stop();
+}
+
+void connection_manager::stop_all()
+{
+ for (auto c: connections_)
+ c->stop();
+ connections_.clear();
+}
+
+} // namespace server
+} // namespace http

Added: trunk/libs/asio/example/cpp11/http/server/connection_manager.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/connection_manager.hpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,48 @@
+//
+// connection_manager.hpp
+// ~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef HTTP_CONNECTION_MANAGER_HPP
+#define HTTP_CONNECTION_MANAGER_HPP
+
+#include <set>
+#include "connection.hpp"
+
+namespace http {
+namespace server {
+
+/// Manages open connections so that they may be cleanly stopped when the server
+/// needs to shut down.
+class connection_manager
+{
+public:
+ connection_manager(const connection_manager&) = delete;
+ connection_manager& operator=(const connection_manager&) = delete;
+
+ /// Construct a connection manager.
+ connection_manager();
+
+ /// Add the specified connection to the manager and start it.
+ void start(connection_ptr c);
+
+ /// Stop the specified connection.
+ void stop(connection_ptr c);
+
+ /// Stop all connections.
+ void stop_all();
+
+private:
+ /// The managed connections.
+ std::set<connection_ptr> connections_;
+};
+
+} // namespace server
+} // namespace http
+
+#endif // HTTP_CONNECTION_MANAGER_HPP

Added: trunk/libs/asio/example/cpp11/http/server/header.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/header.hpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,28 @@
+//
+// header.hpp
+// ~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef HTTP_HEADER_HPP
+#define HTTP_HEADER_HPP
+
+#include <string>
+
+namespace http {
+namespace server {
+
+struct header
+{
+ std::string name;
+ std::string value;
+};
+
+} // namespace server
+} // namespace http
+
+#endif // HTTP_HEADER_HPP

Added: trunk/libs/asio/example/cpp11/http/server/main.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/main.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,43 @@
+//
+// main.cpp
+// ~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <iostream>
+#include <string>
+#include <boost/asio.hpp>
+#include "server.hpp"
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ // Check command line arguments.
+ if (argc != 4)
+ {
+ std::cerr << "Usage: http_server <address> <port> <doc_root>\n";
+ std::cerr << " For IPv4, try:\n";
+ std::cerr << " receiver 0.0.0.0 80 .\n";
+ std::cerr << " For IPv6, try:\n";
+ std::cerr << " receiver 0::0 80 .\n";
+ return 1;
+ }
+
+ // Initialise the server.
+ http::server::server s(argv[1], argv[2], argv[3]);
+
+ // Run the server until stopped.
+ s.run();
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}

Added: trunk/libs/asio/example/cpp11/http/server/mime_types.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/mime_types.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,45 @@
+//
+// mime_types.cpp
+// ~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include "mime_types.hpp"
+
+namespace http {
+namespace server {
+namespace mime_types {
+
+struct mapping
+{
+ const char* extension;
+ const char* mime_type;
+} mappings[] =
+{
+ { "gif", "image/gif" },
+ { "htm", "text/html" },
+ { "html", "text/html" },
+ { "jpg", "image/jpeg" },
+ { "png", "image/png" }
+};
+
+std::string extension_to_type(const std::string& extension)
+{
+ for (mapping m: mappings)
+ {
+ if (m.extension == extension)
+ {
+ return m.mime_type;
+ }
+ }
+
+ return "text/plain";
+}
+
+} // namespace mime_types
+} // namespace server
+} // namespace http

Added: trunk/libs/asio/example/cpp11/http/server/mime_types.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/mime_types.hpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,27 @@
+//
+// mime_types.hpp
+// ~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef HTTP_MIME_TYPES_HPP
+#define HTTP_MIME_TYPES_HPP
+
+#include <string>
+
+namespace http {
+namespace server {
+namespace mime_types {
+
+/// Convert a file extension into a MIME type.
+std::string extension_to_type(const std::string& extension);
+
+} // namespace mime_types
+} // namespace server
+} // namespace http
+
+#endif // HTTP_MIME_TYPES_HPP

Added: trunk/libs/asio/example/cpp11/http/server/reply.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/reply.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,255 @@
+//
+// reply.cpp
+// ~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include "reply.hpp"
+#include <string>
+
+namespace http {
+namespace server {
+
+namespace status_strings {
+
+const std::string ok =
+ "HTTP/1.0 200 OK\r\n";
+const std::string created =
+ "HTTP/1.0 201 Created\r\n";
+const std::string accepted =
+ "HTTP/1.0 202 Accepted\r\n";
+const std::string no_content =
+ "HTTP/1.0 204 No Content\r\n";
+const std::string multiple_choices =
+ "HTTP/1.0 300 Multiple Choices\r\n";
+const std::string moved_permanently =
+ "HTTP/1.0 301 Moved Permanently\r\n";
+const std::string moved_temporarily =
+ "HTTP/1.0 302 Moved Temporarily\r\n";
+const std::string not_modified =
+ "HTTP/1.0 304 Not Modified\r\n";
+const std::string bad_request =
+ "HTTP/1.0 400 Bad Request\r\n";
+const std::string unauthorized =
+ "HTTP/1.0 401 Unauthorized\r\n";
+const std::string forbidden =
+ "HTTP/1.0 403 Forbidden\r\n";
+const std::string not_found =
+ "HTTP/1.0 404 Not Found\r\n";
+const std::string internal_server_error =
+ "HTTP/1.0 500 Internal Server Error\r\n";
+const std::string not_implemented =
+ "HTTP/1.0 501 Not Implemented\r\n";
+const std::string bad_gateway =
+ "HTTP/1.0 502 Bad Gateway\r\n";
+const std::string service_unavailable =
+ "HTTP/1.0 503 Service Unavailable\r\n";
+
+boost::asio::const_buffer to_buffer(reply::status_type status)
+{
+ switch (status)
+ {
+ case reply::ok:
+ return boost::asio::buffer(ok);
+ case reply::created:
+ return boost::asio::buffer(created);
+ case reply::accepted:
+ return boost::asio::buffer(accepted);
+ case reply::no_content:
+ return boost::asio::buffer(no_content);
+ case reply::multiple_choices:
+ return boost::asio::buffer(multiple_choices);
+ case reply::moved_permanently:
+ return boost::asio::buffer(moved_permanently);
+ case reply::moved_temporarily:
+ return boost::asio::buffer(moved_temporarily);
+ case reply::not_modified:
+ return boost::asio::buffer(not_modified);
+ case reply::bad_request:
+ return boost::asio::buffer(bad_request);
+ case reply::unauthorized:
+ return boost::asio::buffer(unauthorized);
+ case reply::forbidden:
+ return boost::asio::buffer(forbidden);
+ case reply::not_found:
+ return boost::asio::buffer(not_found);
+ case reply::internal_server_error:
+ return boost::asio::buffer(internal_server_error);
+ case reply::not_implemented:
+ return boost::asio::buffer(not_implemented);
+ case reply::bad_gateway:
+ return boost::asio::buffer(bad_gateway);
+ case reply::service_unavailable:
+ return boost::asio::buffer(service_unavailable);
+ default:
+ return boost::asio::buffer(internal_server_error);
+ }
+}
+
+} // namespace status_strings
+
+namespace misc_strings {
+
+const char name_value_separator[] = { ':', ' ' };
+const char crlf[] = { '\r', '\n' };
+
+} // namespace misc_strings
+
+std::vector<boost::asio::const_buffer> reply::to_buffers()
+{
+ std::vector<boost::asio::const_buffer> buffers;
+ buffers.push_back(status_strings::to_buffer(status));
+ for (std::size_t i = 0; i < headers.size(); ++i)
+ {
+ header& h = headers[i];
+ buffers.push_back(boost::asio::buffer(h.name));
+ buffers.push_back(boost::asio::buffer(misc_strings::name_value_separator));
+ buffers.push_back(boost::asio::buffer(h.value));
+ buffers.push_back(boost::asio::buffer(misc_strings::crlf));
+ }
+ buffers.push_back(boost::asio::buffer(misc_strings::crlf));
+ buffers.push_back(boost::asio::buffer(content));
+ return buffers;
+}
+
+namespace stock_replies {
+
+const char ok[] = "";
+const char created[] =
+ "<html>"
+ "<head><title>Created</title></head>"
+ "<body><h1>201 Created</h1></body>"
+ "</html>";
+const char accepted[] =
+ "<html>"
+ "<head><title>Accepted</title></head>"
+ "<body><h1>202 Accepted</h1></body>"
+ "</html>";
+const char no_content[] =
+ "<html>"
+ "<head><title>No Content</title></head>"
+ "<body><h1>204 Content</h1></body>"
+ "</html>";
+const char multiple_choices[] =
+ "<html>"
+ "<head><title>Multiple Choices</title></head>"
+ "<body><h1>300 Multiple Choices</h1></body>"
+ "</html>";
+const char moved_permanently[] =
+ "<html>"
+ "<head><title>Moved Permanently</title></head>"
+ "<body><h1>301 Moved Permanently</h1></body>"
+ "</html>";
+const char moved_temporarily[] =
+ "<html>"
+ "<head><title>Moved Temporarily</title></head>"
+ "<body><h1>302 Moved Temporarily</h1></body>"
+ "</html>";
+const char not_modified[] =
+ "<html>"
+ "<head><title>Not Modified</title></head>"
+ "<body><h1>304 Not Modified</h1></body>"
+ "</html>";
+const char bad_request[] =
+ "<html>"
+ "<head><title>Bad Request</title></head>"
+ "<body><h1>400 Bad Request</h1></body>"
+ "</html>";
+const char unauthorized[] =
+ "<html>"
+ "<head><title>Unauthorized</title></head>"
+ "<body><h1>401 Unauthorized</h1></body>"
+ "</html>";
+const char forbidden[] =
+ "<html>"
+ "<head><title>Forbidden</title></head>"
+ "<body><h1>403 Forbidden</h1></body>"
+ "</html>";
+const char not_found[] =
+ "<html>"
+ "<head><title>Not Found</title></head>"
+ "<body><h1>404 Not Found</h1></body>"
+ "</html>";
+const char internal_server_error[] =
+ "<html>"
+ "<head><title>Internal Server Error</title></head>"
+ "<body><h1>500 Internal Server Error</h1></body>"
+ "</html>";
+const char not_implemented[] =
+ "<html>"
+ "<head><title>Not Implemented</title></head>"
+ "<body><h1>501 Not Implemented</h1></body>"
+ "</html>";
+const char bad_gateway[] =
+ "<html>"
+ "<head><title>Bad Gateway</title></head>"
+ "<body><h1>502 Bad Gateway</h1></body>"
+ "</html>";
+const char service_unavailable[] =
+ "<html>"
+ "<head><title>Service Unavailable</title></head>"
+ "<body><h1>503 Service Unavailable</h1></body>"
+ "</html>";
+
+std::string to_string(reply::status_type status)
+{
+ switch (status)
+ {
+ case reply::ok:
+ return ok;
+ case reply::created:
+ return created;
+ case reply::accepted:
+ return accepted;
+ case reply::no_content:
+ return no_content;
+ case reply::multiple_choices:
+ return multiple_choices;
+ case reply::moved_permanently:
+ return moved_permanently;
+ case reply::moved_temporarily:
+ return moved_temporarily;
+ case reply::not_modified:
+ return not_modified;
+ case reply::bad_request:
+ return bad_request;
+ case reply::unauthorized:
+ return unauthorized;
+ case reply::forbidden:
+ return forbidden;
+ case reply::not_found:
+ return not_found;
+ case reply::internal_server_error:
+ return internal_server_error;
+ case reply::not_implemented:
+ return not_implemented;
+ case reply::bad_gateway:
+ return bad_gateway;
+ case reply::service_unavailable:
+ return service_unavailable;
+ default:
+ return internal_server_error;
+ }
+}
+
+} // namespace stock_replies
+
+reply reply::stock_reply(reply::status_type status)
+{
+ reply rep;
+ rep.status = status;
+ rep.content = stock_replies::to_string(status);
+ rep.headers.resize(2);
+ rep.headers[0].name = "Content-Length";
+ rep.headers[0].value = std::to_string(rep.content.size());
+ rep.headers[1].name = "Content-Type";
+ rep.headers[1].value = "text/html";
+ return rep;
+}
+
+} // namespace server
+} // namespace http

Added: trunk/libs/asio/example/cpp11/http/server/reply.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/reply.hpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,64 @@
+//
+// reply.hpp
+// ~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef HTTP_REPLY_HPP
+#define HTTP_REPLY_HPP
+
+#include <string>
+#include <vector>
+#include <boost/asio.hpp>
+#include "header.hpp"
+
+namespace http {
+namespace server {
+
+/// A reply to be sent to a client.
+struct reply
+{
+ /// The status of the reply.
+ enum status_type
+ {
+ ok = 200,
+ created = 201,
+ accepted = 202,
+ no_content = 204,
+ multiple_choices = 300,
+ moved_permanently = 301,
+ moved_temporarily = 302,
+ not_modified = 304,
+ bad_request = 400,
+ unauthorized = 401,
+ forbidden = 403,
+ not_found = 404,
+ internal_server_error = 500,
+ not_implemented = 501,
+ bad_gateway = 502,
+ service_unavailable = 503
+ } status;
+
+ /// The headers to be included in the reply.
+ std::vector<header> headers;
+
+ /// The content to be sent in the reply.
+ std::string content;
+
+ /// Convert the reply into a vector of buffers. The buffers do not own the
+ /// underlying memory blocks, therefore the reply object must remain valid and
+ /// not be changed until the write operation has completed.
+ std::vector<boost::asio::const_buffer> to_buffers();
+
+ /// Get a stock reply.
+ static reply stock_reply(status_type status);
+};
+
+} // namespace server
+} // namespace http
+
+#endif // HTTP_REPLY_HPP

Added: trunk/libs/asio/example/cpp11/http/server/request.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/request.hpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,34 @@
+//
+// request.hpp
+// ~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef HTTP_REQUEST_HPP
+#define HTTP_REQUEST_HPP
+
+#include <string>
+#include <vector>
+#include "header.hpp"
+
+namespace http {
+namespace server {
+
+/// A request received from a client.
+struct request
+{
+ std::string method;
+ std::string uri;
+ int http_version_major;
+ int http_version_minor;
+ std::vector<header> headers;
+};
+
+} // namespace server
+} // namespace http
+
+#endif // HTTP_REQUEST_HPP

Added: trunk/libs/asio/example/cpp11/http/server/request_handler.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/request_handler.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,121 @@
+//
+// request_handler.cpp
+// ~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include "request_handler.hpp"
+#include <fstream>
+#include <sstream>
+#include <string>
+#include "mime_types.hpp"
+#include "reply.hpp"
+#include "request.hpp"
+
+namespace http {
+namespace server {
+
+request_handler::request_handler(const std::string& doc_root)
+ : doc_root_(doc_root)
+{
+}
+
+void request_handler::handle_request(const request& req, reply& rep)
+{
+ // Decode url to path.
+ std::string request_path;
+ if (!url_decode(req.uri, request_path))
+ {
+ rep = reply::stock_reply(reply::bad_request);
+ return;
+ }
+
+ // Request path must be absolute and not contain "..".
+ if (request_path.empty() || request_path[0] != '/'
+ || request_path.find("..") != std::string::npos)
+ {
+ rep = reply::stock_reply(reply::bad_request);
+ return;
+ }
+
+ // If path ends in slash (i.e. is a directory) then add "index.html".
+ if (request_path[request_path.size() - 1] == '/')
+ {
+ request_path += "index.html";
+ }
+
+ // Determine the file extension.
+ std::size_t last_slash_pos = request_path.find_last_of("/");
+ std::size_t last_dot_pos = request_path.find_last_of(".");
+ std::string extension;
+ if (last_dot_pos != std::string::npos && last_dot_pos > last_slash_pos)
+ {
+ extension = request_path.substr(last_dot_pos + 1);
+ }
+
+ // Open the file to send back.
+ std::string full_path = doc_root_ + request_path;
+ std::ifstream is(full_path.c_str(), std::ios::in | std::ios::binary);
+ if (!is)
+ {
+ rep = reply::stock_reply(reply::not_found);
+ return;
+ }
+
+ // Fill out the reply to be sent to the client.
+ rep.status = reply::ok;
+ char buf[512];
+ while (is.read(buf, sizeof(buf)).gcount() > 0)
+ rep.content.append(buf, is.gcount());
+ rep.headers.resize(2);
+ rep.headers[0].name = "Content-Length";
+ rep.headers[0].value = std::to_string(rep.content.size());
+ rep.headers[1].name = "Content-Type";
+ rep.headers[1].value = mime_types::extension_to_type(extension);
+}
+
+bool request_handler::url_decode(const std::string& in, std::string& out)
+{
+ out.clear();
+ out.reserve(in.size());
+ for (std::size_t i = 0; i < in.size(); ++i)
+ {
+ if (in[i] == '%')
+ {
+ if (i + 3 <= in.size())
+ {
+ int value = 0;
+ std::istringstream is(in.substr(i + 1, 2));
+ if (is >> std::hex >> value)
+ {
+ out += static_cast<char>(value);
+ i += 2;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else if (in[i] == '+')
+ {
+ out += ' ';
+ }
+ else
+ {
+ out += in[i];
+ }
+ }
+ return true;
+}
+
+} // namespace server
+} // namespace http

Added: trunk/libs/asio/example/cpp11/http/server/request_handler.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/request_handler.hpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,47 @@
+//
+// request_handler.hpp
+// ~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef HTTP_REQUEST_HANDLER_HPP
+#define HTTP_REQUEST_HANDLER_HPP
+
+#include <string>
+
+namespace http {
+namespace server {
+
+struct reply;
+struct request;
+
+/// The common handler for all incoming requests.
+class request_handler
+{
+public:
+ request_handler(const request_handler&) = delete;
+ request_handler& operator=(const request_handler&) = delete;
+
+ /// Construct with a directory containing files to be served.
+ explicit request_handler(const std::string& doc_root);
+
+ /// Handle a request and produce a reply.
+ void handle_request(const request& req, reply& rep);
+
+private:
+ /// The directory containing the files to be served.
+ std::string doc_root_;
+
+ /// Perform URL-decoding on a string. Returns false if the encoding was
+ /// invalid.
+ static bool url_decode(const std::string& in, std::string& out);
+};
+
+} // namespace server
+} // namespace http
+
+#endif // HTTP_REQUEST_HANDLER_HPP

Added: trunk/libs/asio/example/cpp11/http/server/request_parser.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/request_parser.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,315 @@
+//
+// request_parser.cpp
+// ~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include "request_parser.hpp"
+#include "request.hpp"
+
+namespace http {
+namespace server {
+
+request_parser::request_parser()
+ : state_(method_start)
+{
+}
+
+void request_parser::reset()
+{
+ state_ = method_start;
+}
+
+request_parser::result_type request_parser::consume(request& req, char input)
+{
+ switch (state_)
+ {
+ case method_start:
+ if (!is_char(input) || is_ctl(input) || is_tspecial(input))
+ {
+ return bad;
+ }
+ else
+ {
+ state_ = method;
+ req.method.push_back(input);
+ return indeterminate;
+ }
+ case method:
+ if (input == ' ')
+ {
+ state_ = uri;
+ return indeterminate;
+ }
+ else if (!is_char(input) || is_ctl(input) || is_tspecial(input))
+ {
+ return bad;
+ }
+ else
+ {
+ req.method.push_back(input);
+ return indeterminate;
+ }
+ case uri:
+ if (input == ' ')
+ {
+ state_ = http_version_h;
+ return indeterminate;
+ }
+ else if (is_ctl(input))
+ {
+ return bad;
+ }
+ else
+ {
+ req.uri.push_back(input);
+ return indeterminate;
+ }
+ case http_version_h:
+ if (input == 'H')
+ {
+ state_ = http_version_t_1;
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case http_version_t_1:
+ if (input == 'T')
+ {
+ state_ = http_version_t_2;
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case http_version_t_2:
+ if (input == 'T')
+ {
+ state_ = http_version_p;
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case http_version_p:
+ if (input == 'P')
+ {
+ state_ = http_version_slash;
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case http_version_slash:
+ if (input == '/')
+ {
+ req.http_version_major = 0;
+ req.http_version_minor = 0;
+ state_ = http_version_major_start;
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case http_version_major_start:
+ if (is_digit(input))
+ {
+ req.http_version_major = req.http_version_major * 10 + input - '0';
+ state_ = http_version_major;
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case http_version_major:
+ if (input == '.')
+ {
+ state_ = http_version_minor_start;
+ return indeterminate;
+ }
+ else if (is_digit(input))
+ {
+ req.http_version_major = req.http_version_major * 10 + input - '0';
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case http_version_minor_start:
+ if (is_digit(input))
+ {
+ req.http_version_minor = req.http_version_minor * 10 + input - '0';
+ state_ = http_version_minor;
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case http_version_minor:
+ if (input == '\r')
+ {
+ state_ = expecting_newline_1;
+ return indeterminate;
+ }
+ else if (is_digit(input))
+ {
+ req.http_version_minor = req.http_version_minor * 10 + input - '0';
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case expecting_newline_1:
+ if (input == '\n')
+ {
+ state_ = header_line_start;
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case header_line_start:
+ if (input == '\r')
+ {
+ state_ = expecting_newline_3;
+ return indeterminate;
+ }
+ else if (!req.headers.empty() && (input == ' ' || input == '\t'))
+ {
+ state_ = header_lws;
+ return indeterminate;
+ }
+ else if (!is_char(input) || is_ctl(input) || is_tspecial(input))
+ {
+ return bad;
+ }
+ else
+ {
+ req.headers.push_back(header());
+ req.headers.back().name.push_back(input);
+ state_ = header_name;
+ return indeterminate;
+ }
+ case header_lws:
+ if (input == '\r')
+ {
+ state_ = expecting_newline_2;
+ return indeterminate;
+ }
+ else if (input == ' ' || input == '\t')
+ {
+ return indeterminate;
+ }
+ else if (is_ctl(input))
+ {
+ return bad;
+ }
+ else
+ {
+ state_ = header_value;
+ req.headers.back().value.push_back(input);
+ return indeterminate;
+ }
+ case header_name:
+ if (input == ':')
+ {
+ state_ = space_before_header_value;
+ return indeterminate;
+ }
+ else if (!is_char(input) || is_ctl(input) || is_tspecial(input))
+ {
+ return bad;
+ }
+ else
+ {
+ req.headers.back().name.push_back(input);
+ return indeterminate;
+ }
+ case space_before_header_value:
+ if (input == ' ')
+ {
+ state_ = header_value;
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case header_value:
+ if (input == '\r')
+ {
+ state_ = expecting_newline_2;
+ return indeterminate;
+ }
+ else if (is_ctl(input))
+ {
+ return bad;
+ }
+ else
+ {
+ req.headers.back().value.push_back(input);
+ return indeterminate;
+ }
+ case expecting_newline_2:
+ if (input == '\n')
+ {
+ state_ = header_line_start;
+ return indeterminate;
+ }
+ else
+ {
+ return bad;
+ }
+ case expecting_newline_3:
+ return (input == '\n') ? good : bad;
+ default:
+ return bad;
+ }
+}
+
+bool request_parser::is_char(int c)
+{
+ return c >= 0 && c <= 127;
+}
+
+bool request_parser::is_ctl(int c)
+{
+ return (c >= 0 && c <= 31) || (c == 127);
+}
+
+bool request_parser::is_tspecial(int c)
+{
+ switch (c)
+ {
+ case '(': case ')': case '<': case '>': case '@':
+ case ',': case ';': case ':': case '\\': case '"':
+ case '/': case '[': case ']': case '?': case '=':
+ case '{': case '}': case ' ': case '\t':
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool request_parser::is_digit(int c)
+{
+ return c >= '0' && c <= '9';
+}
+
+} // namespace server
+} // namespace http

Added: trunk/libs/asio/example/cpp11/http/server/request_parser.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/request_parser.hpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,96 @@
+//
+// request_parser.hpp
+// ~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef HTTP_REQUEST_PARSER_HPP
+#define HTTP_REQUEST_PARSER_HPP
+
+#include <tuple>
+
+namespace http {
+namespace server {
+
+struct request;
+
+/// Parser for incoming requests.
+class request_parser
+{
+public:
+ /// Construct ready to parse the request method.
+ request_parser();
+
+ /// Reset to initial parser state.
+ void reset();
+
+ /// Result of parse.
+ enum result_type { good, bad, indeterminate };
+
+ /// Parse some data. The enum return value is good when a complete request has
+ /// been parsed, bad if the data is invalid, indeterminate when more data is
+ /// required. The InputIterator return value indicates how much of the input
+ /// has been consumed.
+ template <typename InputIterator>
+ std::tuple<result_type, InputIterator> parse(request& req,
+ InputIterator begin, InputIterator end)
+ {
+ while (begin != end)
+ {
+ result_type result = consume(req, *begin++);
+ if (result == good || result == bad)
+ return std::make_tuple(result, begin);
+ }
+ return std::make_tuple(indeterminate, begin);
+ }
+
+private:
+ /// Handle the next character of input.
+ result_type consume(request& req, char input);
+
+ /// Check if a byte is an HTTP character.
+ static bool is_char(int c);
+
+ /// Check if a byte is an HTTP control character.
+ static bool is_ctl(int c);
+
+ /// Check if a byte is defined as an HTTP tspecial character.
+ static bool is_tspecial(int c);
+
+ /// Check if a byte is a digit.
+ static bool is_digit(int c);
+
+ /// The current state of the parser.
+ enum state
+ {
+ method_start,
+ method,
+ uri,
+ http_version_h,
+ http_version_t_1,
+ http_version_t_2,
+ http_version_p,
+ http_version_slash,
+ http_version_major_start,
+ http_version_major,
+ http_version_minor_start,
+ http_version_minor,
+ expecting_newline_1,
+ header_line_start,
+ header_lws,
+ header_name,
+ space_before_header_value,
+ header_value,
+ expecting_newline_2,
+ expecting_newline_3
+ } state_;
+};
+
+} // namespace server
+} // namespace http
+
+#endif // HTTP_REQUEST_PARSER_HPP

Added: trunk/libs/asio/example/cpp11/http/server/server.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/server.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,94 @@
+//
+// server.cpp
+// ~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include "server.hpp"
+#include <signal.h>
+#include <utility>
+
+namespace http {
+namespace server {
+
+server::server(const std::string& address, const std::string& port,
+ const std::string& doc_root)
+ : io_service_(),
+ signals_(io_service_),
+ acceptor_(io_service_),
+ connection_manager_(),
+ socket_(io_service_),
+ request_handler_(doc_root)
+{
+ // Register to handle the signals that indicate when the server should exit.
+ // It is safe to register for the same signal multiple times in a program,
+ // provided all registration for the specified signal is made through Asio.
+ signals_.add(SIGINT);
+ signals_.add(SIGTERM);
+#if defined(SIGQUIT)
+ signals_.add(SIGQUIT);
+#endif // defined(SIGQUIT)
+
+ do_await_stop();
+
+ // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
+ boost::asio::ip::tcp::resolver resolver(io_service_);
+ boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve({address, port});
+ acceptor_.open(endpoint.protocol());
+ acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
+ acceptor_.bind(endpoint);
+ acceptor_.listen();
+
+ do_accept();
+}
+
+void server::run()
+{
+ // The io_service::run() call will block until all asynchronous operations
+ // have finished. While the server is running, there is always at least one
+ // asynchronous operation outstanding: the asynchronous accept call waiting
+ // for new incoming connections.
+ io_service_.run();
+}
+
+void server::do_accept()
+{
+ acceptor_.async_accept(socket_,
+ [this](boost::system::error_code ec)
+ {
+ // Check whether the server was stopped by a signal before this
+ // completion handler had a chance to run.
+ if (!acceptor_.is_open())
+ {
+ return;
+ }
+
+ if (!ec)
+ {
+ connection_manager_.start(std::make_shared<connection>(
+ std::move(socket_), connection_manager_, request_handler_));
+ }
+
+ do_accept();
+ });
+}
+
+void server::do_await_stop()
+{
+ signals_.async_wait(
+ [this](boost::system::error_code /*ec*/, int /*signo*/)
+ {
+ // The server is stopped by cancelling all outstanding asynchronous
+ // operations. Once all operations have finished the io_service::run()
+ // call will exit.
+ acceptor_.close();
+ connection_manager_.stop_all();
+ });
+}
+
+} // namespace server
+} // namespace http

Added: trunk/libs/asio/example/cpp11/http/server/server.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/http/server/server.hpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,67 @@
+//
+// server.hpp
+// ~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef HTTP_SERVER_HPP
+#define HTTP_SERVER_HPP
+
+#include <boost/asio.hpp>
+#include <string>
+#include "connection.hpp"
+#include "connection_manager.hpp"
+#include "request_handler.hpp"
+
+namespace http {
+namespace server {
+
+/// The top-level class of the HTTP server.
+class server
+{
+public:
+ server(const server&) = delete;
+ server& operator=(const server&) = delete;
+
+ /// Construct the server to listen on the specified TCP address and port, and
+ /// serve up files from the given directory.
+ explicit server(const std::string& address, const std::string& port,
+ const std::string& doc_root);
+
+ /// Run the server's io_service loop.
+ void run();
+
+private:
+ /// Perform an asynchronous accept operation.
+ void do_accept();
+
+ /// Wait for a request to stop the server.
+ void do_await_stop();
+
+ /// The io_service used to perform asynchronous operations.
+ boost::asio::io_service io_service_;
+
+ /// The signal_set is used to register for process termination notifications.
+ boost::asio::signal_set signals_;
+
+ /// Acceptor used to listen for incoming connections.
+ boost::asio::ip::tcp::acceptor acceptor_;
+
+ /// The connection manager which owns all live connections.
+ connection_manager connection_manager_;
+
+ /// The next socket to be accepted.
+ boost::asio::ip::tcp::socket socket_;
+
+ /// The handler for all incoming requests.
+ request_handler request_handler_;
+};
+
+} // namespace server
+} // namespace http
+
+#endif // HTTP_SERVER_HPP

Added: trunk/libs/asio/example/cpp11/spawn/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/spawn/Jamfile.v2 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+
+import os ;
+
+if [ os.name ] = SOLARIS
+{
+ lib socket ;
+ lib nsl ;
+}
+else if [ os.name ] = NT
+{
+ lib ws2_32 ;
+ lib mswsock ;
+}
+else if [ os.name ] = HPUX
+{
+ lib ipv6 ;
+}
+
+exe server
+ : echo_server.cpp
+ /boost/context//boost_context
+ /boost/coroutine//boost_coroutine
+ /boost/system//boost_system
+ : <define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+ <os>SOLARIS:<library>socket
+ <os>SOLARIS:<library>nsl
+ <os>NT:<define>_WIN32_WINNT=0x0501
+ <os>NT,<toolset>gcc:<library>ws2_32
+ <os>NT,<toolset>gcc:<library>mswsock
+ <os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
+ <os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
+ <os>HPUX:<library>ipv6
+ ;

Added: trunk/libs/asio/example/cpp11/spawn/echo_server.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/cpp11/spawn/echo_server.cpp 2013-05-16 22:25:10 EDT (Thu, 16 May 2013)
@@ -0,0 +1,108 @@
+//
+// echo_server.cpp
+// ~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <boost/asio/io_service.hpp>
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/asio/spawn.hpp>
+#include <boost/asio/steady_timer.hpp>
+#include <boost/asio/write.hpp>
+#include <iostream>
+#include <memory>
+
+using boost::asio::ip::tcp;
+
+class session : public std::enable_shared_from_this<session>
+{
+public:
+ explicit session(tcp::socket socket)
+ : socket_(std::move(socket)),
+ timer_(socket_.get_io_service()),
+ strand_(socket_.get_io_service())
+ {
+ }
+
+ void go()
+ {
+ auto self(shared_from_this());
+ boost::asio::spawn(strand_,
+ [this, self](boost::asio::yield_context yield)
+ {
+ try
+ {
+ char data[128];
+ for (;;)
+ {
+ timer_.expires_from_now(std::chrono::seconds(10));
+ std::size_t n = socket_.async_read_some(boost::asio::buffer(data), yield);
+ boost::asio::async_write(socket_, boost::asio::buffer(data, n), yield);
+ }
+ }
+ catch (std::exception& e)
+ {
+ socket_.close();
+ timer_.cancel();
+ }
+ });
+
+ boost::asio::spawn(strand_,
+ [this, self](boost::asio::yield_context yield)
+ {
+ while (socket_.is_open())
+ {
+ boost::system::error_code ignored_ec;
+ timer_.async_wait(yield[ignored_ec]);
+ if (timer_.expires_from_now() <= std::chrono::seconds(0))
+ socket_.close();
+ }
+ });
+ }
+
+private:
+ tcp::socket socket_;
+ boost::asio::steady_timer timer_;
+ boost::asio::io_service::strand strand_;
+};
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if (argc != 2)
+ {
+ std::cerr << "Usage: echo_server <port>\n";
+ return 1;
+ }
+
+ boost::asio::io_service io_service;
+
+ boost::asio::spawn(io_service,
+ [&](boost::asio::yield_context yield)
+ {
+ tcp::acceptor acceptor(io_service,
+ tcp::endpoint(tcp::v4(), std::atoi(argv[1])));
+
+ for (;;)
+ {
+ boost::system::error_code ec;
+ tcp::socket socket(io_service);
+ acceptor.async_accept(socket, yield[ec]);
+ if (!ec) std::make_shared<session>(std::move(socket))->go();
+ }
+ });
+
+ io_service.run();
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Exception: " << e.what() << "\n";
+ }
+
+ return 0;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk