2
0
mirror of https://github.com/boostorg/asio.git synced 2026-01-28 18:52:09 +00:00
Commit Graph

17 Commits

Author SHA1 Message Date
Christopher Kohlhoff
603397befb Merge from trunk.
------------------------------------------------------------------------
r84301 | chris_kohlhoff | 2013-05-17 07:34:54 +1000 (Fri, 17 May 2013) | 2 lines

Enable handler type requirements static_assert on clang.

------------------------------------------------------------------------
r84308 | chris_kohlhoff | 2013-05-17 09:26:04 +1000 (Fri, 17 May 2013) | 3 lines

Add new traits classes, handler_type and async_result, that allow
the customisation of the return type of an initiating function.

------------------------------------------------------------------------
r84311 | chris_kohlhoff | 2013-05-17 11:38:47 +1000 (Fri, 17 May 2013) | 81 lines

Add the asio::spawn() function, a high-level wrapper for running
stackful coroutines. It is based on the Boost.Coroutine library.

Here is an example of its use:

  asio::spawn(my_strand, do_echo);

  // ...

  void do_echo(asio::yield_context yield)
  {
    try
    {
      char data[128];
      for (;;)
      {
        std::size_t length =
          my_socket.async_read_some(
            asio::buffer(data), yield);

        asio::async_write(my_socket,
            asio::buffer(data, length), yield);
      }
    }
    catch (std::exception& e)
    {
      // ...
    }
  }

The first argument to asio::spawn() may be a strand, io_service or
completion handler. This argument determines the context in which the
coroutine is permitted to execute. For example, a server's per-client
object may consist of multiple coroutines; they should all run on the
same strand so that no explicit synchronisation is required.

The second argument is a function object with signature (**):

  void coroutine(asio::yield_context yield);

that specifies the code to be run as part of the coroutine. The
parameter yield may be passed to an asynchronous operation in place of
the completion handler, as in:

  std::size_t length =
    my_socket.async_read_some(
      asio::buffer(data), yield);

This starts the asynchronous operation and suspends the coroutine. The
coroutine will be resumed automatically when the asynchronous operation
completes.

Where a completion handler signature has the form:

  void handler(error_code ec, result_type result);

the initiating function returns the result_type. In the async_read_some
example above, this is std::size_t. If the asynchronous operation fails,
the error_code is converted into a system_error exception and thrown.

Where a completion handler signature has the form:

  void handler(error_code ec);

the initiating function returns void. As above, an error is passed back
to the coroutine as a system_error exception.

To collect the error_code from an operation, rather than have it throw
an exception, associate the output variable with the yield_context as
follows:

  error_code ec;
  std::size_t length =
    my_socket.async_read_some(
      asio::buffer(data), yield[ec]);

**Note: if asio::spawn() is used with a custom completion handler of
type Handler, the function object signature is actually:
  
  void coroutine(asio::basic_yield_context<Handler> yield);

------------------------------------------------------------------------
r84312 | chris_kohlhoff | 2013-05-17 12:25:10 +1000 (Fri, 17 May 2013) | 4 lines

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.

------------------------------------------------------------------------
r84313 | chris_kohlhoff | 2013-05-17 12:35:08 +1000 (Fri, 17 May 2013) | 26 lines

Add the asio::use_future special value, which adds first-class support
for returning a C++11 std::future from an asynchronous operation's
initiating function.

To use asio::use_future, pass it to an asynchronous operation instead of
a normal completion handler. For example:

  std::future<std::size_t> length =
    my_socket.async_read_some(my_buffer, asio::use_future);

Where a completion handler signature has the form:

  void handler(error_code ec, result_type result);

the initiating function returns a std::future templated on result_type.
In the above example, this is std::size_t. If the asynchronous operation
fails, the error_code is converted into a system_error exception and
passed back to the caller through the future.

Where a completion handler signature has the form:

  void handler(error_code ec);

the initiating function returns std::future<void>. As above, an error
is passed back in the future as a system_error exception.

------------------------------------------------------------------------
r84314 | chris_kohlhoff | 2013-05-17 13:07:51 +1000 (Fri, 17 May 2013) | 27 lines

Add a new handler hook called asio_handler_is_continuation.

Asynchronous operations may represent a continuation of the asynchronous
control flow associated with the current handler. Asio's implementation
can use this knowledge to optimise scheduling of the handler.

The asio_handler_is_continuation hook returns true to indicate whether a
completion handler represents a continuation of the current call
context. The default implementation of the hook returns false, and
applications may customise the hook when necessary. The hook has already
been customised within Asio to return true for the following cases:

