Commit Graph

1744 Commits

Author SHA1 Message Date
Christopher Kohlhoff
1ee1e7b2e3 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. The generated documentation will include a diff
between the two.
2013-05-13 16:38:36 +10:00
Christopher Kohlhoff
5de7e88324 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
in the future 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);
2013-05-13 16:27:18 +10:00
Christopher Kohlhoff
30fb47f1bb Add new traits classes, handler_type and async_result, that allow
the customisation of the return type of an initiating function.
2013-05-13 14:16:43 +10:00
Christopher Kohlhoff
5a8e053a7d Enable handler type requirements static_assert on clang. 2013-05-13 13:58:35 +10:00
Christopher Kohlhoff
bdd9f56425 asio version 1.8.3 released 2013-05-13 13:24:31 +10:00
Christopher Kohlhoff
cb7ee5e92c Detection of boost 1.52 and 1.53. 2013-05-13 11:18:07 +10:00
Christopher Kohlhoff
5d54b0e8c3 Revision history. 2013-05-13 11:16:44 +10:00
Christopher Kohlhoff
a3db517aee Regenerate documentation. 2013-05-13 10:27:23 +10:00
Christopher Kohlhoff
276eb04f42 Add missing include of "asio/error.hpp" header. 2012-12-30 10:13:07 +11:00
Christopher Kohlhoff
c2067a5ea4 Add missing include of <climits> header. 2012-12-30 10:12:48 +11:00
Christopher Kohlhoff
9eb2e5f14b Add a small block recycling optimisation. 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
a57db433e0 Enable noexcept qualifier for error categories when using recent versions of boost. 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
fa545c7b26 Fix deadlock that can occur on Windows when shutting down a pool of io_service threads due to running out of work. 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
78e7dbfa84 Use _snwprintf to address a compile error due to the changed swprintf signature in recent versions of MinGW. 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
a57b9ad376 Use long rather than int for SSL_CTX options, to match OpenSSL. 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
6cf1701ac1 Treat errors from accept as non-fatal. 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
640b17ba7f Fix error in example embedded in basic_socket::get_option's documentation. 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
88cacbfa6d Fix typos in comments. 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
d1f36e5f6b Fix some 64-to-32-bit conversion warnings. 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
cd8ab40d10 Ignore files generated by test-driver. 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
87636b0837 asio version 1.8.2 released 2012-08-21 22:28:04 +10:00
Christopher Kohlhoff
3bfd5b60bf Add configure test for boost 1.51. 2012-08-21 21:43:37 +10:00
Christopher Kohlhoff
6ff1195806 Add revision history. 2012-08-13 21:09:40 +10:00
Christopher Kohlhoff
854d019a58 Instead of using tie(), set the ios_base::unitbuf flag to force the stream to be flushed after every insertion. 2012-07-24 09:40:24 +10:00
Christopher Kohlhoff
1afef34c9a Decorate GCC attribute names with underscores to prevent interaction
with user-defined macros.
2012-07-22 15:49:35 +10:00
Christopher Kohlhoff
45ccb86ae5 Add missing #include of <cctype>, needed for some versions of MinGW. 2012-07-22 09:30:45 +10:00
Christopher Kohlhoff
368bd798f5 Use gcc's atomic builtins on arm, when available. 2012-07-18 09:45:26 +10:00
Christopher Kohlhoff
db0128072c Intel compiler version 11 seems to support __thread keyword too. 2012-07-17 09:16:16 +10:00
Christopher Kohlhoff
8730c250cc Ensure use of __thread keyword is disabled for older Intel compilers. 2012-07-17 09:09:07 +10:00
Christopher Kohlhoff
91dd4e9943 Make strand destruction a no-op, to allow strand objects to be destroyed
after their associated io_service has been destroyed.
2012-07-15 09:56:46 +10:00
Christopher Kohlhoff
baab2276d8 Use the __thread keyword extension when compiling with gcc on linux x86. 2012-07-15 08:58:05 +10:00
Christopher Kohlhoff
572024a782 Avoid calling work_finished() if a completion handler creates more work. 2012-07-13 18:50:34 +10:00
Christopher Kohlhoff
54621fbc87 Eliminate redundant call to call_stack::contains(this) when dispatching a completion handler. 2012-07-13 16:55:53 +10:00
Christopher Kohlhoff
3e01781654 Add support for some newer versions of glibc which provide the epoll_create1
function but always fail with ENOSYS.
2012-07-13 16:37:53 +10:00
Christopher Kohlhoff
dffb3d299a Use SSE2 load and store fences. 2012-07-11 09:51:01 +10:00
Christopher Kohlhoff
4dfd6c3fad Throw exception if SSL engine initialisation fails. 2012-07-11 09:41:03 +10:00
Christopher Kohlhoff
62fb608f99 Fix another regression in buffered_write_stream. 2012-07-11 09:34:30 +10:00
Christopher Kohlhoff
1d1e3365bc asio version 1.8.1 released 2012-07-10 22:59:38 +10:00
Christopher Kohlhoff
b29bdb4e5b Add detection for Boost 1.50.0. 2012-07-04 08:59:56 +10:00
Christopher Kohlhoff
f7264629b0 Update revision history. 2012-05-29 07:59:36 +10:00
Christopher Kohlhoff
83499da38e Use the thread's private_op_queue for handlers returned by the reactor task.
This fixes a problem where signal_set handlers are not being called when the
io_service's concurrency hint is set to 1.
2012-05-29 07:56:12 +10:00
Christopher Kohlhoff
2ded50396f Add support for g++ 4.7 when compiling in C++11 mode. 2012-05-29 07:23:55 +10:00
Christopher Kohlhoff
0a33dcbd6f Revision history. 2012-05-27 07:54:19 +10:00
Christopher Kohlhoff
9e029a9bf0 Added lazy registration for EPOLLOUT. 2012-05-27 07:43:30 +10:00
Christopher Kohlhoff
003cb496b7 Eliminate a lock/unlock pair when rescheduling a strand. 2012-05-24 18:23:16 +10:00
Christopher Kohlhoff
136483df13 Remove trailing whitespace. 2012-05-24 09:23:22 +10:00
Christopher Kohlhoff
10f4bceda3 Last version's race-condition-related revert in the epoll_reactor was
incomplete and broke out-of-band handling. Fixed epoll_reactor::start_op so
that it is now exactly the same as the older, working version.
2012-05-24 08:11:45 +10:00
Christopher Kohlhoff
1f65c999c6 Respect the OPENSSL_NO_ENGINE feature test #define. 2012-05-24 07:38:10 +10:00
Christopher Kohlhoff
199ba153a4 Use correct basic_io_object member functions so that basic_object_handle works with c++11 compilers. 2012-05-24 06:44:24 +10:00
Christopher Kohlhoff
b49202062e asio version 1.8.0 released 2012-05-23 08:57:28 +10:00