detect_ssl returns a bool

fix #1288
This commit is contained in:
Vinnie Falco
2019-03-06 05:46:11 -08:00
parent b51c4bb49a
commit 7f53b0f66c
3 changed files with 11 additions and 14 deletions

View File

@ -2,6 +2,7 @@ Version 229:
* Rename to buffer_bytes * Rename to buffer_bytes
* Tidy up examples * Tidy up examples
* detect_ssl returns a bool
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -482,7 +482,7 @@ public:
/** Close the timed stream. /** Close the timed stream.
This cancels all of the outstanding asynchronous operations This cancels all of the outstanding asynchronous operations
as if by calling @ref cancel, and closes the file as if by calling @ref cancel, and closes the underlying socket.
*/ */
void void
close(); close();

View File

@ -203,15 +203,13 @@ is_tls_client_hello (ConstBufferSequence const& buffers)
@param ec Set to the error if any occurred. @param ec Set to the error if any occurred.
@return `boost::tribool` indicating whether the buffer contains @return `true` if the buffer contains a TLS client handshake and
a TLS client handshake, does not contain a handshake, or needs no error occurred, otherwise `false`.
additional octets. If an error occurs, the return value is
undefined.
*/ */
template< template<
class SyncReadStream, class SyncReadStream,
class DynamicBuffer> class DynamicBuffer>
boost::tribool bool
detect_ssl( detect_ssl(
SyncReadStream& stream, SyncReadStream& stream,
DynamicBuffer& buffer, DynamicBuffer& buffer,
@ -241,7 +239,7 @@ detect_ssl(
{ {
// A definite answer is a success // A definite answer is a success
ec = {}; ec = {};
return result; return static_cast<bool>(result);
} }
// Try to fill our buffer by reading from the stream. // Try to fill our buffer by reading from the stream.
@ -304,14 +302,12 @@ detect_ssl(
this is a completion handler, the implementation takes ownership this is a completion handler, the implementation takes ownership
of the handler by performing a decay-copy, and the equivalent of the handler by performing a decay-copy, and the equivalent
function signature of the handler must be: function signature of the handler must be:
@code @code
void handler( void handler(
error_code const& error, // Set to the error, if any error_code const& error, // Set to the error, if any
boost::tribool result // The result of the detector bool result // The result of the detector
); );
@endcode @endcode
Regardless of whether the asynchronous operation completes Regardless of whether the asynchronous operation completes
immediately or not, the handler will not be invoked from within immediately or not, the handler will not be invoked from within
this function. Invocation of the handler will be performed in a this function. Invocation of the handler will be performed in a
@ -328,7 +324,7 @@ async_detect_ssl(
CompletionToken&& token) CompletionToken&& token)
-> typename net::async_result< -> typename net::async_result<
typename std::decay<CompletionToken>::type, /*< `async_result` customizes the return value based on the completion token >*/ typename std::decay<CompletionToken>::type, /*< `async_result` customizes the return value based on the completion token >*/
void(error_code, boost::tribool)>::return_type; /*< This is the signature for the completion handler >*/ void(error_code, bool)>::return_type; /*< This is the signature for the completion handler >*/
//] //]
//[example_core_detect_ssl_5 //[example_core_detect_ssl_5
@ -399,7 +395,7 @@ async_detect_ssl(
CompletionToken&& token) CompletionToken&& token)
-> typename net::async_result< -> typename net::async_result<
typename std::decay<CompletionToken>::type, typename std::decay<CompletionToken>::type,
void(error_code, boost::tribool)>::return_type void(error_code, bool)>::return_type
{ {
// Make sure arguments meet the type requirements // Make sure arguments meet the type requirements
@ -429,7 +425,7 @@ async_detect_ssl(
return net::async_initiate< return net::async_initiate<
CompletionToken, CompletionToken,
void(error_code, boost::tribool)>( void(error_code, bool)>(
detail::run_detect_ssl_op{}, detail::run_detect_ssl_op{},
token, token,
&stream, // pass the reference by pointer &stream, // pass the reference by pointer
@ -630,7 +626,7 @@ operator()(error_code ec, std::size_t bytes_transferred, bool cont)
// At this point, we are guaranteed that the original initiating // At this point, we are guaranteed that the original initiating
// function is no longer on our stack frame. // function is no longer on our stack frame.
this->invoke_now(ec, result_); this->invoke_now(ec, static_cast<bool>(result_));
} }
} }