- Handlers returned by strand.wrap(), when the corresponding
  asynchronous operation is being initiated from within the strand.

- The internal handlers used to implement the asio::spawn() function's
  stackful coroutines.

- When an intermediate handler of a composed operation (e.g.
  asio::async_read(), asio::async_write(), asio::async_connect(),
  ssl::stream<>, etc.) starts a new asynchronous operation due to the
  composed operation not being complete.

To support this optimisation, a new running_in_this_thread() member
function has been added to the io_service::strand class. This function
returns true when called from within a strand.

------------------------------------------------------------------------
r84315 | chris_kohlhoff | 2013-05-17 20:06:50 +1000 (Fri, 17 May 2013) | 3 lines

Partially decouple Asio from other boost components via an extra level
of indirection.

------------------------------------------------------------------------
r84316 | chris_kohlhoff | 2013-05-17 20:15:21 +1000 (Fri, 17 May 2013) | 2 lines

Minor cleanup.

------------------------------------------------------------------------
r84319 | chris_kohlhoff | 2013-05-17 20:52:08 +1000 (Fri, 17 May 2013) | 9 lines

Support handshake with re-use of data already read from the wire.

Add new overloads of the SSL stream's handshake() and async_handshake()
functions, that accepts a ConstBufferSequence to be used as initial
input to the ssl engine for the handshake procedure.

Thanks go to Nick Jones <nick dot fa dot jones at gmail dot com>, on
whose work this commit is partially based.

------------------------------------------------------------------------
r84320 | chris_kohlhoff | 2013-05-17 20:57:02 +1000 (Fri, 17 May 2013) | 6 lines

Support for creation of TLSv1.1 and TLSv1.2 contexts.

Thanks go to Alvin Cheung <alvin dot cheung at alumni dot ust dot hk>
and Nick Jones <nick dot fa dot jones at gmail dot com>, on whose work
this is based.

------------------------------------------------------------------------
r84322 | chris_kohlhoff | 2013-05-17 21:00:49 +1000 (Fri, 17 May 2013) | 5 lines

Add set_verify_depth function to SSL context and stream.

Thanks go to Nick Jones <nick dot fa dot jones at gmail dot com>, on
whose work this commit is based.

------------------------------------------------------------------------
r84325 | chris_kohlhoff | 2013-05-17 21:04:11 +1000 (Fri, 17 May 2013) | 9 lines

Allow loading of SSL certificate and key data from memory buffers.

Added new buffer-based interfaces:
add_certificate_authority, use_certificate, use_certificate_chain,
use_private_key, use_rsa_private_key, use_tmp_dh.

Thanks go to Nick Jones <nick dot fa dot jones at gmail dot com>, on
whose work this commit is based.

------------------------------------------------------------------------
r84345 | chris_kohlhoff | 2013-05-18 21:24:59 +1000 (Sat, 18 May 2013) | 2 lines

Update copyright notices.

------------------------------------------------------------------------
r84346 | chris_kohlhoff | 2013-05-18 21:54:59 +1000 (Sat, 18 May 2013) | 3 lines

Remove the stackless coroutine class and macros from the HTTP server 4
example, and instead make them a part of Asio's documented interface.

------------------------------------------------------------------------
r84347 | chris_kohlhoff | 2013-05-18 22:01:59 +1000 (Sat, 18 May 2013) | 4 lines

Fix basic_waitable_timer's underlying implementation so that it can
handle any time_point value without overflowing the intermediate
duration objects.

------------------------------------------------------------------------
r84348 | chris_kohlhoff | 2013-05-18 22:07:00 +1000 (Sat, 18 May 2013) | 3 lines

Fix a problem with lost thread wakeups that can occur when making
concurrent calls to run() and poll() on the same io_service object.

------------------------------------------------------------------------
r84349 | chris_kohlhoff | 2013-05-18 22:13:17 +1000 (Sat, 18 May 2013) | 3 lines

Fix implementation of asynchronous connect operation so that it can cope
with spurious readiness notifications from the reactor.

------------------------------------------------------------------------
r84361 | chris_kohlhoff | 2013-05-19 07:56:31 +1000 (Sun, 19 May 2013) | 1 line

Remove some trailing spaces and fix another copyright notice.

------------------------------------------------------------------------
r84363 | chris_kohlhoff | 2013-05-19 14:55:11 +1000 (Sun, 19 May 2013) | 53 lines

Add generic socket protocols and converting move constructors.

Four new protocol classes have been added:

- asio::generic::datagram_protocol
- asio::generic::raw_protocol
- asio::generic::seq_packet_protocol
- asio::generic::stream_protocol

