Commit Graph

1924 Commits

Author SHA1 Message Date
Christopher Kohlhoff
317da0d5f5 Add missing documentation for use_future_t::allocator_type. 2013-06-22 23:04:53 +10:00
Christopher Kohlhoff
a489d98cd4 Add mechanism for disabling automatic Winsock initialisation. 2013-06-22 22:28:44 +10:00
Christopher Kohlhoff
e661917a12 Fix memory leak in ssl::rfc2818_verification class. 2013-06-22 21:24:06 +10:00
Christopher Kohlhoff
7efa576e4d Support both boost.coroutine v1 and v2. 2013-06-22 21:20:38 +10:00
Christopher Kohlhoff
de7e33a1c6 Update documentation to cover new features. 2013-05-27 21:42:00 +10:00
Christopher Kohlhoff
ed80132017 Fix potential data race due to reading the reactor pointer outside the lock. 2013-05-25 22:28:51 +10:00
Christopher Kohlhoff
cbcfb0beba Boostify the futures example. 2013-05-25 22:28:51 +10:00
Christopher Kohlhoff
d9a21e469d Fix incorrect boostification of #warning message. 2013-05-25 20:11:15 +10:00
Christopher Kohlhoff
9d3b94eb6a Fix bug on Windows where certain operations might generate an error_code with
an invalid (i.e. NULL) error_category.
2013-05-25 20:11:15 +10:00
Christopher Kohlhoff
3a5f6881a5 Automatically disable SSL compression.
To mitigate the risk of certain attacks, SSL compression is now disabled
by default. To enable, you can use the new ssl::context::clear_options()
function like so:

  my_context.clear_options(asio::ssl::context::no_compression);
2013-05-25 20:11:15 +10:00
Christopher Kohlhoff
f826bcd519 Add assertions that num_buckets_ is non-zero. 2013-05-25 20:11:15 +10:00
Christopher Kohlhoff
8f62b7d18b Fix waitable timer documentation. 2013-05-25 20:11:15 +10:00
Christopher Kohlhoff
790c1813d3 Fix error in acceptor example. 2013-05-25 20:11:15 +10:00
Christopher Kohlhoff
d2fab1d6f5 Fix potential deadlock in signal_set implementation. 2013-05-25 18:36:52 +10:00
Christopher Kohlhoff
8bb255fd20 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);
2013-05-19 14:48:30 +10:00
Christopher Kohlhoff
ff98090acd Clean up boostified output. 2013-05-19 07:56:36 +10:00
Christopher Kohlhoff
300ba81889 Fix implementation of asynchronous connect operation so that it can cope
with spurious readiness notifications from the reactor.
2013-05-16 11:08:14 +10:00
Christopher Kohlhoff
af6fd3f9c2 Fix a problem with lost thread wakeups that can occur when making
concurrent calls to run() and poll() on the same io_service object.
2013-05-16 10:02:40 +10:00
Christopher Kohlhoff
1aa960ee0e Fix basic_waitable_timer's underlying implementation so that it can
handle any time_point value without overflowing the intermediate
duration objects.
2013-05-15 22:06:55 +10:00
Christopher Kohlhoff
a23aed7aa5 Remove the stackless coroutine class and macros from the HTTP server 4
example, and instead make them a part of Asio's documented interface.
2013-05-14 22:04:37 +10:00
Christopher Kohlhoff
1ed93cec61 Update copyright notices. 2013-05-14 12:29:10 +10:00
Christopher Kohlhoff
49dddfc525 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.
2013-05-14 12:00:42 +10:00
Christopher Kohlhoff
16c12eb1ed 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.
2013-05-14 12:00:42 +10:00
Christopher Kohlhoff
ea1585c05c 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.
2013-05-14 12:00:41 +10:00
Christopher Kohlhoff
cea683f915 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.
2013-05-14 12:00:41 +10:00
Christopher Kohlhoff
dd2accf95f Minor cleanup. 2013-05-14 12:00:40 +10:00
Christopher Kohlhoff
5a083802f0 Add the ability to use Asio without Boost.
When using a C++11 compiler, most of Asio may now be used without a
dependency on Boost header files or libraries. To use Asio in this
way, define ASIO_STANDALONE on your compiler command line or as part of
the project options.

The standalone configuration has currently been tested for the following
platforms and compilers:

- Linux with g++ 4.7 (requires -std=c++11)

- Mac OS X with clang++ / Xcode 4.6 (requires -std=c++11 -stdlib=libc++)
2013-05-14 11:24:07 +10:00
Christopher Kohlhoff
a80c14cdbb 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.
2013-05-13 19:02:38 +10:00
Christopher Kohlhoff
167e1d00eb Regenerate documentation. 2013-05-13 16:38:36 +10:00
Christopher Kohlhoff
a859b497d4 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.
2013-05-13 16:38:36 +10:00
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