Commit Graph

1359 Commits

Author SHA1 Message Date
Christopher Kohlhoff
abd9cdb60f 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 r84363]
2013-05-19 04:55:11 +00:00
Christopher Kohlhoff
34f88cf707 Remove some trailing spaces and fix another copyright notice.
[SVN r84361]
2013-05-18 21:56:31 +00:00
Christopher Kohlhoff
c607f44ac6 Fix implementation of asynchronous connect operation so that it can cope
with spurious readiness notifications from the reactor.


[SVN r84349]
2013-05-18 12:13:17 +00:00
Christopher Kohlhoff
85e9b528c4 Fix a problem with lost thread wakeups that can occur when making
concurrent calls to run() and poll() on the same io_service object.


[SVN r84348]
2013-05-18 12:07:00 +00:00
Christopher Kohlhoff
ff5799ea7e Fix basic_waitable_timer's underlying implementation so that it can
handle any time_point value without overflowing the intermediate
duration objects.


[SVN r84347]
2013-05-18 12:01:59 +00:00
Christopher Kohlhoff
280a7d55b3 Remove the stackless coroutine class and macros from the HTTP server 4
example, and instead make them a part of Asio's documented interface.


[SVN r84346]
2013-05-18 11:54:59 +00:00
Christopher Kohlhoff
95d16d75b7 Update copyright notices.
[SVN r84345]
2013-05-18 11:24:59 +00:00
Christopher Kohlhoff
93610840c2 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.


[SVN r84325]
2013-05-17 11:04:11 +00:00
Christopher Kohlhoff
6bc7463804 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.


[SVN r84322]
2013-05-17 11:00:49 +00:00
Christopher Kohlhoff
0257ed7a11 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.


[SVN r84320]
2013-05-17 10:57:02 +00:00
Christopher Kohlhoff
1c9d4a1ac3 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.


[SVN r84319]
2013-05-17 10:52:08 +00:00
Christopher Kohlhoff
d3adbad455 Minor cleanup.
[SVN r84316]
2013-05-17 10:15:21 +00:00
Christopher Kohlhoff
9644fab951 Partially decouple Asio from other boost components via an extra level
of indirection.


[SVN r84315]
2013-05-17 10:06:50 +00:00
Christopher Kohlhoff
1bba399354 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.


[SVN r84314]
2013-05-17 03:07:51 +00:00
Christopher Kohlhoff
546362b425 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.


[SVN r84313]
2013-05-17 02:35:08 +00:00
Christopher Kohlhoff
4f1d36c7a1 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.


[SVN r84312]
2013-05-17 02:25:10 +00:00
Christopher Kohlhoff
e4b53793cc 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);


[SVN r84311]
2013-05-17 01:38:47 +00:00
Christopher Kohlhoff
be0221203a Add new traits classes, handler_type and async_result, that allow
the customisation of the return type of an initiating function.


[SVN r84308]
2013-05-16 23:26:04 +00:00
Christopher Kohlhoff
0dfdb9b45c Enable handler type requirements static_assert on clang.
[SVN r84301]
2013-05-16 21:34:54 +00:00
Christopher Kohlhoff
41549a4798 Release notes.
[SVN r82554]
2013-01-20 01:47:37 +00:00
Christopher Kohlhoff
007bf03d0c Release notes.
[SVN r82553]
2013-01-20 01:46:48 +00:00
Christopher Kohlhoff
719d65a805 Merge from trunk:
* Fix some 64-to-32-bit conversion warnings. Fixes #7459

* Fix typos in comments. Fixes #7761

* Fix error in example embedded in basic_socket::get_option's documentation. Fixes #7562

* Use long rather than int for SSL_CTX options, to match OpenSSL. Fixes #7209

* Use _snwprintf to address a compile error due to the changed swprintf signature in recent versions of MinGW. Fixes #7373

* Fix deadlock that can occur on Windows when shutting down a pool of io_service threads due to running out of work. Fixes #7552

* Enable noexcept qualifier for error categories. Fixes #7797

* Treat errors from accept as non-fatal. Fixes #7488

* Add a small block recycling optimisation.

* Version bump.

* Regenerate documentation.