These classes implement the Protocol type requirements, but allow the
user to specify the address family (e.g. AF_INET) and protocol type
(e.g. IPPROTO_TCP) at runtime.

A new endpoint class template, asio::generic::basic_endpoint, has been
added to support these new protocol classes. This endpoint can hold any
other endpoint type, provided its native representation fits into a
sockaddr_storage object.

When using C++11, it is now possible to perform move construction from a
socket (or acceptor) object to convert to the more generic protocol's
socket (or acceptor) type. If the protocol conversion is valid:

  Protocol1 p1 = ...;
  Protocol2 p2(p1);

then the corresponding socket conversion is allowed:

  Protocol1::socket socket1(io_service);
  ...
  Protocol2::socket socket2(std::move(socket1));

For example, one possible conversion is from a TCP socket to a generic
stream-oriented socket:

  asio::ip::tcp::socket socket1(io_service);
  ...
  asio::generic::stream_protocol::socket socket2(std::move(socket1));

The conversion is also available for move-assignment. Note that these
conversions are not limited to the newly added generic protocol classes.
User-defined protocols may take advantage of this feature by similarly
ensuring the conversion from Protocol1 to Protocol2 is valid, as above.

As a convenience, the socket acceptor's accept() and async_accept()
functions have been changed so that they can directly accept into a
different protocol's socket type, provided the protocol conversion is
valid. For example, the following is now possible:

  asio::ip::tcp::acceptor acceptor(io_service);
  ...
  asio::generic::stream_protocol::socket socket1(io_service);
  acceptor.accept(socket1);


[SVN r84388]
2013-05-20 12:32:20 +00:00
Christopher Kohlhoff
bb38d425fb Merge from trunk:
* Chrono support.

* Added object_handle support.

* Need to enable the basic_handle class when object_handle is supported.

* Update copyright notices.

* Fix MSVC "performance warning".

* Fix for NetBSD. Fixes #6098.

* Fix regression in buffered_write_stream. Fixes #6310.

* Fix deadlock on Mac OS X. Fixes #6275.

* On linux, connect can return EAGAIN in certain circumstances. Remap to another
  error so that it doesn't look like a non-blocking operation. Fixes #6048.

* Fix non-paged pool "leak" on Windows when io_service is repeatedly run without anything to do. Fixes #6321.

* Disable object_handle on Windows CE.

* Add extra include required for OVERLAPPED struct.

* Fix doxygen comments.

* Update documentation.

* Add missing class.

* Update copyright year.


[SVN r76516]
2012-01-15 13:46:25 +00:00
Christopher Kohlhoff
77dec8e703 Merge from trunk...
Fix compile error in regex overload of async_read_until.hpp. Fixes #5688

Explicitly specify the signal() function from the global namespace. Fixes #5722

Don't read the clock unless the heap is non-empty.

Change the SSL buffers sizes so that they're large enough to hold a complete TLS record. Fixes #5854

Make sure the synchronous null_buffers operations obey the user's non_blocking setting. Fixes #5756

Set size of select fd_set at runtime when using Windows.

Disable warning due to const qualifier being applied to function type.

Fix crash due to gcc_x86_fenced_block that shows up when using the Intel C++ compiler. Fixes #5763

Specialise operations for buffer sequences that are arrays of exactly two buffers.

Initialise all OpenSSL algorithms.

Fix error mapping when session is gracefully shut down.

Various performance improvements:

* Split the task_io_service's run and poll code.

* Use thread-local operation queues in single-threaded use cases (i.e. concurrency_hint is 1) to eliminate a lock/unlock pair.

* Only fence block exit when a handler is being run directly out of the io_service.

* Prefer x86 mfence-based fenced block when available.

* Use a plain ol' long for the atomic_count when all thread support is disabled.

* Allow some epoll_reactor speculative operations to be performed without holding the lock.

* Improve locality of reference by performing an epoll_reactor's I/O operation immediately before the corresponding handler is called. This also improves scalability across CPUs when multiple threads are running the io_service.

* Pass same error_code variable through to each operation's complete() function.

* Optimise creation of and access to the io_service implementation.

Remove unused state in HTTP server examples.

Add latency test programs.


[SVN r74863]
2011-10-09 21:59:57 +00:00
Christopher Kohlhoff
28ab37a23e Merge from trunk:
* Update copyright notice.

* Version bump.

* Fix out-of-bounds address_v4::broadcast() return value on 64-bit systems.

* Use correct interrupt method when timerfd is not available. Fixes #5045