[SVN r82290]
2012-12-30 23:17:13 +00:00
Christopher Kohlhoff
67cd6c1661 Remove file accidentally left behind after a prior merge.
[SVN r82289]
2012-12-30 22:56:35 +00:00
Christopher Kohlhoff
13353857a5 Regenerate documentation.
[SVN r82288]
2012-12-30 22:39:30 +00:00
Christopher Kohlhoff
9a5cfcb604 Version bump.
[SVN r82286]
2012-12-30 22:01:28 +00:00
Christopher Kohlhoff
88cf604923 Add missing include of asio/error.hpp header.
[SVN r82279]
2012-12-29 23:21:32 +00:00
Christopher Kohlhoff
e7d150b823 Add missing include of <climits> header.
[SVN r82278]
2012-12-29 23:10:17 +00:00
Christopher Kohlhoff
e2e33e0f31 Add a small block recycling optimisation.
[SVN r82265]
2012-12-29 13:30:34 +00:00
Christopher Kohlhoff
901bd9d539 Enable noexcept qualifier for error categories. Refs #7797
[SVN r82264]
2012-12-29 13:24:03 +00:00
Christopher Kohlhoff
0a4b463f70 Fix deadlock that can occur on Windows when shutting down a pool of io_service threads due to running out of work. Refs #7552
[SVN r82263]
2012-12-29 13:22:16 +00:00
Christopher Kohlhoff
e5cc32264b Use _snwprintf to address a compile error due to the changed swprintf signature in recent versions of MinGW. Refs #7373
[SVN r82262]
2012-12-29 13:20:44 +00:00
Christopher Kohlhoff
817b56a269 Use long rather than int for SSL_CTX options, to match OpenSSL. Refs #7209
[SVN r82261]
2012-12-29 13:17:59 +00:00
Christopher Kohlhoff
bd5f93f3df Treat errors from accept as non-fatal. Refs #7488
[SVN r82260]
2012-12-29 13:14:37 +00:00
Christopher Kohlhoff
489f421f8e Fix error in example embedded in basic_socket::get_option's documentation. Refs #7562
[SVN r82259]
2012-12-29 13:12:49 +00:00
Christopher Kohlhoff
e8c6842df7 Fix typos in comments. Refs #7761
[SVN r82258]
2012-12-29 13:11:43 +00:00
Christopher Kohlhoff
f65f8bd9f8 Fix some 64-to-32-bit conversion warnings. Refs #7459
[SVN r82257]
2012-12-29 13:08:30 +00:00
Vicente J. Botet Escriba
27896e9147 System/FileSystem/Asio/Thread: ref #7278 Added noexcept to Boost.System to conform with C++11
[SVN r81808]
2012-12-09 14:47:39 +00:00
Christopher Kohlhoff
9faa08829e Revision history.
[SVN r79998]
2012-08-13 11:34:01 +00:00
Christopher Kohlhoff
d2679ef618 Revision history.
[SVN r79997]
2012-08-13 11:31:11 +00:00
Christopher Kohlhoff
f88a411217 Merge from trunk:
* Instead of using tie(), set the ios_base::unitbuf flag to force the stream to be flushed after every insertion. Fixes #7162


[SVN r79712]
2012-07-24 05:42:42 +00:00
Christopher Kohlhoff
355da949d5 Instead of using tie(), set the ios_base::unitbuf flag to force the stream to be flushed after every insertion. Refs #7162
[SVN r79710]
2012-07-23 23:52:15 +00:00
Christopher Kohlhoff
a37edb5c84 Merge from trunk:
* Decorate GCC attribute names with underscores to prevent interaction with user-defined macros. Fixes #6415

* Add missing #include of <cctype>, needed for some versions of MinGW.

* Use gcc's atomic builtins on arm, when available. Fixes #7140.


[SVN r79694]
2012-07-23 11:03:31 +00:00
Christopher Kohlhoff
4d9e2461e0 Decorate GCC attribute names with underscores to prevent interaction with user-defined macros. Refs #6415
[SVN r79649]
2012-07-22 06:07:23 +00:00
Christopher Kohlhoff
b38937e17c Add missing #include of <cctype>, needed for some versions of MinGW.
[SVN r79648]
2012-07-22 06:05:26 +00:00
Christopher Kohlhoff
e00679b068 Use gcc's atomic builtins on arm, when available.
[SVN r79647]
2012-07-22 06:04:23 +00:00
Christopher Kohlhoff
2c7a4d3edb Merge from trunk:
* Ensure use of __thread keyword is disabled for older Intel compilers.


[SVN r79577]
2012-07-17 23:37:34 +00:00
Christopher Kohlhoff
7df5c95ca9 Ensure use of __thread keyword is disabled for older Intel compilers.
[SVN r79568]
2012-07-17 00:01:37 +00:00
Christopher Kohlhoff
cb65bde33b Sync version number with release branch.
[SVN r79551]
2012-07-16 06:29:59 +00:00
Christopher Kohlhoff
a2aa76783d Version bump.
[SVN r79550]
2012-07-16 06:27:57 +00:00
Christopher Kohlhoff
a9029dfabd Merge from trunk:
* Make strand destruction a no-op, to allow strand objects to be destroyed after their associated io_service has been destroyed.

* Use the __thread keyword extension when compiling with gcc on linux x86.

* Avoid calling work_finished() if a completion handler creates more work.

* Eliminate redundant call to call_stack::contains(this) when dispatching a completion handler.

* Add support for some newer versions of glibc which provide the epoll_create1 function but always fail with ENOSYS. Fixes #7012

* Use SSE2 load and store fences.

* Throw exception if SSL engine initialisation fails. Fixes #6303

* Fix another regression in buffered_write_stream. Fixes #6310


[SVN r79549]
2012-07-16 06:26:30 +00:00