[SVN r68200]
2011-01-17 04:28:16 +00:00
Christopher Kohlhoff
df91035ff5 Update copyright notices.
[SVN r58666]
2010-01-04 09:36:00 +00:00
Christopher Kohlhoff
8e413b0ece Merge from trunk.
........
  r48414 | chris_kohlhoff | 2008-08-28 22:03:46 +1000 (Thu, 28 Aug 2008) | 2 lines
  
  Fix uninitialised event handles in asio::detail::thread in external mode.
........
  r48415 | chris_kohlhoff | 2008-08-28 22:04:21 +1000 (Thu, 28 Aug 2008) | 2 lines
  
  Fix duplicate variable warning.
........
  r48416 | chris_kohlhoff | 2008-08-28 22:06:42 +1000 (Thu, 28 Aug 2008) | 3 lines
  
  Fix duplicate variable warning. Use get_io_service() rather than
  deprecated io_service() function.
........
  r48417 | chris_kohlhoff | 2008-08-28 22:09:09 +1000 (Thu, 28 Aug 2008) | 2 lines
  
  Use get_io_service() rather than deprecated io_service() function.
........
  r48418 | chris_kohlhoff | 2008-08-28 22:11:47 +1000 (Thu, 28 Aug 2008) | 9 lines
  
  Change the CompletionCondition concept so that:
  - It is now evaluated before the first call to the underlying
    *_some() operation, as well as after every operation.
  - The return value is a number of bytes, which indicates the maximum
    length to be transferred on the subsequent *_some() operation. If
    the return value is 0 then the composed operation completes.
  
  Add missing unit tests for read_at and write_at.
........
  r48490 | chris_kohlhoff | 2008-08-31 18:58:49 +1000 (Sun, 31 Aug 2008) | 2 lines
  
  Don't build serial port test code when serial ports are not available.
........
  r48491 | chris_kohlhoff | 2008-08-31 19:01:59 +1000 (Sun, 31 Aug 2008) | 3 lines
  
  Refactor reactive socket implementation so that synchronous read, write,
  accept and connect operations don't modify data associated with the socket.
........
  r48495 | chris_kohlhoff | 2008-08-31 21:38:52 +1000 (Sun, 31 Aug 2008) | 2 lines
  
  Add class to allow use of arbitrary Windows overlapped I/O operations.
........
  r48524 | chris_kohlhoff | 2008-09-02 09:04:35 +1000 (Tue, 02 Sep 2008) | 3 lines
  
  Add support for using an eventfd descriptor on linux to interrupt a blocked
  epoll/select reactor.
........
  r48525 | chris_kohlhoff | 2008-09-02 09:05:05 +1000 (Tue, 02 Sep 2008) | 3 lines
  
  Use templates to handle iovec structures that have an iov_base member of
  type char*.
........
  r48526 | chris_kohlhoff | 2008-09-02 09:07:29 +1000 (Tue, 02 Sep 2008) | 2 lines
  
  Fix error in comment.
........
  r48527 | chris_kohlhoff | 2008-09-02 18:46:46 +1000 (Tue, 02 Sep 2008) | 2 lines
  
  Fix to compile with MSVC 7.1.
........
  r48535 | chris_kohlhoff | 2008-09-02 21:34:18 +1000 (Tue, 02 Sep 2008) | 2 lines
  
  Add const overloads of the lowest_layer member functions.
........
  r48558 | chris_kohlhoff | 2008-09-03 18:56:43 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Oops, changeset 48535 accidentally reverted 48527's fix.
........
  r48559 | chris_kohlhoff | 2008-09-03 18:57:48 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Add a workaround for a possible gcc 4.3 optimiser bug.
........
  r48560 | chris_kohlhoff | 2008-09-03 19:06:10 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Explicitly specify return type with bind to keep some compilers happy.
........
  r48561 | chris_kohlhoff | 2008-09-03 19:08:04 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Update completion_condition documentation to match new signature.
........
  r48562 | chris_kohlhoff | 2008-09-03 21:36:43 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Add windows/transmit_file example.
........
  r48563 | chris_kohlhoff | 2008-09-03 21:46:02 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Document BOOST_ASIO_DISABLE_EVENTFD macro.
........
  r48564 | chris_kohlhoff | 2008-09-03 21:54:06 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Add windows::overlapped_ptr to the reference index page.
........
  r48565 | chris_kohlhoff | 2008-09-03 22:28:07 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Regenerate documentation.
........
  r48683 | chris_kohlhoff | 2008-09-09 22:59:43 +1000 (Tue, 09 Sep 2008) | 2 lines
  
  Add windows example directory.
........
  r48684 | chris_kohlhoff | 2008-09-09 23:00:07 +1000 (Tue, 09 Sep 2008) | 2 lines
  
  Remove generated tags file.
........
  r48685 | chris_kohlhoff | 2008-09-09 23:01:16 +1000 (Tue, 09 Sep 2008) | 2 lines
  
  Version bump.
........
  r48686 | chris_kohlhoff | 2008-09-09 23:02:22 +1000 (Tue, 09 Sep 2008) | 2 lines
  
  Handle SSL library errors.
........
  r48715 | chris_kohlhoff | 2008-09-11 10:05:57 +1000 (Thu, 11 Sep 2008) | 2 lines
  
  Clarify which resolve functions perform forward or reverse resolution.
........


[SVN r49194]
2008-10-09 05:41:50 +00:00
Christopher Kohlhoff
ffd222435e Merge bug and doc fixes from trunk.
........
  r46535 | chris_kohlhoff | 2008-06-20 10:25:50 +1000 (Fri, 20 Jun 2008) | 2 lines
  
  One more check needed for BSD serial port extensions.
........
  r46766 | chris_kohlhoff | 2008-06-27 15:38:16 +1000 (Fri, 27 Jun 2008) | 2 lines
  
  Add missing copyright notices.
........
  r46876 | chris_kohlhoff | 2008-06-30 10:24:44 +1000 (Mon, 30 Jun 2008) | 2 lines
  
  Some linux configurations do not automatically define _XOPEN_SOURCE.
........
  r46944 | chris_kohlhoff | 2008-07-01 21:52:54 +1000 (Tue, 01 Jul 2008) | 2 lines
  
  Fix documentation on behaviour when a connect operation fails.
........
  r46945 | chris_kohlhoff | 2008-07-01 21:53:54 +1000 (Tue, 01 Jul 2008) | 2 lines
  
  Fix name of parameter as referred to in documentation.
........
  r46946 | chris_kohlhoff | 2008-07-01 21:58:39 +1000 (Tue, 01 Jul 2008) | 2 lines
  
  Fix typos.
........
  r46947 | chris_kohlhoff | 2008-07-01 21:59:25 +1000 (Tue, 01 Jul 2008) | 2 lines
  
  Merge in new reference index page.
........
  r46948 | chris_kohlhoff | 2008-07-01 22:06:49 +1000 (Tue, 01 Jul 2008) | 2 lines
  
  Documentation generation enhancements.
........
  r46949 | chris_kohlhoff | 2008-07-01 22:13:51 +1000 (Tue, 01 Jul 2008) | 2 lines
  
  Improve buffer() documentation. Fix vector overloads to match TR2 proposal.
........
  r46950 | chris_kohlhoff | 2008-07-01 22:14:57 +1000 (Tue, 01 Jul 2008) | 4 lines
  
  Clarify behaviour of read_until/async_read_until with respect to leftover
  data in the streambuf. Use separate brief descriptions for function groups.
  Add some extra notes to the io_service documentation.
........
  r47013 | chris_kohlhoff | 2008-07-03 08:50:50 +1000 (Thu, 03 Jul 2008) | 2 lines
  
  Regenerate documentation.
........


[SVN r47038]
2008-07-03 13:05:33 +00:00
Christopher Kohlhoff
3fded3b5c8 Merge in new reference index page.
[SVN r46947]
2008-07-01 11:59:25 +00:00
Christopher Kohlhoff
be84a0a75a Add requirements for handle and descriptor services. Add new classes to the
quickref index page.


[SVN r44685]
2008-04-21 07:59:21 +00:00
Christopher Kohlhoff
02e47999fa Update copyright notices.
[SVN r43473]
2008-03-03 14:13:01 +00:00
Christopher Kohlhoff
9f319db484 Clean up documentation.
[SVN r40356]
2007-10-23 13:31:12 +00:00
Christopher Kohlhoff
7b6b09d2a2 Fix documentation generation.
[SVN r39436]
2007-09-21 05:42:55 +00:00
Christopher Kohlhoff
b98a841fa6 Improve documentation for completion condition objects.
[SVN r38323]
2007-07-31 11:39:30 +00:00
Christopher Kohlhoff
d569fc2abc Documentation updates.
[SVN r37700]
2007-05-16 14:35:09 +00:00
Christopher Kohlhoff
9e97501354 Add copyright notice.
[SVN r37489]
2007-04-22 22:26:40 +00:00
Christopher Kohlhoff
c91ed951ef Fix broken links.
[SVN r37488]
2007-04-22 14:21:09 +00:00
Christopher Kohlhoff
a1014798a1 Add quick reference index table.
[SVN r37485]
2007-04-22 09:34:13 +00:00