HDFS-15385 Upgrade boost library to 1.72 (#2051)
* Removed the asio-1.10.2 that was checked in under libhdfspp/third_party directory.
This commit is contained in:
parent
317fe4584a
commit
cce5a6f609
|
@ -6,6 +6,7 @@ Requirements:
|
|||
* Unix System
|
||||
* JDK 1.8
|
||||
* Maven 3.3 or later
|
||||
* Boost 1.72 (if compiling native code)
|
||||
* Protocol Buffers 3.7.1 (if compiling native code)
|
||||
* CMake 3.1 or newer (if compiling native code)
|
||||
* Zlib devel (if compiling native code)
|
||||
|
@ -72,6 +73,12 @@ Installing required packages for clean install of Ubuntu 14.04 LTS Desktop:
|
|||
&& ./configure\
|
||||
&& make install \
|
||||
&& rm -rf /opt/protobuf-3.7-src
|
||||
* Boost
|
||||
$ curl -L https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.bz2/download > boost_1_72_0.tar.bz2 \
|
||||
&& tar --bzip2 -xf boost_1_72_0.tar.bz2 \
|
||||
&& cd boost_1_72_0 \
|
||||
&& ./bootstrap.sh --prefix=/usr/ \
|
||||
&& ./b2 --without-python install
|
||||
|
||||
Optional packages:
|
||||
|
||||
|
@ -468,6 +475,7 @@ Requirements:
|
|||
* Windows System
|
||||
* JDK 1.8
|
||||
* Maven 3.0 or later
|
||||
* Boost 1.72
|
||||
* Protocol Buffers 3.7.1
|
||||
* CMake 3.1 or newer
|
||||
* Visual Studio 2010 Professional or Higher
|
||||
|
|
|
@ -92,6 +92,21 @@ ENV MAVEN_HOME /usr
|
|||
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
|
||||
ENV FINDBUGS_HOME /usr
|
||||
|
||||
#######
|
||||
# Install Boost 1.72 (1.65 ships with Bionic)
|
||||
#######
|
||||
# hadolint ignore=DL3003
|
||||
RUN mkdir -p /opt/boost-library \
|
||||
&& curl -L https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.bz2/download > boost_1_72_0.tar.bz2 \
|
||||
&& mv boost_1_72_0.tar.bz2 /opt/boost-library \
|
||||
&& cd /opt/boost-library \
|
||||
&& tar --bzip2 -xf boost_1_72_0.tar.bz2 \
|
||||
&& cd /opt/boost-library/boost_1_72_0 \
|
||||
&& ./bootstrap.sh --prefix=/usr/ \
|
||||
&& ./b2 --without-python install \
|
||||
&& cd /root \
|
||||
&& rm -rf /opt/boost-library
|
||||
|
||||
######
|
||||
# Install Google Protobuf 3.7.1 (3.0.0 ships with Bionic)
|
||||
######
|
||||
|
|
|
@ -95,6 +95,21 @@ ENV MAVEN_HOME /usr
|
|||
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-arm64
|
||||
ENV FINDBUGS_HOME /usr
|
||||
|
||||
#######
|
||||
# Install Boost 1.72 (1.65 ships with Bionic)
|
||||
#######
|
||||
# hadolint ignore=DL3003
|
||||
RUN mkdir -p /opt/boost-library \
|
||||
&& curl -L https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.bz2/download > boost_1_72_0.tar.bz2 \
|
||||
&& mv boost_1_72_0.tar.bz2 /opt/boost-library \
|
||||
&& cd /opt/boost-library \
|
||||
&& tar --bzip2 -xf boost_1_72_0.tar.bz2 \
|
||||
&& cd /opt/boost-library/boost_1_72_0 \
|
||||
&& ./bootstrap.sh --prefix=/usr/ \
|
||||
&& ./b2 --without-python install \
|
||||
&& cd /root \
|
||||
&& rm -rf /opt/boost-library
|
||||
|
||||
######
|
||||
# Install Google Protobuf 3.7.1 (3.0.0 ships with Bionic)
|
||||
######
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
||||
|
||||
project(hadoop_hdfs_native_client)
|
||||
|
||||
enable_testing()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../hadoop-common-project/hadoop-common)
|
||||
|
|
|
@ -28,6 +28,8 @@ project (libhdfspp)
|
|||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
find_package (Boost 1.72.0 REQUIRED)
|
||||
|
||||
enable_testing()
|
||||
include (CTest)
|
||||
|
||||
|
@ -220,7 +222,7 @@ include_directories(
|
|||
|
||||
include_directories( SYSTEM
|
||||
${PROJECT_BINARY_DIR}/lib/proto
|
||||
third_party/asio-1.10.2/include
|
||||
${Boost_INCLUDE_DIRS}
|
||||
third_party/rapidxml-1.13
|
||||
third_party/gmock-1.7.0
|
||||
third_party/tr2
|
||||
|
|
|
@ -61,10 +61,7 @@
|
|||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
// forward decl
|
||||
namespace asio {
|
||||
class io_service;
|
||||
}
|
||||
#include <boost/asio/io_service.hpp>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
|
@ -133,7 +130,7 @@ class IoService : public std::enable_shared_from_this<IoService>
|
|||
* Access underlying io_service object. Only to be used in asio library calls.
|
||||
* After HDFS-11884 is complete only tests should need direct access to the asio::io_service.
|
||||
**/
|
||||
virtual asio::io_service& GetRaw() = 0;
|
||||
virtual boost::asio::io_service& GetRaw() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ if(NEED_LINK_DL)
|
|||
set(LIB_DL dl)
|
||||
endif()
|
||||
|
||||
include_directories(${Boost_INCLUDE_DIRS} ../../include)
|
||||
add_library(common_obj OBJECT status.cc sasl_digest_md5.cc ioservice_impl.cc options.cc configuration.cc configuration_loader.cc hdfs_configuration.cc uri.cc util.cc retry_policy.cc cancel_tracker.cc logging.cc libhdfs_events_impl.cc auth_info.cc namenode_info.cc statinfo.cc fsinfo.cc content_summary.cc locks.cc config_parser.cc)
|
||||
add_library(common $<TARGET_OBJECTS:common_obj> $<TARGET_OBJECTS:uriparser2_obj>)
|
||||
target_link_libraries(common ${LIB_DL})
|
||||
|
|
|
@ -19,15 +19,17 @@
|
|||
#ifndef LIB_COMMON_ASYNC_STREAM_H_
|
||||
#define LIB_COMMON_ASYNC_STREAM_H_
|
||||
|
||||
#include <asio/buffer.hpp>
|
||||
#include <asio/error_code.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/asio/system_executor.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
// Contiguous buffer types
|
||||
typedef asio::mutable_buffers_1 MutableBuffer;
|
||||
typedef asio::const_buffers_1 ConstBuffer;
|
||||
typedef boost::asio::mutable_buffers_1 MutableBuffer;
|
||||
typedef boost::asio::const_buffers_1 ConstBuffer;
|
||||
|
||||
/*
|
||||
* asio-compatible stream implementation.
|
||||
|
@ -38,13 +40,20 @@ typedef asio::const_buffers_1 ConstBuffer;
|
|||
*/
|
||||
class AsyncStream {
|
||||
public:
|
||||
using executor_type = boost::asio::system_executor;
|
||||
executor_type executor_;
|
||||
|
||||
virtual void async_read_some(const MutableBuffer &buf,
|
||||
std::function<void (const asio::error_code & error,
|
||||
std::function<void (const boost::system::error_code & error,
|
||||
std::size_t bytes_transferred) > handler) = 0;
|
||||
|
||||
virtual void async_write_some(const ConstBuffer &buf,
|
||||
std::function<void (const asio::error_code & error,
|
||||
std::function<void (const boost::system::error_code & error,
|
||||
std::size_t bytes_transferred) > handler) = 0;
|
||||
|
||||
executor_type get_executor() {
|
||||
return executor_;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,10 @@
|
|||
#include "continuation.h"
|
||||
#include "common/util.h"
|
||||
#include "hdfspp/status.h"
|
||||
#include <asio/write.hpp>
|
||||
|
||||
#include <boost/asio/write.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace hdfs {
|
||||
|
@ -37,8 +40,8 @@ public:
|
|||
|
||||
virtual void Run(const Next &next) override {
|
||||
auto handler =
|
||||
[next](const asio::error_code &ec, size_t) { next(ToStatus(ec)); };
|
||||
asio::async_write(*stream_, buffer_, handler);
|
||||
[next](const boost::system::error_code &ec, size_t) { next(ToStatus(ec)); };
|
||||
boost::asio::async_write(*stream_, buffer_, handler);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
|
||||
#include "common/util.h"
|
||||
|
||||
#include <asio/read.hpp>
|
||||
|
||||
#include <boost/asio/read.hpp>
|
||||
#include <boost/asio/write.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <google/protobuf/message_lite.h>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
||||
|
@ -39,7 +41,7 @@ struct ReadDelimitedPBMessageContinuation : public Continuation {
|
|||
|
||||
virtual void Run(const Next &next) override {
|
||||
namespace pbio = google::protobuf::io;
|
||||
auto handler = [this, next](const asio::error_code &ec, size_t) {
|
||||
auto handler = [this, next](const boost::system::error_code &ec, size_t) {
|
||||
Status status;
|
||||
if (ec) {
|
||||
status = ToStatus(ec);
|
||||
|
@ -57,15 +59,15 @@ struct ReadDelimitedPBMessageContinuation : public Continuation {
|
|||
}
|
||||
next(status);
|
||||
};
|
||||
asio::async_read(*stream_,
|
||||
asio::buffer(buf_),
|
||||
boost::asio::async_read(*stream_,
|
||||
boost::asio::buffer(buf_),
|
||||
std::bind(&ReadDelimitedPBMessageContinuation::CompletionHandler, this,
|
||||
std::placeholders::_1, std::placeholders::_2),
|
||||
handler);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t CompletionHandler(const asio::error_code &ec, size_t transferred) {
|
||||
size_t CompletionHandler(const boost::system::error_code &ec, size_t transferred) {
|
||||
if (ec) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -103,7 +105,7 @@ struct WriteDelimitedPBMessageContinuation : Continuation {
|
|||
return;
|
||||
}
|
||||
|
||||
asio::async_write(*stream_, asio::buffer(buf_), [next](const asio::error_code &ec, size_t) { next(ToStatus(ec)); } );
|
||||
boost::asio::async_write(*stream_, boost::asio::buffer(buf_), [next](const boost::system::error_code &ec, size_t) { next(ToStatus(ec)); } );
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
|
||||
#include <hdfspp/fsinfo.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ void IoServiceImpl::Run() {
|
|||
// from escaping this library and crashing the process.
|
||||
|
||||
// As recommended in http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/reference/io_service.html#boost_asio.reference.io_service.effect_of_exceptions_thrown_from_handlers
|
||||
asio::io_service::work work(io_service_);
|
||||
boost::asio::io_service::work work(io_service_);
|
||||
while(true)
|
||||
{
|
||||
try
|
||||
|
@ -145,7 +145,7 @@ void IoServiceImpl::Stop() {
|
|||
io_service_.stop();
|
||||
}
|
||||
|
||||
asio::io_service& IoServiceImpl::GetRaw() {
|
||||
boost::asio::io_service& IoServiceImpl::GetRaw() {
|
||||
return io_service_;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "hdfspp/ioservice.h"
|
||||
|
||||
#include <asio/io_service.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include "common/new_delete.h"
|
||||
|
||||
#include <mutex>
|
||||
|
@ -45,7 +45,7 @@ class IoServiceImpl : public IoService {
|
|||
void PostTask(std::function<void(void)> asyncTask) override;
|
||||
void Run() override;
|
||||
void Stop() override;
|
||||
asio::io_service& GetRaw() override;
|
||||
boost::asio::io_service& GetRaw() override;
|
||||
|
||||
// Add a single worker thread, in the common case try to avoid this in favor
|
||||
// of Init[Default]Workers. Public for use by tests and rare cases where a
|
||||
|
@ -57,7 +57,7 @@ class IoServiceImpl : public IoService {
|
|||
|
||||
private:
|
||||
std::mutex state_lock_;
|
||||
::asio::io_service io_service_;
|
||||
boost::asio::io_service io_service_;
|
||||
|
||||
// For doing logging + resource manager updates on thread start/exit
|
||||
void ThreadStartHook();
|
||||
|
|
|
@ -136,7 +136,7 @@ LogMessage& LogMessage::operator<<(const std::string& str) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator<<(const ::asio::ip::tcp::endpoint& endpoint) {
|
||||
LogMessage& LogMessage::operator<<(const boost::asio::ip::tcp::endpoint& endpoint) {
|
||||
msg_buffer_ << endpoint;
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#ifndef LIB_COMMON_LOGGING_H_
|
||||
#define LIB_COMMON_LOGGING_H_
|
||||
|
||||
#include <asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
#include "hdfspp/log.h"
|
||||
|
||||
|
@ -193,7 +193,7 @@ class LogMessage {
|
|||
LogMessage& operator<<(void *);
|
||||
|
||||
//asio types
|
||||
LogMessage& operator<<(const ::asio::ip::tcp::endpoint& endpoint);
|
||||
LogMessage& operator<<(const boost::asio::ip::tcp::endpoint& endpoint);
|
||||
|
||||
//thread and mutex types
|
||||
LogMessage& operator<<(const std::thread::id& tid);
|
||||
|
|
|
@ -70,7 +70,7 @@ bool ResolveInPlace(std::shared_ptr<IoService> ioservice, ResolvedNamenodeInfo &
|
|||
return true;
|
||||
}
|
||||
|
||||
typedef std::vector<asio::ip::tcp::endpoint> endpoint_vector;
|
||||
typedef std::vector<boost::asio::ip::tcp::endpoint> endpoint_vector;
|
||||
|
||||
// RAII wrapper
|
||||
class ScopedResolver {
|
||||
|
@ -78,8 +78,8 @@ class ScopedResolver {
|
|||
std::shared_ptr<IoService> io_service_;
|
||||
std::string host_;
|
||||
std::string port_;
|
||||
::asio::ip::tcp::resolver::query query_;
|
||||
::asio::ip::tcp::resolver resolver_;
|
||||
boost::asio::ip::tcp::resolver::query query_;
|
||||
boost::asio::ip::tcp::resolver resolver_;
|
||||
endpoint_vector endpoints_;
|
||||
|
||||
// Caller blocks on access if resolution isn't finished
|
||||
|
@ -111,9 +111,9 @@ class ScopedResolver {
|
|||
std::shared_ptr<std::promise<Status>> shared_result = result_status_;
|
||||
|
||||
// Callback to pull a copy of endpoints out of resolver and set promise
|
||||
auto callback = [this, shared_result](const asio::error_code &ec, ::asio::ip::tcp::resolver::iterator out) {
|
||||
auto callback = [this, shared_result](const boost::system::error_code &ec, boost::asio::ip::tcp::resolver::iterator out) {
|
||||
if(!ec) {
|
||||
std::copy(out, ::asio::ip::tcp::resolver::iterator(), std::back_inserter(endpoints_));
|
||||
std::copy(out, boost::asio::ip::tcp::resolver::iterator(), std::back_inserter(endpoints_));
|
||||
}
|
||||
shared_result->set_value( ToStatus(ec) );
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#ifndef COMMON_HDFS_NAMENODE_INFO_H_
|
||||
#define COMMON_HDFS_NAMENODE_INFO_H_
|
||||
|
||||
#include <asio.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
#include <hdfspp/options.h>
|
||||
|
||||
|
@ -37,7 +37,7 @@ struct ResolvedNamenodeInfo : public NamenodeInfo {
|
|||
ResolvedNamenodeInfo& operator=(const NamenodeInfo &info);
|
||||
std::string str() const;
|
||||
|
||||
std::vector<::asio::ip::tcp::endpoint> endpoints;
|
||||
std::vector<boost::asio::ip::tcp::endpoint> endpoints;
|
||||
};
|
||||
|
||||
// Clear endpoints if set and resolve all of them in parallel.
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "common/retry_policy.h"
|
||||
#include "common/logging.h"
|
||||
|
||||
#include <boost/asio/error.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace hdfs {
|
||||
|
@ -57,7 +59,7 @@ RetryAction FixedDelayWithFailover::ShouldRetry(const Status &s, uint64_t retrie
|
|||
(void)max_failover_conn_retries_;
|
||||
LOG_TRACE(kRPC, << "FixedDelayWithFailover::ShouldRetry(retries=" << retries << ", failovers=" << failovers << ")");
|
||||
|
||||
if(failovers < max_failover_retries_ && (s.code() == ::asio::error::timed_out || s.get_server_exception_type() == Status::kStandbyException) )
|
||||
if(failovers < max_failover_retries_ && (s.code() == boost::asio::error::timed_out || s.get_server_exception_type() == Status::kStandbyException) )
|
||||
{
|
||||
// Try connecting to another NN in case this one keeps timing out
|
||||
// Can add the backoff wait specified by dfs.client.failover.sleep.base.millis here
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
namespace hdfs {
|
||||
|
||||
Status ToStatus(const ::asio::error_code &ec) {
|
||||
Status ToStatus(const boost::system::error_code &ec) {
|
||||
if (ec) {
|
||||
return Status(ec.value(), ec.message().c_str());
|
||||
} else {
|
||||
|
@ -134,7 +134,7 @@ std::string Base64Encode(const std::string &src) {
|
|||
}
|
||||
|
||||
|
||||
std::string SafeDisconnect(asio::ip::tcp::socket *sock) {
|
||||
std::string SafeDisconnect(boost::asio::ip::tcp::socket *sock) {
|
||||
std::string err;
|
||||
if(sock && sock->is_open()) {
|
||||
/**
|
||||
|
@ -147,7 +147,7 @@ std::string SafeDisconnect(asio::ip::tcp::socket *sock) {
|
|||
**/
|
||||
|
||||
try {
|
||||
sock->shutdown(asio::ip::tcp::socket::shutdown_both);
|
||||
sock->shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
||||
} catch (const std::exception &e) {
|
||||
err = std::string("shutdown() threw") + e.what();
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include <asio/error_code.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <openssl/rand.h>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
|
||||
|
@ -41,7 +42,7 @@ namespace hdfs {
|
|||
typedef std::lock_guard<std::mutex> mutex_guard;
|
||||
|
||||
|
||||
Status ToStatus(const ::asio::error_code &ec);
|
||||
Status ToStatus(const boost::system::error_code &ec);
|
||||
|
||||
// Determine size of buffer that needs to be allocated in order to serialize msg
|
||||
// in delimited format
|
||||
|
@ -75,7 +76,7 @@ bool lock_held(T & mutex) {
|
|||
// Shutdown and close a socket safely; will check if the socket is open and
|
||||
// catch anything thrown by asio.
|
||||
// Returns a string containing error message on failure, otherwise an empty string.
|
||||
std::string SafeDisconnect(asio::ip::tcp::socket *sock);
|
||||
std::string SafeDisconnect(boost::asio::ip::tcp::socket *sock);
|
||||
|
||||
|
||||
// The following helper function is used for classes that look like the following:
|
||||
|
@ -94,13 +95,13 @@ std::string SafeDisconnect(asio::ip::tcp::socket *sock);
|
|||
// it's a asio socket, and nullptr if it's anything else.
|
||||
|
||||
template <typename sock_t>
|
||||
inline asio::ip::tcp::socket *get_asio_socket_ptr(sock_t *s) {
|
||||
inline boost::asio::ip::tcp::socket *get_asio_socket_ptr(sock_t *s) {
|
||||
(void)s;
|
||||
return nullptr;
|
||||
}
|
||||
template<>
|
||||
inline asio::ip::tcp::socket *get_asio_socket_ptr<asio::ip::tcp::socket>
|
||||
(asio::ip::tcp::socket *s) {
|
||||
inline boost::asio::ip::tcp::socket *get_asio_socket_ptr<boost::asio::ip::tcp::socket>
|
||||
(boost::asio::ip::tcp::socket *s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "datanodeconnection.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#include <boost/asio/connect.hpp>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
DataNodeConnection::~DataNodeConnection(){}
|
||||
|
@ -29,7 +31,7 @@ DataNodeConnectionImpl::DataNodeConnectionImpl(std::shared_ptr<IoService> io_ser
|
|||
const hadoop::common::TokenProto *token,
|
||||
LibhdfsEvents *event_handlers) : event_handlers_(event_handlers)
|
||||
{
|
||||
using namespace ::asio::ip;
|
||||
using namespace boost::asio::ip;
|
||||
|
||||
conn_.reset(new tcp::socket(io_service->GetRaw()));
|
||||
auto datanode_addr = dn_proto.id();
|
||||
|
@ -49,8 +51,8 @@ void DataNodeConnectionImpl::Connect(
|
|||
// Keep the DN from being freed until we're done
|
||||
mutex_guard state_lock(state_lock_);
|
||||
auto shared_this = shared_from_this();
|
||||
asio::async_connect(*conn_, endpoints_.begin(), endpoints_.end(),
|
||||
[shared_this, handler](const asio::error_code &ec, std::array<asio::ip::tcp::endpoint, 1>::iterator it) {
|
||||
boost::asio::async_connect(*conn_, endpoints_.begin(), endpoints_.end(),
|
||||
[shared_this, handler](const boost::system::error_code &ec, std::array<boost::asio::ip::tcp::endpoint, 1>::iterator it) {
|
||||
(void)it;
|
||||
handler(ToStatus(ec), shared_this); });
|
||||
}
|
||||
|
@ -69,7 +71,7 @@ void DataNodeConnectionImpl::Cancel() {
|
|||
}
|
||||
|
||||
void DataNodeConnectionImpl::async_read_some(const MutableBuffer &buf,
|
||||
std::function<void (const asio::error_code & error, std::size_t bytes_transferred) > handler)
|
||||
std::function<void (const boost::system::error_code & error, std::size_t bytes_transferred) > handler)
|
||||
{
|
||||
event_handlers_->call("DN_read_req", "", "", buf.end() - buf.begin());
|
||||
|
||||
|
@ -78,7 +80,7 @@ void DataNodeConnectionImpl::async_read_some(const MutableBuffer &buf,
|
|||
}
|
||||
|
||||
void DataNodeConnectionImpl::async_write_some(const ConstBuffer &buf,
|
||||
std::function<void (const asio::error_code & error, std::size_t bytes_transferred) > handler)
|
||||
std::function<void (const boost::system::error_code & error, std::size_t bytes_transferred) > handler)
|
||||
{
|
||||
event_handlers_->call("DN_write_req", "", "", buf.end() - buf.begin());
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
#include "common/util.h"
|
||||
#include "common/new_delete.h"
|
||||
|
||||
#include "asio.hpp"
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
|
@ -43,7 +44,7 @@ public:
|
|||
|
||||
|
||||
struct SocketDeleter {
|
||||
inline void operator()(asio::ip::tcp::socket *sock) {
|
||||
inline void operator()(boost::asio::ip::tcp::socket* sock) {
|
||||
// Cancel may have already closed the socket.
|
||||
std::string err = SafeDisconnect(sock);
|
||||
if(!err.empty()) {
|
||||
|
@ -59,8 +60,8 @@ private:
|
|||
std::mutex state_lock_;
|
||||
public:
|
||||
MEMCHECKED_CLASS(DataNodeConnectionImpl)
|
||||
std::unique_ptr<asio::ip::tcp::socket, SocketDeleter> conn_;
|
||||
std::array<asio::ip::tcp::endpoint, 1> endpoints_;
|
||||
std::unique_ptr<boost::asio::ip::tcp::socket, SocketDeleter> conn_;
|
||||
std::array<boost::asio::ip::tcp::endpoint, 1> endpoints_;
|
||||
std::string uuid_;
|
||||
LibhdfsEvents *event_handlers_;
|
||||
|
||||
|
@ -74,10 +75,10 @@ public:
|
|||
void Cancel() override;
|
||||
|
||||
void async_read_some(const MutableBuffer &buf,
|
||||
std::function<void (const asio::error_code & error, std::size_t bytes_transferred) > handler) override;
|
||||
std::function<void (const boost::system::error_code & error, std::size_t bytes_transferred) > handler) override;
|
||||
|
||||
void async_write_some(const ConstBuffer &buf,
|
||||
std::function<void (const asio::error_code & error, std::size_t bytes_transferred) > handler) override;
|
||||
std::function<void (const boost::system::error_code & error, std::size_t bytes_transferred) > handler) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <future>
|
||||
#include <tuple>
|
||||
|
||||
#include <boost/asio/buffer.hpp>
|
||||
|
||||
#define FMT_THIS_ADDR "this=" << (void*)this
|
||||
|
||||
namespace hdfs {
|
||||
|
@ -72,7 +74,7 @@ void FileHandleImpl::PositionRead(
|
|||
handler(status, bytes_read);
|
||||
};
|
||||
|
||||
AsyncPreadSome(offset, asio::buffer(buf, buf_size), bad_node_tracker_, callback);
|
||||
AsyncPreadSome(offset, boost::asio::buffer(buf, buf_size), bad_node_tracker_, callback);
|
||||
}
|
||||
|
||||
Status FileHandleImpl::PositionRead(void *buf, size_t buf_size, off_t offset, size_t *bytes_read) {
|
||||
|
@ -233,7 +235,7 @@ void FileHandleImpl::AsyncPreadSome(
|
|||
|
||||
uint64_t offset_within_block = offset - block->offset();
|
||||
uint64_t size_within_block = std::min<uint64_t>(
|
||||
block->b().numbytes() - offset_within_block, asio::buffer_size(buffer));
|
||||
block->b().numbytes() - offset_within_block, boost::asio::buffer_size(buffer));
|
||||
|
||||
LOG_DEBUG(kFileHandle, << "FileHandleImpl::AsyncPreadSome("
|
||||
<< FMT_THIS_ADDR << "), ...) Datanode hostname=" << dnHostName << ", IP Address=" << dnIpAddr
|
||||
|
@ -281,7 +283,7 @@ void FileHandleImpl::AsyncPreadSome(
|
|||
if (status.ok()) {
|
||||
reader->AsyncReadBlock(
|
||||
client_name, *block, offset_within_block,
|
||||
asio::buffer(buffer, size_within_block), read_handler);
|
||||
boost::asio::buffer(buffer, size_within_block), read_handler);
|
||||
} else {
|
||||
handler(status, dn_id, 0);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <pwd.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
#define FMT_THIS_ADDR "this=" << (void*)this
|
||||
|
||||
namespace hdfs {
|
||||
|
@ -36,7 +38,7 @@ namespace hdfs {
|
|||
static const char kNamenodeProtocol[] = "org.apache.hadoop.hdfs.protocol.ClientProtocol";
|
||||
static const int kNamenodeProtocolVersion = 1;
|
||||
|
||||
using ::asio::ip::tcp;
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
static constexpr uint16_t kDefaultPort = 8020;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "filesystem.h"
|
||||
#include "common/continuation/asio.h"
|
||||
|
||||
#include <asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
#define FMT_THIS_ADDR "this=" << (void*)this
|
||||
|
||||
using ::asio::ip::tcp;
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
|
||||
#include <future>
|
||||
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/read.hpp>
|
||||
#include <boost/asio/completion_condition.hpp>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
#define FMT_CONT_AND_PARENT_ADDR "this=" << (void*)this << ", parent=" << (void*)parent_
|
||||
|
@ -113,7 +117,7 @@ void BlockReaderImpl::AsyncRequestBlock(const std::string &client_name,
|
|||
auto read_pb_message =
|
||||
new continuation::ReadDelimitedPBMessageContinuation<AsyncStream, 16384>(dn_, &s->response);
|
||||
|
||||
m->Push(asio_continuation::Write(dn_, asio::buffer(s->header))).Push(read_pb_message);
|
||||
m->Push(asio_continuation::Write(dn_, boost::asio::buffer(s->header))).Push(read_pb_message);
|
||||
|
||||
m->Run([this, handler, offset](const Status &status, const State &s) { Status stat = status;
|
||||
if (stat.ok()) {
|
||||
|
@ -167,7 +171,7 @@ struct BlockReaderImpl::ReadPacketHeader : continuation::Continuation
|
|||
|
||||
parent_->packet_data_read_bytes_ = 0;
|
||||
parent_->packet_len_ = 0;
|
||||
auto handler = [next, this](const asio::error_code &ec, size_t) {
|
||||
auto handler = [next, this](const boost::system::error_code &ec, size_t) {
|
||||
Status status;
|
||||
if (ec) {
|
||||
status = Status(ec.value(), ec.message().c_str());
|
||||
|
@ -191,7 +195,7 @@ struct BlockReaderImpl::ReadPacketHeader : continuation::Continuation
|
|||
next(status);
|
||||
};
|
||||
|
||||
asio::async_read(*parent_->dn_, asio::buffer(buf_),
|
||||
boost::asio::async_read(*parent_->dn_, boost::asio::buffer(buf_),
|
||||
std::bind(&ReadPacketHeader::CompletionHandler, this,
|
||||
std::placeholders::_1, std::placeholders::_2), handler);
|
||||
}
|
||||
|
@ -215,7 +219,7 @@ private:
|
|||
return ntohs(*reinterpret_cast<const short *>(&buf_[kHeaderLenOffset]));
|
||||
}
|
||||
|
||||
size_t CompletionHandler(const asio::error_code &ec, size_t transferred) {
|
||||
size_t CompletionHandler(const boost::system::error_code &ec, size_t transferred) {
|
||||
if (ec) {
|
||||
return 0;
|
||||
} else if (transferred < kHeaderStart) {
|
||||
|
@ -245,7 +249,7 @@ struct BlockReaderImpl::ReadChecksum : continuation::Continuation
|
|||
|
||||
std::shared_ptr<DataNodeConnection> keep_conn_alive_ = shared_conn_;
|
||||
|
||||
auto handler = [parent, next, this, keep_conn_alive_](const asio::error_code &ec, size_t)
|
||||
auto handler = [parent, next, this, keep_conn_alive_](const boost::system::error_code &ec, size_t)
|
||||
{
|
||||
Status status;
|
||||
if (ec) {
|
||||
|
@ -266,7 +270,7 @@ struct BlockReaderImpl::ReadChecksum : continuation::Continuation
|
|||
|
||||
parent->checksum_.resize(parent->packet_len_ - sizeof(int) - parent->header_.datalen());
|
||||
|
||||
asio::async_read(*parent->dn_, asio::buffer(parent->checksum_), handler);
|
||||
boost::asio::async_read(*parent->dn_, boost::asio::buffer(parent->checksum_), handler);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -279,7 +283,7 @@ private:
|
|||
struct BlockReaderImpl::ReadData : continuation::Continuation
|
||||
{
|
||||
ReadData(BlockReaderImpl *parent, std::shared_ptr<size_t> bytes_transferred,
|
||||
const asio::mutable_buffers_1 &buf) : parent_(parent),
|
||||
const boost::asio::mutable_buffers_1 &buf) : parent_(parent),
|
||||
bytes_transferred_(bytes_transferred), buf_(buf), shared_conn_(parent->dn_)
|
||||
{
|
||||
buf_.begin();
|
||||
|
@ -293,7 +297,7 @@ struct BlockReaderImpl::ReadData : continuation::Continuation
|
|||
LOG_TRACE(kBlockReader, << "BlockReaderImpl::ReadData::Run("
|
||||
<< FMT_CONT_AND_PARENT_ADDR << ") called");
|
||||
auto handler =
|
||||
[next, this](const asio::error_code &ec, size_t transferred) {
|
||||
[next, this](const boost::system::error_code &ec, size_t transferred) {
|
||||
Status status;
|
||||
if (ec) {
|
||||
status = Status(ec.value(), ec.message().c_str());
|
||||
|
@ -320,13 +324,13 @@ struct BlockReaderImpl::ReadData : continuation::Continuation
|
|||
|
||||
auto data_len = parent_->header_.datalen() - parent_->packet_data_read_bytes_;
|
||||
|
||||
asio::async_read(*parent_->dn_, buf_, asio::transfer_exactly(data_len), handler);
|
||||
boost::asio::async_read(*parent_->dn_, buf_, boost::asio::transfer_exactly(data_len), handler);
|
||||
}
|
||||
|
||||
private:
|
||||
BlockReaderImpl *parent_;
|
||||
std::shared_ptr<size_t> bytes_transferred_;
|
||||
const asio::mutable_buffers_1 buf_;
|
||||
const boost::asio::mutable_buffers_1 buf_;
|
||||
|
||||
// Keep DNConnection alive.
|
||||
std::shared_ptr<DataNodeConnection> shared_conn_;
|
||||
|
@ -337,7 +341,7 @@ struct BlockReaderImpl::ReadPadding : continuation::Continuation
|
|||
ReadPadding(BlockReaderImpl *parent) : parent_(parent),
|
||||
padding_(parent->chunk_padding_bytes_),
|
||||
bytes_transferred_(std::make_shared<size_t>(0)),
|
||||
read_data_(new ReadData(parent, bytes_transferred_, asio::buffer(padding_))),
|
||||
read_data_(new ReadData(parent, bytes_transferred_, boost::asio::buffer(padding_))),
|
||||
shared_conn_(parent->dn_) {}
|
||||
|
||||
virtual void Run(const Next &next) override {
|
||||
|
@ -505,7 +509,7 @@ private:
|
|||
struct BlockReaderImpl::ReadBlockContinuation : continuation::Continuation
|
||||
{
|
||||
ReadBlockContinuation(BlockReader *reader, MutableBuffer buffer, size_t *transferred)
|
||||
: reader_(reader), buffer_(buffer), buffer_size_(asio::buffer_size(buffer)), transferred_(transferred) {}
|
||||
: reader_(reader), buffer_(buffer), buffer_size_(boost::asio::buffer_size(buffer)), transferred_(transferred) {}
|
||||
|
||||
virtual void Run(const Next &next) override {
|
||||
LOG_TRACE(kBlockReader, << "BlockReaderImpl::ReadBlockContinuation::Run("
|
||||
|
@ -532,7 +536,7 @@ private:
|
|||
next_(status);
|
||||
} else {
|
||||
reader_->AsyncReadPacket(
|
||||
asio::buffer(buffer_ + *transferred_, buffer_size_ - *transferred_),
|
||||
boost::asio::buffer(buffer_ + *transferred_, buffer_size_ - *transferred_),
|
||||
std::bind(&ReadBlockContinuation::OnReadData, this, _1, _2));
|
||||
}
|
||||
}
|
||||
|
@ -551,7 +555,7 @@ void BlockReaderImpl::AsyncReadBlock(
|
|||
auto m = continuation::Pipeline<size_t>::Create(cancel_state_);
|
||||
size_t * bytesTransferred = &m->state();
|
||||
|
||||
size_t size = asio::buffer_size(buffer);
|
||||
size_t size = boost::asio::buffer_size(buffer);
|
||||
|
||||
m->Push(new RequestBlockContinuation(this, client_name, &block.b(), size, offset))
|
||||
.Push(new ReadBlockContinuation(this, buffer, bytesTransferred));
|
||||
|
|
|
@ -21,8 +21,10 @@
|
|||
#include "common/sasl_authenticator.h"
|
||||
#include "common/async_stream.h"
|
||||
#include "connection/datanodeconnection.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
|
@ -45,13 +47,13 @@ public:
|
|||
template <class Handler> void Handshake(const Handler &next);
|
||||
|
||||
void async_read_some(const MutableBuffer &buf,
|
||||
std::function<void (const asio::error_code & error,
|
||||
std::function<void (const boost::system::error_code & error,
|
||||
std::size_t bytes_transferred) > handler) override {
|
||||
stream_->async_read_some(buf, handler);
|
||||
}
|
||||
|
||||
void async_write_some(const ConstBuffer &buf,
|
||||
std::function<void (const asio::error_code & error,
|
||||
std::function<void (const boost::system::error_code & error,
|
||||
std::size_t bytes_transferred) > handler) override {
|
||||
stream_->async_write_some(buf, handler);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#include "common/continuation/asio.h"
|
||||
#include "common/continuation/protobuf.h"
|
||||
|
||||
#include <asio/read.hpp>
|
||||
#include <asio/buffer.hpp>
|
||||
#include <boost/asio/read.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
|
@ -101,7 +101,7 @@ void DataTransferSaslStream<Stream>::Handshake(const Handler &next) {
|
|||
using ::hdfs::continuation::WriteDelimitedPBMessage;
|
||||
|
||||
static const int kMagicNumber = htonl(kDataTransferSasl);
|
||||
static const asio::const_buffers_1 kMagicNumberBuffer = asio::buffer(
|
||||
static const boost::asio::const_buffers_1 kMagicNumberBuffer = boost::asio::buffer(
|
||||
reinterpret_cast<const char *>(kMagicNumber), sizeof(kMagicNumber));
|
||||
|
||||
struct State {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
namespace hdfs {
|
||||
|
||||
static std::string format_endpoints(const std::vector<::asio::ip::tcp::endpoint> &pts) {
|
||||
static std::string format_endpoints(const std::vector<boost::asio::ip::tcp::endpoint> &pts) {
|
||||
std::stringstream ss;
|
||||
for(unsigned int i=0; i<pts.size(); i++)
|
||||
if(i == pts.size() - 1)
|
||||
|
@ -66,7 +66,7 @@ HANamenodeTracker::HANamenodeTracker(const std::vector<ResolvedNamenodeInfo> &se
|
|||
|
||||
HANamenodeTracker::~HANamenodeTracker() {}
|
||||
|
||||
bool HANamenodeTracker::GetFailoverAndUpdate(const std::vector<::asio::ip::tcp::endpoint>& current_endpoints,
|
||||
bool HANamenodeTracker::GetFailoverAndUpdate(const std::vector<boost::asio::ip::tcp::endpoint>& current_endpoints,
|
||||
ResolvedNamenodeInfo& out)
|
||||
{
|
||||
mutex_guard swap_lock(swap_lock_);
|
||||
|
@ -117,7 +117,7 @@ bool HANamenodeTracker::GetFailoverAndUpdate(const std::vector<::asio::ip::tcp::
|
|||
}
|
||||
|
||||
|
||||
bool HANamenodeTracker::IsCurrentActive_locked(const ::asio::ip::tcp::endpoint &ep) const {
|
||||
bool HANamenodeTracker::IsCurrentActive_locked(const boost::asio::ip::tcp::endpoint &ep) const {
|
||||
for(unsigned int i=0;i<active_info_.endpoints.size();i++) {
|
||||
if(ep.address() == active_info_.endpoints[i].address()) {
|
||||
if(ep.port() != active_info_.endpoints[i].port())
|
||||
|
@ -128,7 +128,7 @@ bool HANamenodeTracker::IsCurrentActive_locked(const ::asio::ip::tcp::endpoint &
|
|||
return false;
|
||||
}
|
||||
|
||||
bool HANamenodeTracker::IsCurrentStandby_locked(const ::asio::ip::tcp::endpoint &ep) const {
|
||||
bool HANamenodeTracker::IsCurrentStandby_locked(const boost::asio::ip::tcp::endpoint &ep) const {
|
||||
for(unsigned int i=0;i<standby_info_.endpoints.size();i++) {
|
||||
if(ep.address() == standby_info_.endpoints[i].address()) {
|
||||
if(ep.port() != standby_info_.endpoints[i].port())
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "common/libhdfs_events_impl.h"
|
||||
#include "common/namenode_info.h"
|
||||
|
||||
#include <asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
@ -52,13 +52,13 @@ class HANamenodeTracker {
|
|||
// currently being used. Swap internal state and set out to other node.
|
||||
// Note: This will always mutate internal state. Use IsCurrentActive/Standby to
|
||||
// get info without changing state
|
||||
bool GetFailoverAndUpdate(const std::vector<::asio::ip::tcp::endpoint>& current_endpoints,
|
||||
bool GetFailoverAndUpdate(const std::vector<boost::asio::ip::tcp::endpoint>& current_endpoints,
|
||||
ResolvedNamenodeInfo& out);
|
||||
|
||||
private:
|
||||
// See if endpoint ep is part of the list of endpoints for the active or standby NN
|
||||
bool IsCurrentActive_locked(const ::asio::ip::tcp::endpoint &ep) const;
|
||||
bool IsCurrentStandby_locked(const ::asio::ip::tcp::endpoint &ep) const;
|
||||
bool IsCurrentActive_locked(const boost::asio::ip::tcp::endpoint &ep) const;
|
||||
bool IsCurrentStandby_locked(const boost::asio::ip::tcp::endpoint &ep) const;
|
||||
|
||||
// If HA should be enabled, according to our options and runtime info like # nodes provided
|
||||
bool enabled_;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
||||
|
||||
#include <asio/deadline_timer.hpp>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
|
||||
|
||||
namespace hdfs {
|
||||
|
@ -59,7 +59,7 @@ class Request {
|
|||
|
||||
int call_id() const { return call_id_; }
|
||||
std::string method_name() const { return method_name_; }
|
||||
::asio::deadline_timer &timer() { return timer_; }
|
||||
boost::asio::deadline_timer &timer() { return timer_; }
|
||||
int IncrementRetryCount() { return retry_count_++; }
|
||||
int IncrementFailoverCount();
|
||||
void GetPacket(std::string *res) const;
|
||||
|
@ -75,7 +75,7 @@ class Request {
|
|||
const std::string method_name_;
|
||||
const int call_id_;
|
||||
|
||||
::asio::deadline_timer timer_;
|
||||
boost::asio::deadline_timer timer_;
|
||||
std::string payload_;
|
||||
const Handler handler_;
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
#include <deque>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
typedef const std::function<void(const Status &)> RpcCallback;
|
||||
|
@ -57,10 +59,10 @@ class RpcConnection : public std::enable_shared_from_this<RpcConnection> {
|
|||
|
||||
// Note that a single server can have multiple endpoints - especially both
|
||||
// an ipv4 and ipv6 endpoint
|
||||
virtual void Connect(const std::vector<::asio::ip::tcp::endpoint> &server,
|
||||
virtual void Connect(const std::vector<boost::asio::ip::tcp::endpoint> &server,
|
||||
const AuthInfo & auth_info,
|
||||
RpcCallback &handler) = 0;
|
||||
virtual void ConnectAndFlush(const std::vector<::asio::ip::tcp::endpoint> &server) = 0;
|
||||
virtual void ConnectAndFlush(const std::vector<boost::asio::ip::tcp::endpoint> &server) = 0;
|
||||
virtual void Disconnect() = 0;
|
||||
|
||||
void StartReading();
|
||||
|
@ -110,9 +112,9 @@ class RpcConnection : public std::enable_shared_from_this<RpcConnection> {
|
|||
virtual void SendContext(RpcCallback &handler) = 0;
|
||||
void ContextComplete(const Status &s);
|
||||
|
||||
virtual void OnSendCompleted(const ::asio::error_code &ec,
|
||||
virtual void OnSendCompleted(const boost::system::error_code &ec,
|
||||
size_t transferred) = 0;
|
||||
virtual void OnRecvCompleted(const ::asio::error_code &ec,
|
||||
virtual void OnRecvCompleted(const boost::system::error_code &ec,
|
||||
size_t transferred) = 0;
|
||||
virtual void FlushPendingRequests()=0; // Synchronously write the next request
|
||||
|
||||
|
@ -133,10 +135,10 @@ class RpcConnection : public std::enable_shared_from_this<RpcConnection> {
|
|||
|
||||
Status HandleRpcResponse(std::shared_ptr<Response> response);
|
||||
void HandleRpcTimeout(std::shared_ptr<Request> req,
|
||||
const ::asio::error_code &ec);
|
||||
const boost::system::error_code &ec);
|
||||
void CommsError(const Status &status);
|
||||
|
||||
void ClearAndDisconnect(const ::asio::error_code &ec);
|
||||
void ClearAndDisconnect(const boost::system::error_code &ec);
|
||||
std::shared_ptr<Request> RemoveFromRunningQueue(int call_id);
|
||||
|
||||
std::weak_ptr<LockFreeRpcEngine> engine_;
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "ProtobufRpcEngine.pb.h"
|
||||
#include "IpcConnectionContext.pb.h"
|
||||
|
||||
#include <boost/asio/error.hpp>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
namespace pb = ::google::protobuf;
|
||||
|
@ -89,7 +91,7 @@ void RpcConnection::StartReading() {
|
|||
}
|
||||
|
||||
service->PostLambda(
|
||||
[shared_this, this] () { OnRecvCompleted(::asio::error_code(), 0); }
|
||||
[shared_this, this] () { OnRecvCompleted(boost::system::error_code(), 0); }
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -248,8 +250,8 @@ Status RpcConnection::HandleRpcResponse(std::shared_ptr<Response> response) {
|
|||
}
|
||||
|
||||
void RpcConnection::HandleRpcTimeout(std::shared_ptr<Request> req,
|
||||
const ::asio::error_code &ec) {
|
||||
if (ec.value() == asio::error::operation_aborted) {
|
||||
const boost::system::error_code &ec) {
|
||||
if (ec.value() == boost::asio::error::operation_aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -260,7 +262,7 @@ void RpcConnection::HandleRpcTimeout(std::shared_ptr<Request> req,
|
|||
return;
|
||||
}
|
||||
|
||||
Status stat = ToStatus(ec ? ec : make_error_code(::asio::error::timed_out));
|
||||
Status stat = ToStatus(ec ? ec : make_error_code(boost::asio::error::timed_out));
|
||||
|
||||
r->OnResponseArrived(nullptr, stat);
|
||||
}
|
||||
|
@ -469,7 +471,7 @@ void RpcConnection::CommsError(const Status &status) {
|
|||
pinnedEngine->AsyncRpcCommsError(status, shared_from_this(), requestsToReturn);
|
||||
}
|
||||
|
||||
void RpcConnection::ClearAndDisconnect(const ::asio::error_code &ec) {
|
||||
void RpcConnection::ClearAndDisconnect(const boost::system::error_code &ec) {
|
||||
Disconnect();
|
||||
std::vector<std::shared_ptr<Request>> requests;
|
||||
std::transform(sent_requests_.begin(), sent_requests_.end(),
|
||||
|
|
|
@ -28,9 +28,11 @@
|
|||
#include "common/libhdfs_events_impl.h"
|
||||
#include "hdfspp/ioservice.h"
|
||||
|
||||
#include <asio/connect.hpp>
|
||||
#include <asio/read.hpp>
|
||||
#include <asio/write.hpp>
|
||||
#include <boost/asio/connect.hpp>
|
||||
#include <boost/asio/read.hpp>
|
||||
#include <boost/asio/write.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||
|
||||
#include <system_error>
|
||||
|
||||
|
@ -44,17 +46,17 @@ public:
|
|||
RpcConnectionImpl(std::shared_ptr<RpcEngine> engine);
|
||||
virtual ~RpcConnectionImpl() override;
|
||||
|
||||
virtual void Connect(const std::vector<::asio::ip::tcp::endpoint> &server,
|
||||
virtual void Connect(const std::vector<boost::asio::ip::tcp::endpoint> &server,
|
||||
const AuthInfo & auth_info,
|
||||
RpcCallback &handler) override;
|
||||
virtual void ConnectAndFlush(
|
||||
const std::vector<::asio::ip::tcp::endpoint> &server) override;
|
||||
const std::vector<boost::asio::ip::tcp::endpoint> &server) override;
|
||||
virtual void SendHandshake(RpcCallback &handler) override;
|
||||
virtual void SendContext(RpcCallback &handler) override;
|
||||
virtual void Disconnect() override;
|
||||
virtual void OnSendCompleted(const ::asio::error_code &ec,
|
||||
virtual void OnSendCompleted(const boost::system::error_code &ec,
|
||||
size_t transferred) override;
|
||||
virtual void OnRecvCompleted(const ::asio::error_code &ec,
|
||||
virtual void OnRecvCompleted(const boost::system::error_code &ec,
|
||||
size_t transferred) override;
|
||||
virtual void FlushPendingRequests() override;
|
||||
|
||||
|
@ -65,12 +67,12 @@ public:
|
|||
|
||||
private:
|
||||
const Options options_;
|
||||
::asio::ip::tcp::endpoint current_endpoint_;
|
||||
std::vector<::asio::ip::tcp::endpoint> additional_endpoints_;
|
||||
boost::asio::ip::tcp::endpoint current_endpoint_;
|
||||
std::vector<boost::asio::ip::tcp::endpoint> additional_endpoints_;
|
||||
Socket socket_;
|
||||
::asio::deadline_timer connect_timer_;
|
||||
boost::asio::deadline_timer connect_timer_;
|
||||
|
||||
void ConnectComplete(const ::asio::error_code &ec, const ::asio::ip::tcp::endpoint &remote);
|
||||
void ConnectComplete(const boost::system::error_code &ec, const boost::asio::ip::tcp::endpoint &remote);
|
||||
};
|
||||
|
||||
template <class Socket>
|
||||
|
@ -95,7 +97,7 @@ RpcConnectionImpl<Socket>::~RpcConnectionImpl() {
|
|||
|
||||
template <class Socket>
|
||||
void RpcConnectionImpl<Socket>::Connect(
|
||||
const std::vector<::asio::ip::tcp::endpoint> &server,
|
||||
const std::vector<boost::asio::ip::tcp::endpoint> &server,
|
||||
const AuthInfo & auth_info,
|
||||
RpcCallback &handler) {
|
||||
LOG_TRACE(kRPC, << "RpcConnectionImpl::Connect called");
|
||||
|
@ -124,7 +126,7 @@ void RpcConnectionImpl<Socket>::Connect(
|
|||
|
||||
template <class Socket>
|
||||
void RpcConnectionImpl<Socket>::ConnectAndFlush(
|
||||
const std::vector<::asio::ip::tcp::endpoint> &server) {
|
||||
const std::vector<boost::asio::ip::tcp::endpoint> &server) {
|
||||
|
||||
LOG_INFO(kRPC, << "ConnectAndFlush called");
|
||||
std::lock_guard<std::mutex> state_lock(connection_state_lock_);
|
||||
|
@ -147,29 +149,29 @@ void RpcConnectionImpl<Socket>::ConnectAndFlush(
|
|||
|
||||
// Take the first endpoint, but remember the alternatives for later
|
||||
additional_endpoints_ = server;
|
||||
::asio::ip::tcp::endpoint first_endpoint = additional_endpoints_.front();
|
||||
boost::asio::ip::tcp::endpoint first_endpoint = additional_endpoints_.front();
|
||||
additional_endpoints_.erase(additional_endpoints_.begin());
|
||||
current_endpoint_ = first_endpoint;
|
||||
|
||||
auto shared_this = shared_from_this();
|
||||
socket_.async_connect(first_endpoint, [shared_this, this, first_endpoint](const ::asio::error_code &ec) {
|
||||
socket_.async_connect(first_endpoint, [shared_this, this, first_endpoint](const boost::system::error_code &ec) {
|
||||
ConnectComplete(ec, first_endpoint);
|
||||
});
|
||||
|
||||
// Prompt the timer to timeout
|
||||
auto weak_this = std::weak_ptr<RpcConnection>(shared_this);
|
||||
connect_timer_.expires_from_now(
|
||||
std::chrono::milliseconds(options_.rpc_connect_timeout));
|
||||
connect_timer_.async_wait([shared_this, this, first_endpoint](const ::asio::error_code &ec) {
|
||||
boost::posix_time::milliseconds(options_.rpc_connect_timeout));
|
||||
connect_timer_.async_wait([shared_this, this, first_endpoint](const boost::system::error_code &ec) {
|
||||
if (ec)
|
||||
ConnectComplete(ec, first_endpoint);
|
||||
else
|
||||
ConnectComplete(make_error_code(asio::error::host_unreachable), first_endpoint);
|
||||
ConnectComplete(make_error_code(boost::asio::error::host_unreachable), first_endpoint);
|
||||
});
|
||||
}
|
||||
|
||||
template <class Socket>
|
||||
void RpcConnectionImpl<Socket>::ConnectComplete(const ::asio::error_code &ec, const ::asio::ip::tcp::endpoint & remote) {
|
||||
void RpcConnectionImpl<Socket>::ConnectComplete(const boost::system::error_code &ec, const boost::asio::ip::tcp::endpoint & remote) {
|
||||
auto shared_this = RpcConnectionImpl<Socket>::shared_from_this();
|
||||
std::lock_guard<std::mutex> state_lock(connection_state_lock_);
|
||||
connect_timer_.cancel();
|
||||
|
@ -211,20 +213,20 @@ void RpcConnectionImpl<Socket>::ConnectComplete(const ::asio::error_code &ec, co
|
|||
if (!additional_endpoints_.empty()) {
|
||||
// If we have additional endpoints, keep trying until we either run out or
|
||||
// hit one
|
||||
::asio::ip::tcp::endpoint next_endpoint = additional_endpoints_.front();
|
||||
boost::asio::ip::tcp::endpoint next_endpoint = additional_endpoints_.front();
|
||||
additional_endpoints_.erase(additional_endpoints_.begin());
|
||||
current_endpoint_ = next_endpoint;
|
||||
|
||||
socket_.async_connect(next_endpoint, [shared_this, this, next_endpoint](const ::asio::error_code &ec) {
|
||||
socket_.async_connect(next_endpoint, [shared_this, this, next_endpoint](const boost::system::error_code &ec) {
|
||||
ConnectComplete(ec, next_endpoint);
|
||||
});
|
||||
connect_timer_.expires_from_now(
|
||||
std::chrono::milliseconds(options_.rpc_connect_timeout));
|
||||
connect_timer_.async_wait([shared_this, this, next_endpoint](const ::asio::error_code &ec) {
|
||||
boost::posix_time::milliseconds(options_.rpc_connect_timeout));
|
||||
connect_timer_.async_wait([shared_this, this, next_endpoint](const boost::system::error_code &ec) {
|
||||
if (ec)
|
||||
ConnectComplete(ec, next_endpoint);
|
||||
else
|
||||
ConnectComplete(make_error_code(asio::error::host_unreachable), next_endpoint);
|
||||
ConnectComplete(make_error_code(boost::asio::error::host_unreachable), next_endpoint);
|
||||
});
|
||||
} else {
|
||||
CommsError(status);
|
||||
|
@ -241,9 +243,9 @@ void RpcConnectionImpl<Socket>::SendHandshake(RpcCallback &handler) {
|
|||
|
||||
auto shared_this = shared_from_this();
|
||||
auto handshake_packet = PrepareHandshakePacket();
|
||||
::asio::async_write(socket_, asio::buffer(*handshake_packet),
|
||||
boost::asio::async_write(socket_, boost::asio::buffer(*handshake_packet),
|
||||
[handshake_packet, handler, shared_this, this](
|
||||
const ::asio::error_code &ec, size_t) {
|
||||
const boost::system::error_code &ec, size_t) {
|
||||
Status status = ToStatus(ec);
|
||||
handler(status);
|
||||
});
|
||||
|
@ -257,16 +259,16 @@ void RpcConnectionImpl<Socket>::SendContext(RpcCallback &handler) {
|
|||
|
||||
auto shared_this = shared_from_this();
|
||||
auto context_packet = PrepareContextPacket();
|
||||
::asio::async_write(socket_, asio::buffer(*context_packet),
|
||||
boost::asio::async_write(socket_, boost::asio::buffer(*context_packet),
|
||||
[context_packet, handler, shared_this, this](
|
||||
const ::asio::error_code &ec, size_t) {
|
||||
const boost::system::error_code &ec, size_t) {
|
||||
Status status = ToStatus(ec);
|
||||
handler(status);
|
||||
});
|
||||
}
|
||||
|
||||
template <class Socket>
|
||||
void RpcConnectionImpl<Socket>::OnSendCompleted(const ::asio::error_code &ec,
|
||||
void RpcConnectionImpl<Socket>::OnSendCompleted(const boost::system::error_code &ec,
|
||||
size_t) {
|
||||
using std::placeholders::_1;
|
||||
using std::placeholders::_2;
|
||||
|
@ -340,16 +342,16 @@ void RpcConnectionImpl<Socket>::FlushPendingRequests() {
|
|||
outgoing_request_ = req;
|
||||
|
||||
req->timer().expires_from_now(
|
||||
std::chrono::milliseconds(options_.rpc_timeout));
|
||||
req->timer().async_wait([weak_this, weak_req, this](const ::asio::error_code &ec) {
|
||||
boost::posix_time::milliseconds(options_.rpc_timeout));
|
||||
req->timer().async_wait([weak_this, weak_req, this](const boost::system::error_code &ec) {
|
||||
auto timeout_this = weak_this.lock();
|
||||
auto timeout_req = weak_req.lock();
|
||||
if (timeout_this && timeout_req)
|
||||
this->HandleRpcTimeout(timeout_req, ec);
|
||||
});
|
||||
|
||||
asio::async_write(socket_, asio::buffer(*payload),
|
||||
[shared_this, this, payload](const ::asio::error_code &ec,
|
||||
boost::asio::async_write(socket_, boost::asio::buffer(*payload),
|
||||
[shared_this, this, payload](const boost::system::error_code &ec,
|
||||
size_t size) {
|
||||
OnSendCompleted(ec, size);
|
||||
});
|
||||
|
@ -374,13 +376,13 @@ void RpcConnectionImpl<Socket>::FlushPendingRequests() {
|
|||
|
||||
|
||||
template <class Socket>
|
||||
void RpcConnectionImpl<Socket>::OnRecvCompleted(const ::asio::error_code &original_ec,
|
||||
void RpcConnectionImpl<Socket>::OnRecvCompleted(const boost::system::error_code &original_ec,
|
||||
size_t) {
|
||||
using std::placeholders::_1;
|
||||
using std::placeholders::_2;
|
||||
std::lock_guard<std::mutex> state_lock(connection_state_lock_);
|
||||
|
||||
::asio::error_code my_ec(original_ec);
|
||||
boost::system::error_code my_ec(original_ec);
|
||||
|
||||
LOG_TRACE(kRPC, << "RpcConnectionImpl::OnRecvCompleted called");
|
||||
|
||||
|
@ -390,7 +392,7 @@ void RpcConnectionImpl<Socket>::OnRecvCompleted(const ::asio::error_code &origin
|
|||
event_response event_resp = event_handlers_->call(FS_NN_READ_EVENT, cluster_name_.c_str(), 0);
|
||||
#ifndef LIBHDFSPP_SIMULATE_ERROR_DISABLED
|
||||
if (event_resp.response_type() == event_response::kTest_Error) {
|
||||
my_ec = std::make_error_code(std::errc::network_down);
|
||||
my_ec = boost::system::error_code(boost::system::errc::errc_t::network_down, boost::system::system_category());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -399,7 +401,7 @@ void RpcConnectionImpl<Socket>::OnRecvCompleted(const ::asio::error_code &origin
|
|||
case 0:
|
||||
// No errors
|
||||
break;
|
||||
case asio::error::operation_aborted:
|
||||
case boost::asio::error::operation_aborted:
|
||||
// The event loop has been shut down. Ignore the error.
|
||||
return;
|
||||
default:
|
||||
|
@ -414,20 +416,20 @@ void RpcConnectionImpl<Socket>::OnRecvCompleted(const ::asio::error_code &origin
|
|||
|
||||
if (current_response_state_->state_ == Response::kReadLength) {
|
||||
current_response_state_->state_ = Response::kReadContent;
|
||||
auto buf = ::asio::buffer(reinterpret_cast<char *>(¤t_response_state_->length_),
|
||||
auto buf = boost::asio::buffer(reinterpret_cast<char *>(¤t_response_state_->length_),
|
||||
sizeof(current_response_state_->length_));
|
||||
asio::async_read(
|
||||
boost::asio::async_read(
|
||||
socket_, buf,
|
||||
[shared_this, this](const ::asio::error_code &ec, size_t size) {
|
||||
[shared_this, this](const boost::system::error_code &ec, size_t size) {
|
||||
OnRecvCompleted(ec, size);
|
||||
});
|
||||
} else if (current_response_state_->state_ == Response::kReadContent) {
|
||||
current_response_state_->state_ = Response::kParseResponse;
|
||||
current_response_state_->length_ = ntohl(current_response_state_->length_);
|
||||
current_response_state_->data_.resize(current_response_state_->length_);
|
||||
asio::async_read(
|
||||
socket_, ::asio::buffer(current_response_state_->data_),
|
||||
[shared_this, this](const ::asio::error_code &ec, size_t size) {
|
||||
boost::asio::async_read(
|
||||
socket_, boost::asio::buffer(current_response_state_->data_),
|
||||
[shared_this, this](const boost::system::error_code &ec, size_t size) {
|
||||
OnRecvCompleted(ec, size);
|
||||
});
|
||||
} else if (current_response_state_->state_ == Response::kParseResponse) {
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
template <class T>
|
||||
|
@ -171,7 +173,7 @@ std::shared_ptr<RpcConnection> RpcEngine::NewConnection()
|
|||
{
|
||||
LOG_DEBUG(kRPC, << "RpcEngine::NewConnection called");
|
||||
|
||||
return std::make_shared<RpcConnectionImpl<::asio::ip::tcp::socket>>(shared_from_this());
|
||||
return std::make_shared<RpcConnectionImpl<boost::asio::ip::tcp::socket>>(shared_from_this());
|
||||
}
|
||||
|
||||
std::shared_ptr<RpcConnection> RpcEngine::InitializeConnection()
|
||||
|
@ -307,8 +309,8 @@ void RpcEngine::RpcCommsError(
|
|||
if (head_action->delayMillis > 0) {
|
||||
auto weak_conn = std::weak_ptr<RpcConnection>(conn_);
|
||||
retry_timer.expires_from_now(
|
||||
std::chrono::milliseconds(head_action->delayMillis));
|
||||
retry_timer.async_wait([this, weak_conn](asio::error_code ec) {
|
||||
boost::posix_time::milliseconds(head_action->delayMillis));
|
||||
retry_timer.async_wait([this, weak_conn](boost::system::error_code ec) {
|
||||
auto strong_conn = weak_conn.lock();
|
||||
if ( (!ec) && (strong_conn) ) {
|
||||
strong_conn->ConnectAndFlush(last_endpoints_);
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
|
||||
#include <google/protobuf/message_lite.h>
|
||||
|
||||
#include <asio/ip/tcp.hpp>
|
||||
#include <asio/deadline_timer.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
@ -160,7 +160,7 @@ protected:
|
|||
static std::string getRandomClientId();
|
||||
|
||||
// Remember all of the last endpoints in case we need to reconnect and retry
|
||||
std::vector<::asio::ip::tcp::endpoint> last_endpoints_;
|
||||
std::vector<boost::asio::ip::tcp::endpoint> last_endpoints_;
|
||||
|
||||
private:
|
||||
mutable std::shared_ptr<IoService> io_service_;
|
||||
|
@ -173,7 +173,7 @@ private:
|
|||
AuthInfo auth_info_;
|
||||
std::string cluster_name_;
|
||||
std::atomic_int call_id_;
|
||||
::asio::deadline_timer retry_timer;
|
||||
boost::asio::deadline_timer retry_timer;
|
||||
|
||||
std::shared_ptr<LibhdfsEvents> event_handlers_;
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
find_package(Boost REQUIRED COMPONENTS date_time)
|
||||
|
||||
# Delegate some functionality to libhdfs, until libhdfspp is complete.
|
||||
set (LIBHDFS_SRC_DIR ../../libhdfs)
|
||||
set (LIBHDFS_TESTS_DIR ../../libhdfs-tests)
|
||||
|
@ -81,7 +83,7 @@ add_memcheck_test(retry_policy retry_policy_test)
|
|||
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
add_executable(rpc_engine_test rpc_engine_test.cc ${PROTO_TEST_SRCS} ${PROTO_TEST_HDRS})
|
||||
target_link_libraries(rpc_engine_test test_common rpc proto common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(rpc_engine_test test_common rpc proto common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
|
||||
add_memcheck_test(rpc_engine rpc_engine_test)
|
||||
|
||||
add_executable(bad_datanode_test bad_datanode_test.cc)
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
|
||||
using hadoop::common::TokenProto;
|
||||
using hadoop::hdfs::DatanodeInfoProto;
|
||||
using hadoop::hdfs::DatanodeIDProto;
|
||||
|
@ -42,7 +45,7 @@ class MockReader : public BlockReader {
|
|||
public:
|
||||
MOCK_METHOD2(
|
||||
AsyncReadPacket,
|
||||
void(const asio::mutable_buffers_1 &,
|
||||
void(const boost::asio::mutable_buffers_1 &,
|
||||
const std::function<void(const Status &, size_t transferred)> &));
|
||||
|
||||
MOCK_METHOD5(AsyncRequestBlock,
|
||||
|
@ -69,17 +72,17 @@ class MockDNConnection : public DataNodeConnection, public std::enable_shared_fr
|
|||
}
|
||||
|
||||
void async_read_some(const MutableBuffer &buf,
|
||||
std::function<void (const asio::error_code & error,
|
||||
std::function<void (const boost::system::error_code & error,
|
||||
std::size_t bytes_transferred) > handler) override {
|
||||
(void)buf;
|
||||
handler(asio::error::fault, 0);
|
||||
handler(boost::asio::error::fault, 0);
|
||||
}
|
||||
|
||||
void async_write_some(const ConstBuffer &buf,
|
||||
std::function<void (const asio::error_code & error,
|
||||
std::function<void (const boost::system::error_code & error,
|
||||
std::size_t bytes_transferred) > handler) override {
|
||||
(void)buf;
|
||||
handler(asio::error::fault, 0);
|
||||
handler(boost::asio::error::fault, 0);
|
||||
}
|
||||
|
||||
virtual void Cancel() override {
|
||||
|
@ -141,7 +144,7 @@ TEST(BadDataNodeTest, TestNoNodes) {
|
|||
size_t read = 0;
|
||||
|
||||
// Exclude the one datanode with the data
|
||||
is.AsyncPreadSome(0, asio::buffer(buf, sizeof(buf)), nullptr,
|
||||
is.AsyncPreadSome(0, boost::asio::buffer(buf, sizeof(buf)), nullptr,
|
||||
[&stat, &read](const Status &status, const std::string &, size_t transferred) {
|
||||
stat = status;
|
||||
read = transferred;
|
||||
|
@ -202,7 +205,7 @@ TEST(BadDataNodeTest, NNEventCallback) {
|
|||
Status::OK(), 0));
|
||||
|
||||
is.AsyncPreadSome(
|
||||
0, asio::buffer(buf, sizeof(buf)), nullptr,
|
||||
0, boost::asio::buffer(buf, sizeof(buf)), nullptr,
|
||||
[&stat, &read](const Status &status, const std::string &,
|
||||
size_t transferred) {
|
||||
stat = status;
|
||||
|
@ -248,7 +251,7 @@ TEST(BadDataNodeTest, RecoverableError) {
|
|||
|
||||
|
||||
is.AsyncPreadSome(
|
||||
0, asio::buffer(buf, sizeof(buf)), nullptr,
|
||||
0, boost::asio::buffer(buf, sizeof(buf)), nullptr,
|
||||
[&stat, &read](const Status &status, const std::string &,
|
||||
size_t transferred) {
|
||||
stat = status;
|
||||
|
@ -300,7 +303,7 @@ TEST(BadDataNodeTest, InternalError) {
|
|||
sizeof(buf)));
|
||||
|
||||
is.AsyncPreadSome(
|
||||
0, asio::buffer(buf, sizeof(buf)), nullptr,
|
||||
0, boost::asio::buffer(buf, sizeof(buf)), nullptr,
|
||||
[&stat, &read](const Status &status, const std::string &,
|
||||
size_t transferred) {
|
||||
stat = status;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
namespace hdfs {
|
||||
|
||||
MockConnectionBase::MockConnectionBase(::asio::io_service *io_service)
|
||||
MockConnectionBase::MockConnectionBase(boost::asio::io_service *io_service)
|
||||
: io_service_(io_service)
|
||||
{}
|
||||
|
||||
|
@ -31,7 +31,7 @@ ProducerResult SharedMockConnection::Produce() {
|
|||
return shared_prducer->Produce();
|
||||
} else {
|
||||
assert(false && "No producer registered");
|
||||
return std::make_pair(asio::error_code(), "");
|
||||
return std::make_pair(boost::system::error_code(), "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,21 +20,21 @@
|
|||
|
||||
#include "common/async_stream.h"
|
||||
|
||||
#include <asio/error_code.hpp>
|
||||
#include <asio/buffer.hpp>
|
||||
#include <asio/streambuf.hpp>
|
||||
#include <asio/io_service.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
namespace hdfs {
|
||||
|
||||
typedef std::pair<asio::error_code, std::string> ProducerResult;
|
||||
typedef std::pair<boost::system::error_code, std::string> ProducerResult;
|
||||
class AsioProducer {
|
||||
public:
|
||||
/*
|
||||
* Return either:
|
||||
* (::asio::error_code(), <some data>) for a good result
|
||||
* (::boost::system::error_code(), <some data>) for a good result
|
||||
* (<an ::asio::error instance>, <anything>) to pass an error to the caller
|
||||
* (::asio::error::would_block, <anything>) to block the next call forever
|
||||
*/
|
||||
|
@ -45,53 +45,53 @@ public:
|
|||
|
||||
class MockConnectionBase : public AsioProducer, public AsyncStream {
|
||||
public:
|
||||
MockConnectionBase(::asio::io_service *io_service);
|
||||
MockConnectionBase(boost::asio::io_service *io_service);
|
||||
virtual ~MockConnectionBase();
|
||||
typedef std::pair<asio::error_code, std::string> ProducerResult;
|
||||
typedef std::pair<boost::system::error_code, std::string> ProducerResult;
|
||||
|
||||
void async_read_some(const MutableBuffer &buf,
|
||||
std::function<void (const asio::error_code & error,
|
||||
std::function<void (const boost::system::error_code & error,
|
||||
std::size_t bytes_transferred) > handler) override {
|
||||
if (produced_.size() == 0) {
|
||||
ProducerResult r = Produce();
|
||||
if (r.first == asio::error::would_block) {
|
||||
if (r.first == boost::asio::error::would_block) {
|
||||
return; // No more reads to do
|
||||
}
|
||||
if (r.first) {
|
||||
io_service_->post(std::bind(handler, r.first, 0));
|
||||
return;
|
||||
}
|
||||
asio::mutable_buffers_1 data = produced_.prepare(r.second.size());
|
||||
asio::buffer_copy(data, asio::buffer(r.second));
|
||||
boost::asio::mutable_buffers_1 data = produced_.prepare(r.second.size());
|
||||
boost::asio::buffer_copy(data, boost::asio::buffer(r.second));
|
||||
produced_.commit(r.second.size());
|
||||
}
|
||||
|
||||
size_t len = std::min(asio::buffer_size(buf), produced_.size());
|
||||
asio::buffer_copy(buf, produced_.data());
|
||||
size_t len = std::min(boost::asio::buffer_size(buf), produced_.size());
|
||||
boost::asio::buffer_copy(buf, produced_.data());
|
||||
produced_.consume(len);
|
||||
io_service_->post(std::bind(handler, asio::error_code(), len));
|
||||
io_service_->post(std::bind(handler, boost::system::error_code(), len));
|
||||
}
|
||||
|
||||
void async_write_some(const ConstBuffer &buf,
|
||||
std::function<void (const asio::error_code & error,
|
||||
std::function<void (const boost::system::error_code & error,
|
||||
std::size_t bytes_transferred) > handler) override {
|
||||
// CompletionResult res = OnWrite(buf);
|
||||
io_service_->post(std::bind(handler, asio::error_code(), asio::buffer_size(buf)));
|
||||
io_service_->post(std::bind(handler, boost::system::error_code(), boost::asio::buffer_size(buf)));
|
||||
}
|
||||
|
||||
template <class Endpoint, class Callback>
|
||||
void async_connect(const Endpoint &, Callback &&handler) {
|
||||
io_service_->post([handler]() { handler(::asio::error_code()); });
|
||||
io_service_->post([handler]() { handler(::boost::system::error_code()); });
|
||||
}
|
||||
|
||||
virtual void cancel() {}
|
||||
virtual void close() {}
|
||||
protected:
|
||||
ProducerResult Produce() override = 0;
|
||||
::asio::io_service *io_service_;
|
||||
boost::asio::io_service *io_service_;
|
||||
|
||||
private:
|
||||
asio::streambuf produced_;
|
||||
boost::asio::streambuf produced_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -114,10 +114,10 @@ public:
|
|||
assert(data);
|
||||
|
||||
if (!data->checkProducerForConnect) {
|
||||
io_service_->post([handler]() { handler(::asio::error_code()); });
|
||||
io_service_->post([handler]() { handler(::boost::system::error_code()); });
|
||||
} else {
|
||||
ProducerResult result = Produce();
|
||||
if (result.first == asio::error::would_block) {
|
||||
if (result.first == boost::asio::error::would_block) {
|
||||
return; // Connect will hang
|
||||
} else {
|
||||
io_service_->post([handler, result]() { handler( result.first); });
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -44,9 +47,9 @@ using ::hadoop::hdfs::ReadOpChecksumInfoProto;
|
|||
using ::hadoop::hdfs::LocatedBlockProto;
|
||||
using ::hadoop::hdfs::LocatedBlocksProto;
|
||||
|
||||
using ::asio::buffer;
|
||||
using ::asio::error_code;
|
||||
using ::asio::mutable_buffers_1;
|
||||
using boost::asio::buffer;
|
||||
using boost::system::error_code;
|
||||
using boost::asio::mutable_buffers_1;
|
||||
using ::testing::_;
|
||||
using ::testing::InvokeArgument;
|
||||
using ::testing::Return;
|
||||
|
@ -60,7 +63,7 @@ namespace hdfs {
|
|||
|
||||
class MockDNConnection : public MockConnectionBase, public DataNodeConnection{
|
||||
public:
|
||||
MockDNConnection(::asio::io_service &io_service)
|
||||
MockDNConnection(boost::asio::io_service &io_service)
|
||||
: MockConnectionBase(&io_service), OnRead([](){}) {}
|
||||
MOCK_METHOD0(Produce, ProducerResult());
|
||||
|
||||
|
@ -70,14 +73,14 @@ public:
|
|||
std::function<void(void)> OnRead;
|
||||
|
||||
void async_read_some(const MutableBuffer &buf,
|
||||
std::function<void (const asio::error_code & error,
|
||||
std::function<void (const boost::system::error_code & error,
|
||||
std::size_t bytes_transferred) > handler) override {
|
||||
this->OnRead();
|
||||
this->MockConnectionBase::async_read_some(buf, handler);
|
||||
}
|
||||
|
||||
void async_write_some(const ConstBuffer &buf,
|
||||
std::function<void (const asio::error_code & error,
|
||||
std::function<void (const boost::system::error_code & error,
|
||||
std::size_t bytes_transferred) > handler) override {
|
||||
this->MockConnectionBase::async_write_some(buf, handler);
|
||||
}
|
||||
|
@ -96,7 +99,7 @@ public:
|
|||
|
||||
MOCK_METHOD2(
|
||||
AsyncReadPacket,
|
||||
void(const asio::mutable_buffers_1 &,
|
||||
void(const boost::asio::mutable_buffers_1 &,
|
||||
const std::function<void(const Status &, size_t transferred)> &));
|
||||
|
||||
MOCK_METHOD5(AsyncRequestBlock,
|
||||
|
@ -163,7 +166,7 @@ TEST(RemoteBlockReaderTest, TestReadSingleTrunk) {
|
|||
.WillOnce(InvokeArgument<1>(Status::OK(), sizeof(buf)));
|
||||
|
||||
reader.AsyncReadBlock(
|
||||
GetRandomClientName(), block, 0, asio::buffer(buf, sizeof(buf)),
|
||||
GetRandomClientName(), block, 0, boost::asio::buffer(buf, sizeof(buf)),
|
||||
[&stat, &read](const Status &status, size_t transferred) {
|
||||
stat = status;
|
||||
read = transferred;
|
||||
|
@ -190,7 +193,7 @@ TEST(RemoteBlockReaderTest, TestReadMultipleTrunk) {
|
|||
.WillRepeatedly(InvokeArgument<1>(Status::OK(), sizeof(buf) / 4));
|
||||
|
||||
reader.AsyncReadBlock(
|
||||
GetRandomClientName(), block, 0, asio::buffer(buf, sizeof(buf)),
|
||||
GetRandomClientName(), block, 0, boost::asio::buffer(buf, sizeof(buf)),
|
||||
[&stat, &read](const Status &status, size_t transferred) {
|
||||
stat = status;
|
||||
read = transferred;
|
||||
|
@ -218,7 +221,7 @@ TEST(RemoteBlockReaderTest, TestReadError) {
|
|||
.WillOnce(InvokeArgument<1>(Status::Error("error"), 0));
|
||||
|
||||
reader.AsyncReadBlock(
|
||||
GetRandomClientName(), block, 0, asio::buffer(buf, sizeof(buf)),
|
||||
GetRandomClientName(), block, 0, boost::asio::buffer(buf, sizeof(buf)),
|
||||
[&stat, &read](const Status &status, size_t transferred) {
|
||||
stat = status;
|
||||
read = transferred;
|
||||
|
@ -250,7 +253,7 @@ ReadContent(std::shared_ptr<Stream> conn, const ExtendedBlockProto &block,
|
|||
TEST(RemoteBlockReaderTest, TestReadWholeBlock) {
|
||||
static const size_t kChunkSize = 512;
|
||||
static const string kChunkData(kChunkSize, 'a');
|
||||
::asio::io_service io_service;
|
||||
boost::asio::io_service io_service;
|
||||
auto conn = std::make_shared<MockDNConnection>(io_service);
|
||||
BlockOpResponseProto block_op_resp;
|
||||
|
||||
|
@ -287,7 +290,7 @@ TEST(RemoteBlockReaderTest, TestCancelWhileReceiving) {
|
|||
|
||||
static const size_t kChunkSize = 512;
|
||||
static const string kChunkData(kChunkSize, 'a');
|
||||
::asio::io_service io_service;
|
||||
boost::asio::io_service io_service;
|
||||
auto conn = std::make_shared<MockDNConnection>(io_service);
|
||||
BlockOpResponseProto block_op_resp;
|
||||
|
||||
|
@ -338,7 +341,7 @@ TEST(RemoteBlockReaderTest, TestReadWithinChunk) {
|
|||
static const size_t kOffset = kChunkSize / 4;
|
||||
static const string kChunkData = string(kOffset, 'a') + string(kLength, 'b');
|
||||
|
||||
::asio::io_service io_service;
|
||||
boost::asio::io_service io_service;
|
||||
auto conn = std::make_shared<MockDNConnection>(io_service);
|
||||
BlockOpResponseProto block_op_resp;
|
||||
ReadOpChecksumInfoProto *checksum_info =
|
||||
|
@ -378,7 +381,7 @@ TEST(RemoteBlockReaderTest, TestReadMultiplePacket) {
|
|||
static const size_t kChunkSize = 1024;
|
||||
static const string kChunkData(kChunkSize, 'a');
|
||||
|
||||
::asio::io_service io_service;
|
||||
boost::asio::io_service io_service;
|
||||
auto conn = std::make_shared<MockDNConnection>(io_service);
|
||||
BlockOpResponseProto block_op_resp;
|
||||
block_op_resp.set_status(::hadoop::hdfs::Status::SUCCESS);
|
||||
|
@ -428,7 +431,7 @@ TEST(RemoteBlockReaderTest, TestReadCancelBetweenPackets) {
|
|||
static const size_t kChunkSize = 1024;
|
||||
static const string kChunkData(kChunkSize, 'a');
|
||||
|
||||
::asio::io_service io_service;
|
||||
boost::asio::io_service io_service;
|
||||
auto conn = std::make_shared<MockDNConnection>(io_service);
|
||||
BlockOpResponseProto block_op_resp;
|
||||
block_op_resp.set_status(::hadoop::hdfs::Status::SUCCESS);
|
||||
|
@ -482,7 +485,7 @@ TEST(RemoteBlockReaderTest, TestSaslConnection) {
|
|||
static const string kAuthPayload = "realm=\"0\",nonce=\"+GAWc+O6yEAWpew/"
|
||||
"qKah8qh4QZLoOLCDcTtEKhlS\",qop=\"auth\","
|
||||
"charset=utf-8,algorithm=md5-sess";
|
||||
::asio::io_service io_service;
|
||||
boost::asio::io_service io_service;
|
||||
auto conn = std::make_shared<MockDNConnection>(io_service);
|
||||
BlockOpResponseProto block_op_resp;
|
||||
block_op_resp.set_status(::hadoop::hdfs::Status::SUCCESS);
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||
|
||||
using ::hadoop::common::RpcResponseHeaderProto;
|
||||
using ::hadoop::common::EmptyRequestProto;
|
||||
|
@ -33,8 +35,6 @@ using ::hadoop::common::EmptyResponseProto;
|
|||
using ::hadoop::common::EchoRequestProto;
|
||||
using ::hadoop::common::EchoResponseProto;
|
||||
|
||||
using ::asio::error_code;
|
||||
|
||||
using ::testing::Return;
|
||||
|
||||
using ::std::make_pair;
|
||||
|
@ -47,20 +47,20 @@ namespace hdfs {
|
|||
|
||||
std::vector<ResolvedNamenodeInfo> make_endpoint() {
|
||||
ResolvedNamenodeInfo result;
|
||||
result.endpoints.push_back(asio::ip::basic_endpoint<asio::ip::tcp>());
|
||||
result.endpoints.push_back(boost::asio::ip::basic_endpoint<boost::asio::ip::tcp>());
|
||||
return std::vector<ResolvedNamenodeInfo>({result});
|
||||
}
|
||||
|
||||
class MockRPCConnection : public MockConnectionBase {
|
||||
public:
|
||||
MockRPCConnection(::asio::io_service &io_service)
|
||||
MockRPCConnection(boost::asio::io_service &io_service)
|
||||
: MockConnectionBase(&io_service) {}
|
||||
MOCK_METHOD0(Produce, ProducerResult());
|
||||
};
|
||||
|
||||
class SharedMockRPCConnection : public SharedMockConnection {
|
||||
public:
|
||||
SharedMockRPCConnection(::asio::io_service &io_service)
|
||||
SharedMockRPCConnection(boost::asio::io_service &io_service)
|
||||
: SharedMockConnection(&io_service) {}
|
||||
};
|
||||
|
||||
|
@ -79,9 +79,9 @@ protected:
|
|||
|
||||
}
|
||||
|
||||
static inline std::pair<error_code, string> RpcResponse(
|
||||
static inline std::pair<boost::system::error_code, string> RpcResponse(
|
||||
const RpcResponseHeaderProto &h, const std::string &data,
|
||||
const ::asio::error_code &ec = error_code()) {
|
||||
const boost::system::error_code &ec = boost::system::error_code()) {
|
||||
uint32_t payload_length =
|
||||
pbio::CodedOutputStream::VarintSize32(h.ByteSize()) +
|
||||
pbio::CodedOutputStream::VarintSize32(data.size()) + h.ByteSize() +
|
||||
|
@ -157,7 +157,7 @@ TEST(RpcEngineTest, TestConnectionResetAndFail) {
|
|||
h.set_status(RpcResponseHeaderProto::SUCCESS);
|
||||
EXPECT_CALL(conn->TEST_get_mutable_socket(), Produce())
|
||||
.WillOnce(Return(RpcResponse(
|
||||
h, "", make_error_code(::asio::error::connection_reset))));
|
||||
h, "", make_error_code(boost::asio::error::connection_reset))));
|
||||
|
||||
std::shared_ptr<RpcConnection> conn_ptr(conn);
|
||||
engine->TEST_SetRpcConnection(conn_ptr);
|
||||
|
@ -200,7 +200,7 @@ TEST(RpcEngineTest, TestConnectionResetAndRecover) {
|
|||
h.set_status(RpcResponseHeaderProto::SUCCESS);
|
||||
EXPECT_CALL(*producer, Produce())
|
||||
.WillOnce(Return(RpcResponse(
|
||||
h, "", make_error_code(::asio::error::connection_reset))))
|
||||
h, "", make_error_code(boost::asio::error::connection_reset))))
|
||||
.WillOnce(Return(RpcResponse(h, server_resp.SerializeAsString())));
|
||||
SharedMockConnection::SetSharedConnectionData(producer);
|
||||
|
||||
|
@ -240,7 +240,7 @@ TEST(RpcEngineTest, TestConnectionResetAndRecoverWithDelay) {
|
|||
h.set_status(RpcResponseHeaderProto::SUCCESS);
|
||||
EXPECT_CALL(*producer, Produce())
|
||||
.WillOnce(Return(RpcResponse(
|
||||
h, "", make_error_code(::asio::error::connection_reset))))
|
||||
h, "", make_error_code(boost::asio::error::connection_reset))))
|
||||
.WillOnce(Return(RpcResponse(h, server_resp.SerializeAsString())));
|
||||
SharedMockConnection::SetSharedConnectionData(producer);
|
||||
|
||||
|
@ -254,9 +254,9 @@ TEST(RpcEngineTest, TestConnectionResetAndRecoverWithDelay) {
|
|||
ASSERT_TRUE(stat.ok());
|
||||
});
|
||||
|
||||
::asio::deadline_timer timer(io_service->GetRaw());
|
||||
timer.expires_from_now(std::chrono::hours(100));
|
||||
timer.async_wait([](const asio::error_code & err){(void)err; ASSERT_FALSE("Timed out"); });
|
||||
boost::asio::deadline_timer timer(io_service->GetRaw());
|
||||
timer.expires_from_now(boost::posix_time::hours(100));
|
||||
timer.async_wait([](const boost::system::error_code & err){(void)err; ASSERT_FALSE("Timed out"); });
|
||||
|
||||
io_service->Run();
|
||||
ASSERT_TRUE(complete);
|
||||
|
@ -279,7 +279,7 @@ TEST(RpcEngineTest, TestConnectionFailure)
|
|||
std::shared_ptr<SharedConnectionEngine> engine
|
||||
= std::make_shared<SharedConnectionEngine>(io_service, options, "foo", "", "protocol", 1);
|
||||
EXPECT_CALL(*producer, Produce())
|
||||
.WillOnce(Return(std::make_pair(make_error_code(::asio::error::connection_reset), "")));
|
||||
.WillOnce(Return(std::make_pair(make_error_code(boost::asio::error::connection_reset), "")));
|
||||
|
||||
engine->Connect("", make_endpoint(), [&complete, io_service](const Status &stat) {
|
||||
complete = true;
|
||||
|
@ -306,9 +306,9 @@ TEST(RpcEngineTest, TestConnectionFailureRetryAndFailure)
|
|||
std::shared_ptr<SharedConnectionEngine> engine =
|
||||
std::make_shared<SharedConnectionEngine>(io_service, options, "foo", "", "protocol", 1);
|
||||
EXPECT_CALL(*producer, Produce())
|
||||
.WillOnce(Return(std::make_pair(make_error_code(::asio::error::connection_reset), "")))
|
||||
.WillOnce(Return(std::make_pair(make_error_code(::asio::error::connection_reset), "")))
|
||||
.WillOnce(Return(std::make_pair(make_error_code(::asio::error::connection_reset), "")));
|
||||
.WillOnce(Return(std::make_pair(make_error_code(boost::asio::error::connection_reset), "")))
|
||||
.WillOnce(Return(std::make_pair(make_error_code(boost::asio::error::connection_reset), "")))
|
||||
.WillOnce(Return(std::make_pair(make_error_code(boost::asio::error::connection_reset), "")));
|
||||
|
||||
engine->Connect("", make_endpoint(), [&complete, io_service](const Status &stat) {
|
||||
complete = true;
|
||||
|
@ -335,9 +335,9 @@ TEST(RpcEngineTest, TestConnectionFailureAndRecover)
|
|||
std::shared_ptr<SharedConnectionEngine> engine =
|
||||
std::make_shared<SharedConnectionEngine>(io_service, options, "foo", "", "protocol", 1);
|
||||
EXPECT_CALL(*producer, Produce())
|
||||
.WillOnce(Return(std::make_pair(make_error_code(::asio::error::connection_reset), "")))
|
||||
.WillOnce(Return(std::make_pair(::asio::error_code(), "")))
|
||||
.WillOnce(Return(std::make_pair(::asio::error::would_block, "")));
|
||||
.WillOnce(Return(std::make_pair(make_error_code(boost::asio::error::connection_reset), "")))
|
||||
.WillOnce(Return(std::make_pair(boost::system::error_code(), "")))
|
||||
.WillOnce(Return(std::make_pair(boost::asio::error::would_block, "")));
|
||||
|
||||
engine->Connect("", make_endpoint(), [&complete, io_service](const Status &stat) {
|
||||
complete = true;
|
||||
|
@ -390,8 +390,8 @@ TEST(RpcEngineTest, TestEventCallbacks)
|
|||
h.set_callid(1);
|
||||
h.set_status(RpcResponseHeaderProto::SUCCESS);
|
||||
EXPECT_CALL(*producer, Produce())
|
||||
.WillOnce(Return(std::make_pair(::asio::error_code(), ""))) // subverted by callback
|
||||
.WillOnce(Return(std::make_pair(::asio::error_code(), "")))
|
||||
.WillOnce(Return(std::make_pair(boost::system::error_code(), ""))) // subverted by callback
|
||||
.WillOnce(Return(std::make_pair(boost::system::error_code(), "")))
|
||||
.WillOnce(Return(RpcResponse(h, "b"))) // subverted by callback
|
||||
.WillOnce(Return(RpcResponse(h, server_resp.SerializeAsString())));
|
||||
SharedMockConnection::SetSharedConnectionData(producer);
|
||||
|
@ -444,9 +444,9 @@ TEST(RpcEngineTest, TestConnectionFailureAndAsyncRecover)
|
|||
std::shared_ptr<SharedConnectionEngine> engine =
|
||||
std::make_shared<SharedConnectionEngine>(io_service, options, "foo", "", "protocol", 1);
|
||||
EXPECT_CALL(*producer, Produce())
|
||||
.WillOnce(Return(std::make_pair(make_error_code(::asio::error::connection_reset), "")))
|
||||
.WillOnce(Return(std::make_pair(::asio::error_code(), "")))
|
||||
.WillOnce(Return(std::make_pair(::asio::error::would_block, "")));
|
||||
.WillOnce(Return(std::make_pair(make_error_code(boost::asio::error::connection_reset), "")))
|
||||
.WillOnce(Return(std::make_pair(boost::system::error_code(), "")))
|
||||
.WillOnce(Return(std::make_pair(boost::asio::error::would_block, "")));
|
||||
|
||||
engine->Connect("", make_endpoint(), [&complete, io_service](const Status &stat) {
|
||||
complete = true;
|
||||
|
@ -454,9 +454,9 @@ TEST(RpcEngineTest, TestConnectionFailureAndAsyncRecover)
|
|||
ASSERT_TRUE(stat.ok());
|
||||
});
|
||||
|
||||
::asio::deadline_timer timer(io_service->GetRaw());
|
||||
timer.expires_from_now(std::chrono::hours(100));
|
||||
timer.async_wait([](const asio::error_code & err){(void)err; ASSERT_FALSE("Timed out"); });
|
||||
boost::asio::deadline_timer timer(io_service->GetRaw());
|
||||
timer.expires_from_now(boost::posix_time::hours(100));
|
||||
timer.async_wait([](const boost::system::error_code & err){(void)err; ASSERT_FALSE("Timed out"); });
|
||||
|
||||
io_service->Run();
|
||||
ASSERT_TRUE(complete);
|
||||
|
@ -473,7 +473,7 @@ TEST(RpcEngineTest, TestTimeout) {
|
|||
conn->StartReading();
|
||||
|
||||
EXPECT_CALL(conn->TEST_get_mutable_socket(), Produce())
|
||||
.WillOnce(Return(std::make_pair(::asio::error::would_block, "")));
|
||||
.WillOnce(Return(std::make_pair(boost::asio::error::would_block, "")));
|
||||
|
||||
std::shared_ptr<RpcConnection> conn_ptr(conn);
|
||||
engine->TEST_SetRpcConnection(conn_ptr);
|
||||
|
@ -489,9 +489,9 @@ TEST(RpcEngineTest, TestTimeout) {
|
|||
ASSERT_FALSE(stat.ok());
|
||||
});
|
||||
|
||||
::asio::deadline_timer timer(io_service->GetRaw());
|
||||
timer.expires_from_now(std::chrono::hours(100));
|
||||
timer.async_wait([](const asio::error_code & err){(void)err; ASSERT_FALSE("Timed out"); });
|
||||
boost::asio::deadline_timer timer(io_service->GetRaw());
|
||||
timer.expires_from_now(boost::posix_time::hours(100));
|
||||
timer.async_wait([](const boost::system::error_code & err){(void)err; ASSERT_FALSE("Timed out"); });
|
||||
|
||||
io_service->Run();
|
||||
ASSERT_TRUE(complete);
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
@ -1,122 +0,0 @@
|
|||
//
|
||||
// asio.hpp
|
||||
// ~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_HPP
|
||||
#define ASIO_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/basic_datagram_socket.hpp"
|
||||
#include "asio/basic_deadline_timer.hpp"
|
||||
#include "asio/basic_io_object.hpp"
|
||||
#include "asio/basic_raw_socket.hpp"
|
||||
#include "asio/basic_seq_packet_socket.hpp"
|
||||
#include "asio/basic_serial_port.hpp"
|
||||
#include "asio/basic_signal_set.hpp"
|
||||
#include "asio/basic_socket_acceptor.hpp"
|
||||
#include "asio/basic_socket_iostream.hpp"
|
||||
#include "asio/basic_socket_streambuf.hpp"
|
||||
#include "asio/basic_stream_socket.hpp"
|
||||
#include "asio/basic_streambuf.hpp"
|
||||
#include "asio/basic_waitable_timer.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/buffered_read_stream_fwd.hpp"
|
||||
#include "asio/buffered_read_stream.hpp"
|
||||
#include "asio/buffered_stream_fwd.hpp"
|
||||
#include "asio/buffered_stream.hpp"
|
||||
#include "asio/buffered_write_stream_fwd.hpp"
|
||||
#include "asio/buffered_write_stream.hpp"
|
||||
#include "asio/buffers_iterator.hpp"
|
||||
#include "asio/completion_condition.hpp"
|
||||
#include "asio/connect.hpp"
|
||||
#include "asio/coroutine.hpp"
|
||||
#include "asio/datagram_socket_service.hpp"
|
||||
#include "asio/deadline_timer_service.hpp"
|
||||
#include "asio/deadline_timer.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/error_code.hpp"
|
||||
#include "asio/generic/basic_endpoint.hpp"
|
||||
#include "asio/generic/datagram_protocol.hpp"
|
||||
#include "asio/generic/raw_protocol.hpp"
|
||||
#include "asio/generic/seq_packet_protocol.hpp"
|
||||
#include "asio/generic/stream_protocol.hpp"
|
||||
#include "asio/handler_alloc_hook.hpp"
|
||||
#include "asio/handler_continuation_hook.hpp"
|
||||
#include "asio/handler_invoke_hook.hpp"
|
||||
#include "asio/handler_type.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
#include "asio/ip/address.hpp"
|
||||
#include "asio/ip/address_v4.hpp"
|
||||
#include "asio/ip/address_v6.hpp"
|
||||
#include "asio/ip/basic_endpoint.hpp"
|
||||
#include "asio/ip/basic_resolver.hpp"
|
||||
#include "asio/ip/basic_resolver_entry.hpp"
|
||||
#include "asio/ip/basic_resolver_iterator.hpp"
|
||||
#include "asio/ip/basic_resolver_query.hpp"
|
||||
#include "asio/ip/host_name.hpp"
|
||||
#include "asio/ip/icmp.hpp"
|
||||
#include "asio/ip/multicast.hpp"
|
||||
#include "asio/ip/resolver_query_base.hpp"
|
||||
#include "asio/ip/resolver_service.hpp"
|
||||
#include "asio/ip/tcp.hpp"
|
||||
#include "asio/ip/udp.hpp"
|
||||
#include "asio/ip/unicast.hpp"
|
||||
#include "asio/ip/v6_only.hpp"
|
||||
#include "asio/is_read_buffered.hpp"
|
||||
#include "asio/is_write_buffered.hpp"
|
||||
#include "asio/local/basic_endpoint.hpp"
|
||||
#include "asio/local/connect_pair.hpp"
|
||||
#include "asio/local/datagram_protocol.hpp"
|
||||
#include "asio/local/stream_protocol.hpp"
|
||||
#include "asio/placeholders.hpp"
|
||||
#include "asio/posix/basic_descriptor.hpp"
|
||||
#include "asio/posix/basic_stream_descriptor.hpp"
|
||||
#include "asio/posix/descriptor_base.hpp"
|
||||
#include "asio/posix/stream_descriptor.hpp"
|
||||
#include "asio/posix/stream_descriptor_service.hpp"
|
||||
#include "asio/raw_socket_service.hpp"
|
||||
#include "asio/read.hpp"
|
||||
#include "asio/read_at.hpp"
|
||||
#include "asio/read_until.hpp"
|
||||
#include "asio/seq_packet_socket_service.hpp"
|
||||
#include "asio/serial_port.hpp"
|
||||
#include "asio/serial_port_base.hpp"
|
||||
#include "asio/serial_port_service.hpp"
|
||||
#include "asio/signal_set.hpp"
|
||||
#include "asio/signal_set_service.hpp"
|
||||
#include "asio/socket_acceptor_service.hpp"
|
||||
#include "asio/socket_base.hpp"
|
||||
#include "asio/strand.hpp"
|
||||
#include "asio/stream_socket_service.hpp"
|
||||
#include "asio/streambuf.hpp"
|
||||
#include "asio/system_error.hpp"
|
||||
#include "asio/thread.hpp"
|
||||
#include "asio/time_traits.hpp"
|
||||
#include "asio/version.hpp"
|
||||
#include "asio/wait_traits.hpp"
|
||||
#include "asio/waitable_timer_service.hpp"
|
||||
#include "asio/windows/basic_handle.hpp"
|
||||
#include "asio/windows/basic_object_handle.hpp"
|
||||
#include "asio/windows/basic_random_access_handle.hpp"
|
||||
#include "asio/windows/basic_stream_handle.hpp"
|
||||
#include "asio/windows/object_handle.hpp"
|
||||
#include "asio/windows/object_handle_service.hpp"
|
||||
#include "asio/windows/overlapped_ptr.hpp"
|
||||
#include "asio/windows/random_access_handle.hpp"
|
||||
#include "asio/windows/random_access_handle_service.hpp"
|
||||
#include "asio/windows/stream_handle.hpp"
|
||||
#include "asio/windows/stream_handle_service.hpp"
|
||||
#include "asio/write.hpp"
|
||||
#include "asio/write_at.hpp"
|
||||
|
||||
#endif // ASIO_HPP
|
|
@ -1,94 +0,0 @@
|
|||
//
|
||||
// async_result.hpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_ASYNC_RESULT_HPP
|
||||
#define ASIO_ASYNC_RESULT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/handler_type.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// An interface for customising the behaviour of an initiating function.
|
||||
/**
|
||||
* This template may be specialised for user-defined handler types.
|
||||
*/
|
||||
template <typename Handler>
|
||||
class async_result
|
||||
{
|
||||
public:
|
||||
/// The return type of the initiating function.
|
||||
typedef void type;
|
||||
|
||||
/// Construct an async result from a given handler.
|
||||
/**
|
||||
* When using a specalised async_result, the constructor has an opportunity
|
||||
* to initialise some state associated with the handler, which is then
|
||||
* returned from the initiating function.
|
||||
*/
|
||||
explicit async_result(Handler&)
|
||||
{
|
||||
}
|
||||
|
||||
/// Obtain the value to be returned from the initiating function.
|
||||
type get()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
// Helper template to deduce the true type of a handler, capture a local copy
|
||||
// of the handler, and then create an async_result for the handler.
|
||||
template <typename Handler, typename Signature>
|
||||
struct async_result_init
|
||||
{
|
||||
explicit async_result_init(ASIO_MOVE_ARG(Handler) orig_handler)
|
||||
: handler(ASIO_MOVE_CAST(Handler)(orig_handler)),
|
||||
result(handler)
|
||||
{
|
||||
}
|
||||
|
||||
typename handler_type<Handler, Signature>::type handler;
|
||||
async_result<typename handler_type<Handler, Signature>::type> result;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Signature>
|
||||
struct async_result_type_helper
|
||||
{
|
||||
typedef typename async_result<
|
||||
typename handler_type<Handler, Signature>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
# define ASIO_INITFN_RESULT_TYPE(h, sig) \
|
||||
void_or_deduced
|
||||
#elif defined(_MSC_VER) && (_MSC_VER < 1500)
|
||||
# define ASIO_INITFN_RESULT_TYPE(h, sig) \
|
||||
typename ::asio::detail::async_result_type_helper<h, sig>::type
|
||||
#else
|
||||
# define ASIO_INITFN_RESULT_TYPE(h, sig) \
|
||||
typename ::asio::async_result< \
|
||||
typename ::asio::handler_type<h, sig>::type>::type
|
||||
#endif
|
||||
|
||||
#endif // ASIO_ASYNC_RESULT_HPP
|
|
@ -1,949 +0,0 @@
|
|||
//
|
||||
// basic_datagram_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_DATAGRAM_SOCKET_HPP
|
||||
#define ASIO_BASIC_DATAGRAM_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/datagram_socket_service.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides datagram-oriented socket functionality.
|
||||
/**
|
||||
* The basic_datagram_socket class template provides asynchronous and blocking
|
||||
* datagram-oriented socket functionality.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename Protocol,
|
||||
typename DatagramSocketService = datagram_socket_service<Protocol> >
|
||||
class basic_datagram_socket
|
||||
: public basic_socket<Protocol, DatagramSocketService>
|
||||
{
|
||||
public:
|
||||
/// (Deprecated: Use native_handle_type.) The native representation of a
|
||||
/// socket.
|
||||
typedef typename DatagramSocketService::native_handle_type native_type;
|
||||
|
||||
/// The native representation of a socket.
|
||||
typedef typename DatagramSocketService::native_handle_type native_handle_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// Construct a basic_datagram_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a datagram socket without opening it. The open()
|
||||
* function must be called before data can be sent or received on the socket.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*/
|
||||
explicit basic_datagram_socket(asio::io_service& io_service)
|
||||
: basic_socket<Protocol, DatagramSocketService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_datagram_socket.
|
||||
/**
|
||||
* This constructor creates and opens a datagram socket.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(asio::io_service& io_service,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol, DatagramSocketService>(io_service, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_datagram_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
* This constructor creates a datagram socket and automatically opens it bound
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the datagram
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(asio::io_service& io_service,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, DatagramSocketService>(io_service, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_datagram_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a datagram socket object to hold an existing
|
||||
* native socket.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(asio::io_service& io_service,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol, DatagramSocketService>(
|
||||
io_service, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_datagram_socket from another.
|
||||
/**
|
||||
* This constructor moves a datagram socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_datagram_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_datagram_socket(basic_datagram_socket&& other)
|
||||
: basic_socket<Protocol, DatagramSocketService>(
|
||||
ASIO_MOVE_CAST(basic_datagram_socket)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_datagram_socket from another.
|
||||
/**
|
||||
* This assignment operator moves a datagram socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_datagram_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_datagram_socket& operator=(basic_datagram_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol, DatagramSocketService>::operator=(
|
||||
ASIO_MOVE_CAST(basic_datagram_socket)(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Move-construct a basic_datagram_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This constructor moves a datagram socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_datagram_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename DatagramSocketService1>
|
||||
basic_datagram_socket(
|
||||
basic_datagram_socket<Protocol1, DatagramSocketService1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol, DatagramSocketService>(
|
||||
ASIO_MOVE_CAST2(basic_datagram_socket<
|
||||
Protocol1, DatagramSocketService1>)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_datagram_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This assignment operator moves a datagram socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_datagram_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename DatagramSocketService1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_datagram_socket>::type& operator=(
|
||||
basic_datagram_socket<Protocol1, DatagramSocketService1>&& other)
|
||||
{
|
||||
basic_socket<Protocol, DatagramSocketService>::operator=(
|
||||
ASIO_MOVE_CAST2(basic_datagram_socket<
|
||||
Protocol1, DatagramSocketService1>)(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the datagram socket. The function
|
||||
* call will block until the data has been sent successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One ore more data buffers to be sent on the socket.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected datagram socket.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code socket.send(asio::buffer(data, size)); @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the datagram socket. The function
|
||||
* call will block until the data has been sent successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One ore more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected datagram socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the datagram socket. The function
|
||||
* call will block until the data has been sent successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected datagram socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the datagram socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected datagram
|
||||
* socket.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_send(asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the datagram socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected datagram
|
||||
* socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send a datagram to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* asio::ip::udp::endpoint destination(
|
||||
* asio::ip::address::from_string("1.2.3.4"), 12345);
|
||||
* socket.send_to(asio::buffer(data, size), destination);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, 0, ec);
|
||||
asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send a datagram to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, flags, ec);
|
||||
asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send a datagram to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send_to(this->get_implementation(),
|
||||
buffers, destination, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send a datagram to the specified
|
||||
* remote endpoint. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
* Copies will be made of the endpoint as required.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* asio::ip::udp::endpoint destination(
|
||||
* asio::ip::address::from_string("1.2.3.4"), 12345);
|
||||
* socket.async_send_to(
|
||||
* asio::buffer(data, size), destination, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, 0,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send a datagram to the specified
|
||||
* remote endpoint. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
* Copies will be made of the endpoint as required.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, flags,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the datagram socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected datagram
|
||||
* socket.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code socket.receive(asio::buffer(data, size)); @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the datagram socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected datagram
|
||||
* socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the datagram socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected datagram
|
||||
* socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the datagram
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
* datagram socket.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the datagram
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
* datagram socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive a datagram. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* asio::ip::udp::endpoint sender_endpoint;
|
||||
* socket.receive_from(
|
||||
* asio::buffer(data, size), sender_endpoint);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0, ec);
|
||||
asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive a datagram. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags, ec);
|
||||
asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive a datagram. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive_from(this->get_implementation(),
|
||||
buffers, sender_endpoint, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive a datagram. The function
|
||||
* call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram. Ownership of the sender_endpoint object
|
||||
* is retained by the caller, which must guarantee that it is valid until the
|
||||
* handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code socket.async_receive_from(
|
||||
* asio::buffer(data, size), sender_endpoint, handler); @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive a datagram. The function
|
||||
* call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram. Ownership of the sender_endpoint object
|
||||
* is retained by the caller, which must guarantee that it is valid until the
|
||||
* handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BASIC_DATAGRAM_SOCKET_HPP
|
|
@ -1,520 +0,0 @@
|
|||
//
|
||||
// basic_deadline_timer.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_DEADLINE_TIMER_HPP
|
||||
#define ASIO_BASIC_DEADLINE_TIMER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
|| defined(ASIO_CPP11_DATE_TIME) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include <cstddef>
|
||||
#include "asio/basic_io_object.hpp"
|
||||
#include "asio/deadline_timer_service.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides waitable timer functionality.
|
||||
/**
|
||||
* The basic_deadline_timer class template provides the ability to perform a
|
||||
* blocking or asynchronous wait for a timer to expire.
|
||||
*
|
||||
* A deadline timer is always in one of two states: "expired" or "not expired".
|
||||
* If the wait() or async_wait() function is called on an expired timer, the
|
||||
* wait operation will complete immediately.
|
||||
*
|
||||
* Most applications will use the asio::deadline_timer typedef.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Examples
|
||||
* Performing a blocking wait:
|
||||
* @code
|
||||
* // Construct a timer without setting an expiry time.
|
||||
* asio::deadline_timer timer(io_service);
|
||||
*
|
||||
* // Set an expiry time relative to now.
|
||||
* timer.expires_from_now(boost::posix_time::seconds(5));
|
||||
*
|
||||
* // Wait for the timer to expire.
|
||||
* timer.wait();
|
||||
* @endcode
|
||||
*
|
||||
* @par
|
||||
* Performing an asynchronous wait:
|
||||
* @code
|
||||
* void handler(const asio::error_code& error)
|
||||
* {
|
||||
* if (!error)
|
||||
* {
|
||||
* // Timer expired.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* // Construct a timer with an absolute expiry time.
|
||||
* asio::deadline_timer timer(io_service,
|
||||
* boost::posix_time::time_from_string("2005-12-07 23:59:59.000"));
|
||||
*
|
||||
* // Start an asynchronous wait.
|
||||
* timer.async_wait(handler);
|
||||
* @endcode
|
||||
*
|
||||
* @par Changing an active deadline_timer's expiry time
|
||||
*
|
||||
* Changing the expiry time of a timer while there are pending asynchronous
|
||||
* waits causes those wait operations to be cancelled. To ensure that the action
|
||||
* associated with the timer is performed only once, use something like this:
|
||||
* used:
|
||||
*
|
||||
* @code
|
||||
* void on_some_event()
|
||||
* {
|
||||
* if (my_timer.expires_from_now(seconds(5)) > 0)
|
||||
* {
|
||||
* // We managed to cancel the timer. Start new asynchronous wait.
|
||||
* my_timer.async_wait(on_timeout);
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // Too late, timer has already expired!
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* void on_timeout(const asio::error_code& e)
|
||||
* {
|
||||
* if (e != asio::error::operation_aborted)
|
||||
* {
|
||||
* // Timer was not cancelled, take necessary action.
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @li The asio::basic_deadline_timer::expires_from_now() function
|
||||
* cancels any pending asynchronous waits, and returns the number of
|
||||
* asynchronous waits that were cancelled. If it returns 0 then you were too
|
||||
* late and the wait handler has already been executed, or will soon be
|
||||
* executed. If it returns 1 then the wait handler was successfully cancelled.
|
||||
*
|
||||
* @li If a wait handler is cancelled, the asio::error_code passed to
|
||||
* it contains the value asio::error::operation_aborted.
|
||||
*/
|
||||
template <typename Time,
|
||||
typename TimeTraits = asio::time_traits<Time>,
|
||||
typename TimerService = deadline_timer_service<Time, TimeTraits> >
|
||||
class basic_deadline_timer
|
||||
: public basic_io_object<TimerService>
|
||||
{
|
||||
public:
|
||||
/// The time traits type.
|
||||
typedef TimeTraits traits_type;
|
||||
|
||||
/// The time type.
|
||||
typedef typename traits_type::time_type time_type;
|
||||
|
||||
/// The duration type.
|
||||
typedef typename traits_type::duration_type duration_type;
|
||||
|
||||
/// Constructor.
|
||||
/**
|
||||
* This constructor creates a timer without setting an expiry time. The
|
||||
* expires_at() or expires_from_now() functions must be called to set an
|
||||
* expiry time before the timer can be waited on.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*/
|
||||
explicit basic_deadline_timer(asio::io_service& io_service)
|
||||
: basic_io_object<TimerService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time as an absolute time.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, expressed
|
||||
* as an absolute time.
|
||||
*/
|
||||
basic_deadline_timer(asio::io_service& io_service,
|
||||
const time_type& expiry_time)
|
||||
: basic_io_object<TimerService>(io_service)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.expires_at(this->implementation, expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time relative to now.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, relative to
|
||||
* now.
|
||||
*/
|
||||
basic_deadline_timer(asio::io_service& io_service,
|
||||
const duration_type& expiry_time)
|
||||
: basic_io_object<TimerService>(io_service)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.expires_from_now(this->implementation, expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_from_now");
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->service.cancel(this->implementation, ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel(asio::error_code& ec)
|
||||
{
|
||||
return this->service.cancel(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->service.cancel_one(this->implementation, ec);
|
||||
asio::detail::throw_error(ec, "cancel_one");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one(asio::error_code& ec)
|
||||
{
|
||||
return this->service.cancel_one(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
time_type expires_at() const
|
||||
{
|
||||
return this->service.expires_at(this->implementation);
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_type& expiry_time)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->service.expires_at(
|
||||
this->implementation, expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_type& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->service.expires_at(this->implementation, expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
duration_type expires_from_now() const
|
||||
{
|
||||
return this->service.expires_from_now(this->implementation);
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration_type& expiry_time)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->service.expires_from_now(
|
||||
this->implementation, expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_from_now");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration_type& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->service.expires_from_now(
|
||||
this->implementation, expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void wait()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.wait(this->implementation, ec);
|
||||
asio::detail::throw_error(ec, "wait");
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
void wait(asio::error_code& ec)
|
||||
{
|
||||
this->service.wait(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous wait on the timer.
|
||||
/**
|
||||
* This function may be used to initiate an asynchronous wait against the
|
||||
* timer. It always returns immediately.
|
||||
*
|
||||
* For each call to async_wait(), the supplied handler will be called exactly
|
||||
* once. The handler will be called when:
|
||||
*
|
||||
* @li The timer has expired.
|
||||
*
|
||||
* @li The timer was cancelled, in which case the handler is passed the error
|
||||
* code asio::error::operation_aborted.
|
||||
*
|
||||
* @param handler The handler to be called when the timer expires. Copies
|
||||
* will be made of the handler as required. The function signature of the
|
||||
* handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error // Result of operation.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*/
|
||||
template <typename WaitHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WaitHandler,
|
||||
void (asio::error_code))
|
||||
async_wait(ASIO_MOVE_ARG(WaitHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WaitHandler.
|
||||
ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
|
||||
|
||||
return this->service.async_wait(this->implementation,
|
||||
ASIO_MOVE_CAST(WaitHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// || defined(ASIO_CPP11_DATE_TIME)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // ASIO_BASIC_DEADLINE_TIMER_HPP
|
|
@ -1,240 +0,0 @@
|
|||
//
|
||||
// basic_io_object.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_IO_OBJECT_HPP
|
||||
#define ASIO_BASIC_IO_OBJECT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
namespace detail
|
||||
{
|
||||
// Type trait used to determine whether a service supports move.
|
||||
template <typename IoObjectService>
|
||||
class service_has_move
|
||||
{
|
||||
private:
|
||||
typedef IoObjectService service_type;
|
||||
typedef typename service_type::implementation_type implementation_type;
|
||||
|
||||
template <typename T, typename U>
|
||||
static auto eval(T* t, U* u) -> decltype(t->move_construct(*u, *u), char());
|
||||
static char (&eval(...))[2];
|
||||
|
||||
public:
|
||||
static const bool value =
|
||||
sizeof(service_has_move::eval(
|
||||
static_cast<service_type*>(0),
|
||||
static_cast<implementation_type*>(0))) == 1;
|
||||
};
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
/// Base class for all I/O objects.
|
||||
/**
|
||||
* @note All I/O objects are non-copyable. However, when using C++0x, certain
|
||||
* I/O objects do support move construction and move assignment.
|
||||
*/
|
||||
#if !defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
template <typename IoObjectService>
|
||||
#else
|
||||
template <typename IoObjectService,
|
||||
bool Movable = detail::service_has_move<IoObjectService>::value>
|
||||
#endif
|
||||
class basic_io_object
|
||||
{
|
||||
public:
|
||||
/// The type of the service that will be used to provide I/O operations.
|
||||
typedef IoObjectService service_type;
|
||||
|
||||
/// The underlying implementation type of I/O object.
|
||||
typedef typename service_type::implementation_type implementation_type;
|
||||
|
||||
/// Get the io_service associated with the object.
|
||||
/**
|
||||
* This function may be used to obtain the io_service object that the I/O
|
||||
* object uses to dispatch handlers for asynchronous operations.
|
||||
*
|
||||
* @return A reference to the io_service object that the I/O object will use
|
||||
* to dispatch handlers. Ownership is not transferred to the caller.
|
||||
*/
|
||||
asio::io_service& get_io_service()
|
||||
{
|
||||
return service.get_io_service();
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Construct a basic_io_object.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().construct(get_implementation()); @endcode
|
||||
*/
|
||||
explicit basic_io_object(asio::io_service& io_service)
|
||||
: service(asio::use_service<IoObjectService>(io_service))
|
||||
{
|
||||
service.construct(implementation);
|
||||
}
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_io_object.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().move_construct(
|
||||
* get_implementation(), other.get_implementation()); @endcode
|
||||
*
|
||||
* @note Available only for services that support movability,
|
||||
*/
|
||||
basic_io_object(basic_io_object&& other);
|
||||
|
||||
/// Move-assign a basic_io_object.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().move_assign(get_implementation(),
|
||||
* other.get_service(), other.get_implementation()); @endcode
|
||||
*
|
||||
* @note Available only for services that support movability,
|
||||
*/
|
||||
basic_io_object& operator=(basic_io_object&& other);
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Protected destructor to prevent deletion through this type.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().destroy(get_implementation()); @endcode
|
||||
*/
|
||||
~basic_io_object()
|
||||
{
|
||||
service.destroy(implementation);
|
||||
}
|
||||
|
||||
/// Get the service associated with the I/O object.
|
||||
service_type& get_service()
|
||||
{
|
||||
return service;
|
||||
}
|
||||
|
||||
/// Get the service associated with the I/O object.
|
||||
const service_type& get_service() const
|
||||
{
|
||||
return service;
|
||||
}
|
||||
|
||||
/// (Deprecated: Use get_service().) The service associated with the I/O
|
||||
/// object.
|
||||
/**
|
||||
* @note Available only for services that do not support movability.
|
||||
*/
|
||||
service_type& service;
|
||||
|
||||
/// Get the underlying implementation of the I/O object.
|
||||
implementation_type& get_implementation()
|
||||
{
|
||||
return implementation;
|
||||
}
|
||||
|
||||
/// Get the underlying implementation of the I/O object.
|
||||
const implementation_type& get_implementation() const
|
||||
{
|
||||
return implementation;
|
||||
}
|
||||
|
||||
/// (Deprecated: Use get_implementation().) The underlying implementation of
|
||||
/// the I/O object.
|
||||
implementation_type implementation;
|
||||
|
||||
private:
|
||||
basic_io_object(const basic_io_object&);
|
||||
basic_io_object& operator=(const basic_io_object&);
|
||||
};
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
// Specialisation for movable objects.
|
||||
template <typename IoObjectService>
|
||||
class basic_io_object<IoObjectService, true>
|
||||
{
|
||||
public:
|
||||
typedef IoObjectService service_type;
|
||||
typedef typename service_type::implementation_type implementation_type;
|
||||
|
||||
asio::io_service& get_io_service()
|
||||
{
|
||||
return service_->get_io_service();
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit basic_io_object(asio::io_service& io_service)
|
||||
: service_(&asio::use_service<IoObjectService>(io_service))
|
||||
{
|
||||
service_->construct(implementation);
|
||||
}
|
||||
|
||||
basic_io_object(basic_io_object&& other)
|
||||
: service_(&other.get_service())
|
||||
{
|
||||
service_->move_construct(implementation, other.implementation);
|
||||
}
|
||||
|
||||
~basic_io_object()
|
||||
{
|
||||
service_->destroy(implementation);
|
||||
}
|
||||
|
||||
basic_io_object& operator=(basic_io_object&& other)
|
||||
{
|
||||
service_->move_assign(implementation,
|
||||
*other.service_, other.implementation);
|
||||
service_ = other.service_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
service_type& get_service()
|
||||
{
|
||||
return *service_;
|
||||
}
|
||||
|
||||
const service_type& get_service() const
|
||||
{
|
||||
return *service_;
|
||||
}
|
||||
|
||||
implementation_type& get_implementation()
|
||||
{
|
||||
return implementation;
|
||||
}
|
||||
|
||||
const implementation_type& get_implementation() const
|
||||
{
|
||||
return implementation;
|
||||
}
|
||||
|
||||
implementation_type implementation;
|
||||
|
||||
private:
|
||||
basic_io_object(const basic_io_object&);
|
||||
void operator=(const basic_io_object&);
|
||||
|
||||
IoObjectService* service_;
|
||||
};
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BASIC_IO_OBJECT_HPP
|
|
@ -1,940 +0,0 @@
|
|||
//
|
||||
// basic_raw_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_RAW_SOCKET_HPP
|
||||
#define ASIO_BASIC_RAW_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/raw_socket_service.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides raw-oriented socket functionality.
|
||||
/**
|
||||
* The basic_raw_socket class template provides asynchronous and blocking
|
||||
* raw-oriented socket functionality.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename Protocol,
|
||||
typename RawSocketService = raw_socket_service<Protocol> >
|
||||
class basic_raw_socket
|
||||
: public basic_socket<Protocol, RawSocketService>
|
||||
{
|
||||
public:
|
||||
/// (Deprecated: Use native_handle_type.) The native representation of a
|
||||
/// socket.
|
||||
typedef typename RawSocketService::native_handle_type native_type;
|
||||
|
||||
/// The native representation of a socket.
|
||||
typedef typename RawSocketService::native_handle_type native_handle_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// Construct a basic_raw_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a raw socket without opening it. The open()
|
||||
* function must be called before data can be sent or received on the socket.
|
||||
*
|
||||
* @param io_service The io_service object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*/
|
||||
explicit basic_raw_socket(asio::io_service& io_service)
|
||||
: basic_socket<Protocol, RawSocketService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_raw_socket.
|
||||
/**
|
||||
* This constructor creates and opens a raw socket.
|
||||
*
|
||||
* @param io_service The io_service object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_raw_socket(asio::io_service& io_service,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol, RawSocketService>(io_service, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_raw_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
* This constructor creates a raw socket and automatically opens it bound
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_service The io_service object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the raw
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_raw_socket(asio::io_service& io_service,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, RawSocketService>(io_service, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_raw_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a raw socket object to hold an existing
|
||||
* native socket.
|
||||
*
|
||||
* @param io_service The io_service object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_raw_socket(asio::io_service& io_service,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol, RawSocketService>(
|
||||
io_service, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_raw_socket from another.
|
||||
/**
|
||||
* This constructor moves a raw socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_raw_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_raw_socket(basic_raw_socket&& other)
|
||||
: basic_socket<Protocol, RawSocketService>(
|
||||
ASIO_MOVE_CAST(basic_raw_socket)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_raw_socket from another.
|
||||
/**
|
||||
* This assignment operator moves a raw socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_raw_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_raw_socket& operator=(basic_raw_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol, RawSocketService>::operator=(
|
||||
ASIO_MOVE_CAST(basic_raw_socket)(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Move-construct a basic_raw_socket from a socket of another protocol type.
|
||||
/**
|
||||
* This constructor moves a raw socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_raw_socket object from which the move will
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename RawSocketService1>
|
||||
basic_raw_socket(basic_raw_socket<Protocol1, RawSocketService1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol, RawSocketService>(
|
||||
ASIO_MOVE_CAST2(basic_raw_socket<
|
||||
Protocol1, RawSocketService1>)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_raw_socket from a socket of another protocol type.
|
||||
/**
|
||||
* This assignment operator moves a raw socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_raw_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename RawSocketService1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_raw_socket>::type& operator=(
|
||||
basic_raw_socket<Protocol1, RawSocketService1>&& other)
|
||||
{
|
||||
basic_socket<Protocol, RawSocketService>::operator=(
|
||||
ASIO_MOVE_CAST2(basic_raw_socket<
|
||||
Protocol1, RawSocketService1>)(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the raw socket. The function call
|
||||
* will block until the data has been sent successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One ore more data buffers to be sent on the socket.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected raw socket.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code socket.send(asio::buffer(data, size)); @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the raw socket. The function call
|
||||
* will block until the data has been sent successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One ore more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected raw socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the raw socket. The function call
|
||||
* will block until the data has been sent successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected raw socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the raw socket. The function call
|
||||
* will block until the data has been sent successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected raw
|
||||
* socket.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_send(asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the raw socket. The function call
|
||||
* will block until the data has been sent successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected raw
|
||||
* socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Send raw data to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send raw data to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* asio::ip::udp::endpoint destination(
|
||||
* asio::ip::address::from_string("1.2.3.4"), 12345);
|
||||
* socket.send_to(asio::buffer(data, size), destination);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, 0, ec);
|
||||
asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send raw data to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send raw data to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, flags, ec);
|
||||
asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send raw data to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send raw data to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send_to(this->get_implementation(),
|
||||
buffers, destination, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send raw data to the specified
|
||||
* remote endpoint. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
* Copies will be made of the endpoint as required.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* asio::ip::udp::endpoint destination(
|
||||
* asio::ip::address::from_string("1.2.3.4"), 12345);
|
||||
* socket.async_send_to(
|
||||
* asio::buffer(data, size), destination, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send_to(this->get_implementation(),
|
||||
buffers, destination, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send raw data to the specified
|
||||
* remote endpoint. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
* Copies will be made of the endpoint as required.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, flags,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the raw socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected raw
|
||||
* socket.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code socket.receive(asio::buffer(data, size)); @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the raw socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected raw
|
||||
* socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the raw socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected raw
|
||||
* socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the raw
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
* raw socket.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the raw
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
* raw socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive raw data with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive raw data. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the data.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* asio::ip::udp::endpoint sender_endpoint;
|
||||
* socket.receive_from(
|
||||
* asio::buffer(data, size), sender_endpoint);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0, ec);
|
||||
asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive raw data with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive raw data. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the data.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags, ec);
|
||||
asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive raw data with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive raw data. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the data.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive_from(this->get_implementation(),
|
||||
buffers, sender_endpoint, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive raw data. The function
|
||||
* call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the data. Ownership of the sender_endpoint object
|
||||
* is retained by the caller, which must guarantee that it is valid until the
|
||||
* handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code socket.async_receive_from(
|
||||
* asio::buffer(data, size), 0, sender_endpoint, handler); @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive raw data. The function
|
||||
* call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the data. Ownership of the sender_endpoint object
|
||||
* is retained by the caller, which must guarantee that it is valid until the
|
||||
* handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BASIC_RAW_SOCKET_HPP
|
|
@ -1,565 +0,0 @@
|
|||
//
|
||||
// basic_seq_packet_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_SEQ_PACKET_SOCKET_HPP
|
||||
#define ASIO_BASIC_SEQ_PACKET_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/seq_packet_socket_service.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides sequenced packet socket functionality.
|
||||
/**
|
||||
* The basic_seq_packet_socket class template provides asynchronous and blocking
|
||||
* sequenced packet socket functionality.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename Protocol,
|
||||
typename SeqPacketSocketService = seq_packet_socket_service<Protocol> >
|
||||
class basic_seq_packet_socket
|
||||
: public basic_socket<Protocol, SeqPacketSocketService>
|
||||
{
|
||||
public:
|
||||
/// (Deprecated: Use native_handle_type.) The native representation of a
|
||||
/// socket.
|
||||
typedef typename SeqPacketSocketService::native_handle_type native_type;
|
||||
|
||||
/// The native representation of a socket.
|
||||
typedef typename SeqPacketSocketService::native_handle_type
|
||||
native_handle_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// Construct a basic_seq_packet_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a sequenced packet socket without opening it. The
|
||||
* socket needs to be opened and then connected or accepted before data can
|
||||
* be sent or received on it.
|
||||
*
|
||||
* @param io_service The io_service object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
*/
|
||||
explicit basic_seq_packet_socket(asio::io_service& io_service)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_seq_packet_socket.
|
||||
/**
|
||||
* This constructor creates and opens a sequenced_packet socket. The socket
|
||||
* needs to be connected or accepted before data can be sent or received on
|
||||
* it.
|
||||
*
|
||||
* @param io_service The io_service object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_seq_packet_socket(asio::io_service& io_service,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(io_service, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_seq_packet_socket, opening it and binding it to the
|
||||
/// given local endpoint.
|
||||
/**
|
||||
* This constructor creates a sequenced packet socket and automatically opens
|
||||
* it bound to the specified endpoint on the local machine. The protocol used
|
||||
* is the protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_service The io_service object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the sequenced
|
||||
* packet socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_seq_packet_socket(asio::io_service& io_service,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(io_service, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_seq_packet_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a sequenced packet socket object to hold an
|
||||
* existing native socket.
|
||||
*
|
||||
* @param io_service The io_service object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_seq_packet_socket(asio::io_service& io_service,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(
|
||||
io_service, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_seq_packet_socket from another.
|
||||
/**
|
||||
* This constructor moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_seq_packet_socket(basic_seq_packet_socket&& other)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(
|
||||
ASIO_MOVE_CAST(basic_seq_packet_socket)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_seq_packet_socket from another.
|
||||
/**
|
||||
* This assignment operator moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_seq_packet_socket& operator=(basic_seq_packet_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol, SeqPacketSocketService>::operator=(
|
||||
ASIO_MOVE_CAST(basic_seq_packet_socket)(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Move-construct a basic_seq_packet_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This constructor moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename SeqPacketSocketService1>
|
||||
basic_seq_packet_socket(
|
||||
basic_seq_packet_socket<Protocol1, SeqPacketSocketService1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(
|
||||
ASIO_MOVE_CAST2(basic_seq_packet_socket<
|
||||
Protocol1, SeqPacketSocketService1>)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_seq_packet_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This assignment operator moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename SeqPacketSocketService1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_seq_packet_socket>::type& operator=(
|
||||
basic_seq_packet_socket<Protocol1, SeqPacketSocketService1>&& other)
|
||||
{
|
||||
basic_socket<Protocol, SeqPacketSocketService>::operator=(
|
||||
ASIO_MOVE_CAST2(basic_seq_packet_socket<
|
||||
Protocol1, SeqPacketSocketService1>)(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the sequenced packet socket. The
|
||||
* function call will block until the data has been sent successfully, or an
|
||||
* until error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.send(asio::buffer(data, size), 0);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the sequenced packet socket. The
|
||||
* function call will block the data has been sent successfully, or an until
|
||||
* error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref write function if you need to ensure that all data
|
||||
* is written before the blocking operation completes.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the sequenced packet
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_send(asio::buffer(data, size), 0, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
/**
|
||||
* This function is used to receive data on the sequenced packet socket. The
|
||||
* function call will block until data has been received successfully, or
|
||||
* until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param out_flags After the receive call completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.receive(asio::buffer(data, size), out_flags);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags& out_flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, out_flags, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
/**
|
||||
* This function is used to receive data on the sequenced packet socket. The
|
||||
* function call will block until data has been received successfully, or
|
||||
* until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param in_flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param out_flags After the receive call completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.receive(asio::buffer(data, size), 0, out_flags);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags& out_flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, in_flags, out_flags, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the sequenced packet socket. The
|
||||
* function call will block until data has been received successfully, or
|
||||
* until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param in_flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param out_flags After the receive call completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags& out_flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(this->get_implementation(),
|
||||
buffers, in_flags, out_flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the sequenced
|
||||
* packet socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param out_flags Once the asynchronous operation completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record. The caller must guarantee that the referenced
|
||||
* variable remains valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(asio::buffer(data, size), out_flags, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags& out_flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(
|
||||
this->get_implementation(), buffers, 0, out_flags,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the sequenced
|
||||
* data socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param in_flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param out_flags Once the asynchronous operation completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record. The caller must guarantee that the referenced
|
||||
* variable remains valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(
|
||||
* asio::buffer(data, size),
|
||||
* 0, out_flags, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags& out_flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(
|
||||
this->get_implementation(), buffers, in_flags, out_flags,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BASIC_SEQ_PACKET_SOCKET_HPP
|
|
@ -1,695 +0,0 @@
|
|||
//
|
||||
// basic_serial_port.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_SERIAL_PORT_HPP
|
||||
#define ASIO_BASIC_SERIAL_PORT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_SERIAL_PORT) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include <string>
|
||||
#include "asio/basic_io_object.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/serial_port_base.hpp"
|
||||
#include "asio/serial_port_service.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides serial port functionality.
|
||||
/**
|
||||
* The basic_serial_port class template provides functionality that is common
|
||||
* to all serial ports.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename SerialPortService = serial_port_service>
|
||||
class basic_serial_port
|
||||
: public basic_io_object<SerialPortService>,
|
||||
public serial_port_base
|
||||
{
|
||||
public:
|
||||
/// (Deprecated: Use native_handle_type.) The native representation of a
|
||||
/// serial port.
|
||||
typedef typename SerialPortService::native_handle_type native_type;
|
||||
|
||||
/// The native representation of a serial port.
|
||||
typedef typename SerialPortService::native_handle_type native_handle_type;
|
||||
|
||||
/// A basic_serial_port is always the lowest layer.
|
||||
typedef basic_serial_port<SerialPortService> lowest_layer_type;
|
||||
|
||||
/// Construct a basic_serial_port without opening it.
|
||||
/**
|
||||
* This constructor creates a serial port without opening it.
|
||||
*
|
||||
* @param io_service The io_service object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
*/
|
||||
explicit basic_serial_port(asio::io_service& io_service)
|
||||
: basic_io_object<SerialPortService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_serial_port.
|
||||
/**
|
||||
* This constructor creates and opens a serial port for the specified device
|
||||
* name.
|
||||
*
|
||||
* @param io_service The io_service object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
*
|
||||
* @param device The platform-specific device name for this serial
|
||||
* port.
|
||||
*/
|
||||
explicit basic_serial_port(asio::io_service& io_service,
|
||||
const char* device)
|
||||
: basic_io_object<SerialPortService>(io_service)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().open(this->get_implementation(), device, ec);
|
||||
asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
/// Construct and open a basic_serial_port.
|
||||
/**
|
||||
* This constructor creates and opens a serial port for the specified device
|
||||
* name.
|
||||
*
|
||||
* @param io_service The io_service object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
*
|
||||
* @param device The platform-specific device name for this serial
|
||||
* port.
|
||||
*/
|
||||
explicit basic_serial_port(asio::io_service& io_service,
|
||||
const std::string& device)
|
||||
: basic_io_object<SerialPortService>(io_service)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().open(this->get_implementation(), device, ec);
|
||||
asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
/// Construct a basic_serial_port on an existing native serial port.
|
||||
/**
|
||||
* This constructor creates a serial port object to hold an existing native
|
||||
* serial port.
|
||||
*
|
||||
* @param io_service The io_service object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
*
|
||||
* @param native_serial_port A native serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_serial_port(asio::io_service& io_service,
|
||||
const native_handle_type& native_serial_port)
|
||||
: basic_io_object<SerialPortService>(io_service)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().assign(this->get_implementation(),
|
||||
native_serial_port, ec);
|
||||
asio::detail::throw_error(ec, "assign");
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_serial_port from another.
|
||||
/**
|
||||
* This constructor moves a serial port from one object to another.
|
||||
*
|
||||
* @param other The other basic_serial_port object from which the move will
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_serial_port(io_service&) constructor.
|
||||
*/
|
||||
basic_serial_port(basic_serial_port&& other)
|
||||
: basic_io_object<SerialPortService>(
|
||||
ASIO_MOVE_CAST(basic_serial_port)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_serial_port from another.
|
||||
/**
|
||||
* This assignment operator moves a serial port from one object to another.
|
||||
*
|
||||
* @param other The other basic_serial_port object from which the move will
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_serial_port(io_service&) constructor.
|
||||
*/
|
||||
basic_serial_port& operator=(basic_serial_port&& other)
|
||||
{
|
||||
basic_io_object<SerialPortService>::operator=(
|
||||
ASIO_MOVE_CAST(basic_serial_port)(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
/**
|
||||
* This function returns a reference to the lowest layer in a stack of
|
||||
* layers. Since a basic_serial_port cannot contain any further layers, it
|
||||
* simply returns a reference to itself.
|
||||
*
|
||||
* @return A reference to the lowest layer in the stack of layers. Ownership
|
||||
* is not transferred to the caller.
|
||||
*/
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Get a const reference to the lowest layer.
|
||||
/**
|
||||
* This function returns a const reference to the lowest layer in a stack of
|
||||
* layers. Since a basic_serial_port cannot contain any further layers, it
|
||||
* simply returns a reference to itself.
|
||||
*
|
||||
* @return A const reference to the lowest layer in the stack of layers.
|
||||
* Ownership is not transferred to the caller.
|
||||
*/
|
||||
const lowest_layer_type& lowest_layer() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Open the serial port using the specified device name.
|
||||
/**
|
||||
* This function opens the serial port for the specified device name.
|
||||
*
|
||||
* @param device The platform-specific device name.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void open(const std::string& device)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().open(this->get_implementation(), device, ec);
|
||||
asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
/// Open the serial port using the specified device name.
|
||||
/**
|
||||
* This function opens the serial port using the given platform-specific
|
||||
* device name.
|
||||
*
|
||||
* @param device The platform-specific device name.
|
||||
*
|
||||
* @param ec Set the indicate what error occurred, if any.
|
||||
*/
|
||||
asio::error_code open(const std::string& device,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().open(this->get_implementation(), device, ec);
|
||||
}
|
||||
|
||||
/// Assign an existing native serial port to the serial port.
|
||||
/*
|
||||
* This function opens the serial port to hold an existing native serial port.
|
||||
*
|
||||
* @param native_serial_port A native serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void assign(const native_handle_type& native_serial_port)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().assign(this->get_implementation(),
|
||||
native_serial_port, ec);
|
||||
asio::detail::throw_error(ec, "assign");
|
||||
}
|
||||
|
||||
/// Assign an existing native serial port to the serial port.
|
||||
/*
|
||||
* This function opens the serial port to hold an existing native serial port.
|
||||
*
|
||||
* @param native_serial_port A native serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
asio::error_code assign(const native_handle_type& native_serial_port,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().assign(this->get_implementation(),
|
||||
native_serial_port, ec);
|
||||
}
|
||||
|
||||
/// Determine whether the serial port is open.
|
||||
bool is_open() const
|
||||
{
|
||||
return this->get_service().is_open(this->get_implementation());
|
||||
}
|
||||
|
||||
/// Close the serial port.
|
||||
/**
|
||||
* This function is used to close the serial port. Any asynchronous read or
|
||||
* write operations will be cancelled immediately, and will complete with the
|
||||
* asio::error::operation_aborted error.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void close()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().close(this->get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "close");
|
||||
}
|
||||
|
||||
/// Close the serial port.
|
||||
/**
|
||||
* This function is used to close the serial port. Any asynchronous read or
|
||||
* write operations will be cancelled immediately, and will complete with the
|
||||
* asio::error::operation_aborted error.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
asio::error_code close(asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().close(this->get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// (Deprecated: Use native_handle().) Get the native serial port
|
||||
/// representation.
|
||||
/**
|
||||
* This function may be used to obtain the underlying representation of the
|
||||
* serial port. This is intended to allow access to native serial port
|
||||
* functionality that is not otherwise provided.
|
||||
*/
|
||||
native_type native()
|
||||
{
|
||||
return this->get_service().native_handle(this->get_implementation());
|
||||
}
|
||||
|
||||
/// Get the native serial port representation.
|
||||
/**
|
||||
* This function may be used to obtain the underlying representation of the
|
||||
* serial port. This is intended to allow access to native serial port
|
||||
* functionality that is not otherwise provided.
|
||||
*/
|
||||
native_handle_type native_handle()
|
||||
{
|
||||
return this->get_service().native_handle(this->get_implementation());
|
||||
}
|
||||
|
||||
/// Cancel all asynchronous operations associated with the serial port.
|
||||
/**
|
||||
* This function causes all outstanding asynchronous read or write operations
|
||||
* to finish immediately, and the handlers for cancelled operations will be
|
||||
* passed the asio::error::operation_aborted error.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().cancel(this->get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
}
|
||||
|
||||
/// Cancel all asynchronous operations associated with the serial port.
|
||||
/**
|
||||
* This function causes all outstanding asynchronous read or write operations
|
||||
* to finish immediately, and the handlers for cancelled operations will be
|
||||
* passed the asio::error::operation_aborted error.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
asio::error_code cancel(asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().cancel(this->get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Send a break sequence to the serial port.
|
||||
/**
|
||||
* This function causes a break sequence of platform-specific duration to be
|
||||
* sent out the serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void send_break()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().send_break(this->get_implementation(), ec);
|
||||
asio::detail::throw_error(ec, "send_break");
|
||||
}
|
||||
|
||||
/// Send a break sequence to the serial port.
|
||||
/**
|
||||
* This function causes a break sequence of platform-specific duration to be
|
||||
* sent out the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
asio::error_code send_break(asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send_break(this->get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Set an option on the serial port.
|
||||
/**
|
||||
* This function is used to set an option on the serial port.
|
||||
*
|
||||
* @param option The option value to be set on the serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @sa SettableSerialPortOption @n
|
||||
* asio::serial_port_base::baud_rate @n
|
||||
* asio::serial_port_base::flow_control @n
|
||||
* asio::serial_port_base::parity @n
|
||||
* asio::serial_port_base::stop_bits @n
|
||||
* asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename SettableSerialPortOption>
|
||||
void set_option(const SettableSerialPortOption& option)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().set_option(this->get_implementation(), option, ec);
|
||||
asio::detail::throw_error(ec, "set_option");
|
||||
}
|
||||
|
||||
/// Set an option on the serial port.
|
||||
/**
|
||||
* This function is used to set an option on the serial port.
|
||||
*
|
||||
* @param option The option value to be set on the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @sa SettableSerialPortOption @n
|
||||
* asio::serial_port_base::baud_rate @n
|
||||
* asio::serial_port_base::flow_control @n
|
||||
* asio::serial_port_base::parity @n
|
||||
* asio::serial_port_base::stop_bits @n
|
||||
* asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename SettableSerialPortOption>
|
||||
asio::error_code set_option(const SettableSerialPortOption& option,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().set_option(
|
||||
this->get_implementation(), option, ec);
|
||||
}
|
||||
|
||||
/// Get an option from the serial port.
|
||||
/**
|
||||
* This function is used to get the current value of an option on the serial
|
||||
* port.
|
||||
*
|
||||
* @param option The option value to be obtained from the serial port.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @sa GettableSerialPortOption @n
|
||||
* asio::serial_port_base::baud_rate @n
|
||||
* asio::serial_port_base::flow_control @n
|
||||
* asio::serial_port_base::parity @n
|
||||
* asio::serial_port_base::stop_bits @n
|
||||
* asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename GettableSerialPortOption>
|
||||
void get_option(GettableSerialPortOption& option)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->get_service().get_option(this->get_implementation(), option, ec);
|
||||
asio::detail::throw_error(ec, "get_option");
|
||||
}
|
||||
|
||||
/// Get an option from the serial port.
|
||||
/**
|
||||
* This function is used to get the current value of an option on the serial
|
||||
* port.
|
||||
*
|
||||
* @param option The option value to be obtained from the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occured, if any.
|
||||
*
|
||||
* @sa GettableSerialPortOption @n
|
||||
* asio::serial_port_base::baud_rate @n
|
||||
* asio::serial_port_base::flow_control @n
|
||||
* asio::serial_port_base::parity @n
|
||||
* asio::serial_port_base::stop_bits @n
|
||||
* asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename GettableSerialPortOption>
|
||||
asio::error_code get_option(GettableSerialPortOption& option,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().get_option(
|
||||
this->get_implementation(), option, ec);
|
||||
}
|
||||
|
||||
/// Write some data to the serial port.
|
||||
/**
|
||||
* This function is used to write data to the serial port. The function call
|
||||
* will block until one or more bytes of the data has been written
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the serial port.
|
||||
*
|
||||
* @returns The number of bytes written.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The write_some operation may not transmit all of the data to the
|
||||
* peer. Consider using the @ref write function if you need to ensure that
|
||||
* all data is written before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.write_some(asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on writing multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().write_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
asio::detail::throw_error(ec, "write_some");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Write some data to the serial port.
|
||||
/**
|
||||
* This function is used to write data to the serial port. The function call
|
||||
* will block until one or more bytes of the data has been written
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes written. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The write_some operation may not transmit all of the data to the
|
||||
* peer. Consider using the @ref write function if you need to ensure that
|
||||
* all data is written before the blocking operation completes.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().write_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write.
|
||||
/**
|
||||
* This function is used to asynchronously write data to the serial port.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the serial port.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the write operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes written.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The write operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
* data is written before the asynchronous operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.async_write_some(asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on writing multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_write_some(this->get_implementation(),
|
||||
buffers, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Read some data from the serial port.
|
||||
/**
|
||||
* This function is used to read data from the serial port. The function
|
||||
* call will block until one or more bytes of data has been read successfully,
|
||||
* or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
*
|
||||
* @returns The number of bytes read.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The read_some operation may not read all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that
|
||||
* the requested amount of data is read before the blocking operation
|
||||
* completes.
|
||||
*
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.read_some(asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on reading into multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().read_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
asio::detail::throw_error(ec, "read_some");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Read some data from the serial port.
|
||||
/**
|
||||
* This function is used to read data from the serial port. The function
|
||||
* call will block until one or more bytes of data has been read successfully,
|
||||
* or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes read. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The read_some operation may not read all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that
|
||||
* the requested amount of data is read before the blocking operation
|
||||
* completes.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().read_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read.
|
||||
/**
|
||||
* This function is used to asynchronously read data from the serial port.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the read operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes read.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The read operation may not read all of the requested number of bytes.
|
||||
* Consider using the @ref async_read function if you need to ensure that the
|
||||
* requested amount of data is read before the asynchronous operation
|
||||
* completes.
|
||||
*
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.async_read_some(asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on reading into multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_read_some(this->get_implementation(),
|
||||
buffers, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // defined(ASIO_HAS_SERIAL_PORT)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // ASIO_BASIC_SERIAL_PORT_HPP
|
|
@ -1,384 +0,0 @@
|
|||
//
|
||||
// basic_signal_set.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_SIGNAL_SET_HPP
|
||||
#define ASIO_BASIC_SIGNAL_SET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#include "asio/basic_io_object.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/signal_set_service.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides signal functionality.
|
||||
/**
|
||||
* The basic_signal_set class template provides the ability to perform an
|
||||
* asynchronous wait for one or more signals to occur.
|
||||
*
|
||||
* Most applications will use the asio::signal_set typedef.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Example
|
||||
* Performing an asynchronous wait:
|
||||
* @code
|
||||
* void handler(
|
||||
* const asio::error_code& error,
|
||||
* int signal_number)
|
||||
* {
|
||||
* if (!error)
|
||||
* {
|
||||
* // A signal occurred.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* // Construct a signal set registered for process termination.
|
||||
* asio::signal_set signals(io_service, SIGINT, SIGTERM);
|
||||
*
|
||||
* // Start an asynchronous wait for one of the signals to occur.
|
||||
* signals.async_wait(handler);
|
||||
* @endcode
|
||||
*
|
||||
* @par Queueing of signal notifications
|
||||
*
|
||||
* If a signal is registered with a signal_set, and the signal occurs when
|
||||
* there are no waiting handlers, then the signal notification is queued. The
|
||||
* next async_wait operation on that signal_set will dequeue the notification.
|
||||
* If multiple notifications are queued, subsequent async_wait operations
|
||||
* dequeue them one at a time. Signal notifications are dequeued in order of
|
||||
* ascending signal number.
|
||||
*
|
||||
* If a signal number is removed from a signal_set (using the @c remove or @c
|
||||
* erase member functions) then any queued notifications for that signal are
|
||||
* discarded.
|
||||
*
|
||||
* @par Multiple registration of signals
|
||||
*
|
||||
* The same signal number may be registered with different signal_set objects.
|
||||
* When the signal occurs, one handler is called for each signal_set object.
|
||||
*
|
||||
* Note that multiple registration only works for signals that are registered
|
||||
* using Asio. The application must not also register a signal handler using
|
||||
* functions such as @c signal() or @c sigaction().
|
||||
*
|
||||
* @par Signal masking on POSIX platforms
|
||||
*
|
||||
* POSIX allows signals to be blocked using functions such as @c sigprocmask()
|
||||
* and @c pthread_sigmask(). For signals to be delivered, programs must ensure
|
||||
* that any signals registered using signal_set objects are unblocked in at
|
||||
* least one thread.
|
||||
*/
|
||||
template <typename SignalSetService = signal_set_service>
|
||||
class basic_signal_set
|
||||
: public basic_io_object<SignalSetService>
|
||||
{
|
||||
public:
|
||||
/// Construct a signal set without adding any signals.
|
||||
/**
|
||||
* This constructor creates a signal set without registering for any signals.
|
||||
*
|
||||
* @param io_service The io_service object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
*/
|
||||
explicit basic_signal_set(asio::io_service& io_service)
|
||||
: basic_io_object<SignalSetService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a signal set and add one signal.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for one signal.
|
||||
*
|
||||
* @param io_service The io_service object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
*
|
||||
* @param signal_number_1 The signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code asio::signal_set signals(io_service);
|
||||
* signals.add(signal_number_1); @endcode
|
||||
*/
|
||||
basic_signal_set(asio::io_service& io_service, int signal_number_1)
|
||||
: basic_io_object<SignalSetService>(io_service)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.add(this->implementation, signal_number_1, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Construct a signal set and add two signals.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for two signals.
|
||||
*
|
||||
* @param io_service The io_service object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
*
|
||||
* @param signal_number_1 The first signal number to be added.
|
||||
*
|
||||
* @param signal_number_2 The second signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code asio::signal_set signals(io_service);
|
||||
* signals.add(signal_number_1);
|
||||
* signals.add(signal_number_2); @endcode
|
||||
*/
|
||||
basic_signal_set(asio::io_service& io_service, int signal_number_1,
|
||||
int signal_number_2)
|
||||
: basic_io_object<SignalSetService>(io_service)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.add(this->implementation, signal_number_1, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
this->service.add(this->implementation, signal_number_2, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Construct a signal set and add three signals.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for three signals.
|
||||
*
|
||||
* @param io_service The io_service object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
*
|
||||
* @param signal_number_1 The first signal number to be added.
|
||||
*
|
||||
* @param signal_number_2 The second signal number to be added.
|
||||
*
|
||||
* @param signal_number_3 The third signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code asio::signal_set signals(io_service);
|
||||
* signals.add(signal_number_1);
|
||||
* signals.add(signal_number_2);
|
||||
* signals.add(signal_number_3); @endcode
|
||||
*/
|
||||
basic_signal_set(asio::io_service& io_service, int signal_number_1,
|
||||
int signal_number_2, int signal_number_3)
|
||||
: basic_io_object<SignalSetService>(io_service)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.add(this->implementation, signal_number_1, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
this->service.add(this->implementation, signal_number_2, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
this->service.add(this->implementation, signal_number_3, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Add a signal to a signal_set.
|
||||
/**
|
||||
* This function adds the specified signal to the set. It has no effect if the
|
||||
* signal is already in the set.
|
||||
*
|
||||
* @param signal_number The signal to be added to the set.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void add(int signal_number)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.add(this->implementation, signal_number, ec);
|
||||
asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Add a signal to a signal_set.
|
||||
/**
|
||||
* This function adds the specified signal to the set. It has no effect if the
|
||||
* signal is already in the set.
|
||||
*
|
||||
* @param signal_number The signal to be added to the set.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
asio::error_code add(int signal_number,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->service.add(this->implementation, signal_number, ec);
|
||||
}
|
||||
|
||||
/// Remove a signal from a signal_set.
|
||||
/**
|
||||
* This function removes the specified signal from the set. It has no effect
|
||||
* if the signal is not in the set.
|
||||
*
|
||||
* @param signal_number The signal to be removed from the set.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note Removes any notifications that have been queued for the specified
|
||||
* signal number.
|
||||
*/
|
||||
void remove(int signal_number)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.remove(this->implementation, signal_number, ec);
|
||||
asio::detail::throw_error(ec, "remove");
|
||||
}
|
||||
|
||||
/// Remove a signal from a signal_set.
|
||||
/**
|
||||
* This function removes the specified signal from the set. It has no effect
|
||||
* if the signal is not in the set.
|
||||
*
|
||||
* @param signal_number The signal to be removed from the set.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @note Removes any notifications that have been queued for the specified
|
||||
* signal number.
|
||||
*/
|
||||
asio::error_code remove(int signal_number,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->service.remove(this->implementation, signal_number, ec);
|
||||
}
|
||||
|
||||
/// Remove all signals from a signal_set.
|
||||
/**
|
||||
* This function removes all signals from the set. It has no effect if the set
|
||||
* is already empty.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note Removes all queued notifications.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.clear(this->implementation, ec);
|
||||
asio::detail::throw_error(ec, "clear");
|
||||
}
|
||||
|
||||
/// Remove all signals from a signal_set.
|
||||
/**
|
||||
* This function removes all signals from the set. It has no effect if the set
|
||||
* is already empty.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @note Removes all queued notifications.
|
||||
*/
|
||||
asio::error_code clear(asio::error_code& ec)
|
||||
{
|
||||
return this->service.clear(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Cancel all operations associated with the signal set.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the signal set. The handler for each cancelled
|
||||
* operation will be invoked with the asio::error::operation_aborted
|
||||
* error code.
|
||||
*
|
||||
* Cancellation does not alter the set of registered signals.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If a registered signal occurred before cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
void cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.cancel(this->implementation, ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
}
|
||||
|
||||
/// Cancel all operations associated with the signal set.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the signal set. The handler for each cancelled
|
||||
* operation will be invoked with the asio::error::operation_aborted
|
||||
* error code.
|
||||
*
|
||||
* Cancellation does not alter the set of registered signals.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @note If a registered signal occurred before cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
asio::error_code cancel(asio::error_code& ec)
|
||||
{
|
||||
return this->service.cancel(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous operation to wait for a signal to be delivered.
|
||||
/**
|
||||
* This function may be used to initiate an asynchronous wait against the
|
||||
* signal set. It always returns immediately.
|
||||
*
|
||||
* For each call to async_wait(), the supplied handler will be called exactly
|
||||
* once. The handler will be called when:
|
||||
*
|
||||
* @li One of the registered signals in the signal set occurs; or
|
||||
*
|
||||
* @li The signal set was cancelled, in which case the handler is passed the
|
||||
* error code asio::error::operation_aborted.
|
||||
*
|
||||
* @param handler The handler to be called when the signal occurs. Copies
|
||||
* will be made of the handler as required. The function signature of the
|
||||
* handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* int signal_number // Indicates which signal occurred.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*/
|
||||
template <typename SignalHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(SignalHandler,
|
||||
void (asio::error_code, int))
|
||||
async_wait(ASIO_MOVE_ARG(SignalHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a SignalHandler.
|
||||
ASIO_SIGNAL_HANDLER_CHECK(SignalHandler, handler) type_check;
|
||||
|
||||
return this->service.async_wait(this->implementation,
|
||||
ASIO_MOVE_CAST(SignalHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BASIC_SIGNAL_SET_HPP
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,286 +0,0 @@
|
|||
//
|
||||
// basic_socket_iostream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_SOCKET_IOSTREAM_HPP
|
||||
#define ASIO_BASIC_SOCKET_IOSTREAM_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include "asio/basic_socket_streambuf.hpp"
|
||||
#include "asio/stream_socket_service.hpp"
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
# include "asio/detail/variadic_templates.hpp"
|
||||
|
||||
// A macro that should expand to:
|
||||
// template <typename T1, ..., typename Tn>
|
||||
// explicit basic_socket_iostream(T1 x1, ..., Tn xn)
|
||||
// : std::basic_iostream<char>(
|
||||
// &this->detail::socket_iostream_base<
|
||||
// Protocol, StreamSocketService, Time,
|
||||
// TimeTraits, TimerService>::streambuf_)
|
||||
// {
|
||||
// if (rdbuf()->connect(x1, ..., xn) == 0)
|
||||
// this->setstate(std::ios_base::failbit);
|
||||
// }
|
||||
// This macro should only persist within this file.
|
||||
|
||||
# define ASIO_PRIVATE_CTR_DEF(n) \
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
explicit basic_socket_iostream(ASIO_VARIADIC_PARAMS(n)) \
|
||||
: std::basic_iostream<char>( \
|
||||
&this->detail::socket_iostream_base< \
|
||||
Protocol, StreamSocketService, Time, \
|
||||
TimeTraits, TimerService>::streambuf_) \
|
||||
{ \
|
||||
this->setf(std::ios_base::unitbuf); \
|
||||
if (rdbuf()->connect(ASIO_VARIADIC_ARGS(n)) == 0) \
|
||||
this->setstate(std::ios_base::failbit); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
// A macro that should expand to:
|
||||
// template <typename T1, ..., typename Tn>
|
||||
// void connect(T1 x1, ..., Tn xn)
|
||||
// {
|
||||
// if (rdbuf()->connect(x1, ..., xn) == 0)
|
||||
// this->setstate(std::ios_base::failbit);
|
||||
// }
|
||||
// This macro should only persist within this file.
|
||||
|
||||
# define ASIO_PRIVATE_CONNECT_DEF(n) \
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
void connect(ASIO_VARIADIC_PARAMS(n)) \
|
||||
{ \
|
||||
if (rdbuf()->connect(ASIO_VARIADIC_ARGS(n)) == 0) \
|
||||
this->setstate(std::ios_base::failbit); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// A separate base class is used to ensure that the streambuf is initialised
|
||||
// prior to the basic_socket_iostream's basic_iostream base class.
|
||||
template <typename Protocol, typename StreamSocketService,
|
||||
typename Time, typename TimeTraits, typename TimerService>
|
||||
class socket_iostream_base
|
||||
{
|
||||
protected:
|
||||
basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService> streambuf_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/// Iostream interface for a socket.
|
||||
template <typename Protocol,
|
||||
typename StreamSocketService = stream_socket_service<Protocol>,
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
typename Time = boost::posix_time::ptime,
|
||||
typename TimeTraits = asio::time_traits<Time>,
|
||||
typename TimerService = deadline_timer_service<Time, TimeTraits> >
|
||||
#else
|
||||
typename Time = steady_timer::clock_type,
|
||||
typename TimeTraits = steady_timer::traits_type,
|
||||
typename TimerService = steady_timer::service_type>
|
||||
#endif
|
||||
class basic_socket_iostream
|
||||
: private detail::socket_iostream_base<Protocol,
|
||||
StreamSocketService, Time, TimeTraits, TimerService>,
|
||||
public std::basic_iostream<char>
|
||||
{
|
||||
private:
|
||||
// These typedefs are intended keep this class's implementation independent
|
||||
// of whether it's using Boost.DateTime, Boost.Chrono or std::chrono.
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
typedef TimeTraits traits_helper;
|
||||
#else
|
||||
typedef detail::chrono_time_traits<Time, TimeTraits> traits_helper;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The time type.
|
||||
typedef typename TimeTraits::time_type time_type;
|
||||
|
||||
/// The duration type.
|
||||
typedef typename TimeTraits::duration_type duration_type;
|
||||
#else
|
||||
typedef typename traits_helper::time_type time_type;
|
||||
typedef typename traits_helper::duration_type duration_type;
|
||||
#endif
|
||||
|
||||
/// Construct a basic_socket_iostream without establishing a connection.
|
||||
basic_socket_iostream()
|
||||
: std::basic_iostream<char>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol, StreamSocketService, Time,
|
||||
TimeTraits, TimerService>::streambuf_)
|
||||
{
|
||||
this->setf(std::ios_base::unitbuf);
|
||||
}
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Establish a connection to an endpoint corresponding to a resolver query.
|
||||
/**
|
||||
* This constructor automatically establishes a connection based on the
|
||||
* supplied resolver query parameters. The arguments are used to construct
|
||||
* a resolver query object.
|
||||
*/
|
||||
template <typename T1, ..., typename TN>
|
||||
explicit basic_socket_iostream(T1 t1, ..., TN tn);
|
||||
#elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
template <typename... T>
|
||||
explicit basic_socket_iostream(T... x)
|
||||
: std::basic_iostream<char>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol, StreamSocketService, Time,
|
||||
TimeTraits, TimerService>::streambuf_)
|
||||
{
|
||||
this->setf(std::ios_base::unitbuf);
|
||||
if (rdbuf()->connect(x...) == 0)
|
||||
this->setstate(std::ios_base::failbit);
|
||||
}
|
||||
#else
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_CTR_DEF)
|
||||
#endif
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Establish a connection to an endpoint corresponding to a resolver query.
|
||||
/**
|
||||
* This function automatically establishes a connection based on the supplied
|
||||
* resolver query parameters. The arguments are used to construct a resolver
|
||||
* query object.
|
||||
*/
|
||||
template <typename T1, ..., typename TN>
|
||||
void connect(T1 t1, ..., TN tn);
|
||||
#elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
template <typename... T>
|
||||
void connect(T... x)
|
||||
{
|
||||
if (rdbuf()->connect(x...) == 0)
|
||||
this->setstate(std::ios_base::failbit);
|
||||
}
|
||||
#else
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_CONNECT_DEF)
|
||||
#endif
|
||||
|
||||
/// Close the connection.
|
||||
void close()
|
||||
{
|
||||
if (rdbuf()->close() == 0)
|
||||
this->setstate(std::ios_base::failbit);
|
||||
}
|
||||
|
||||
/// Return a pointer to the underlying streambuf.
|
||||
basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService>* rdbuf() const
|
||||
{
|
||||
return const_cast<basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService>*>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol, StreamSocketService, Time,
|
||||
TimeTraits, TimerService>::streambuf_);
|
||||
}
|
||||
|
||||
/// Get the last error associated with the stream.
|
||||
/**
|
||||
* @return An \c error_code corresponding to the last error from the stream.
|
||||
*
|
||||
* @par Example
|
||||
* To print the error associated with a failure to establish a connection:
|
||||
* @code tcp::iostream s("www.boost.org", "http");
|
||||
* if (!s)
|
||||
* {
|
||||
* std::cout << "Error: " << s.error().message() << std::endl;
|
||||
* } @endcode
|
||||
*/
|
||||
const asio::error_code& error() const
|
||||
{
|
||||
return rdbuf()->puberror();
|
||||
}
|
||||
|
||||
/// Get the stream's expiry time as an absolute time.
|
||||
/**
|
||||
* @return An absolute time value representing the stream's expiry time.
|
||||
*/
|
||||
time_type expires_at() const
|
||||
{
|
||||
return rdbuf()->expires_at();
|
||||
}
|
||||
|
||||
/// Set the stream's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the stream.
|
||||
*/
|
||||
void expires_at(const time_type& expiry_time)
|
||||
{
|
||||
rdbuf()->expires_at(expiry_time);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time relative to now.
|
||||
/**
|
||||
* @return A relative time value representing the stream's expiry time.
|
||||
*/
|
||||
duration_type expires_from_now() const
|
||||
{
|
||||
return rdbuf()->expires_from_now();
|
||||
}
|
||||
|
||||
/// Set the stream's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*/
|
||||
void expires_from_now(const duration_type& expiry_time)
|
||||
{
|
||||
rdbuf()->expires_from_now(expiry_time);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
# undef ASIO_PRIVATE_CTR_DEF
|
||||
# undef ASIO_PRIVATE_CONNECT_DEF
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // ASIO_BASIC_SOCKET_IOSTREAM_HPP
|
|
@ -1,567 +0,0 @@
|
|||
//
|
||||
// basic_socket_streambuf.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_SOCKET_STREAMBUF_HPP
|
||||
#define ASIO_BASIC_SOCKET_STREAMBUF_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#include <streambuf>
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/deadline_timer_service.hpp"
|
||||
#include "asio/detail/array.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
#include "asio/stream_socket_service.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
# include "asio/deadline_timer.hpp"
|
||||
#else
|
||||
# include "asio/steady_timer.hpp"
|
||||
#endif
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
# include "asio/detail/variadic_templates.hpp"
|
||||
|
||||
// A macro that should expand to:
|
||||
// template <typename T1, ..., typename Tn>
|
||||
// basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
// Time, TimeTraits, TimerService>* connect(
|
||||
// T1 x1, ..., Tn xn)
|
||||
// {
|
||||
// init_buffers();
|
||||
// this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
// typedef typename Protocol::resolver resolver_type;
|
||||
// typedef typename resolver_type::query resolver_query;
|
||||
// resolver_query query(x1, ..., xn);
|
||||
// resolve_and_connect(query);
|
||||
// return !ec_ ? this : 0;
|
||||
// }
|
||||
// This macro should only persist within this file.
|
||||
|
||||
# define ASIO_PRIVATE_CONNECT_DEF(n) \
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
basic_socket_streambuf<Protocol, StreamSocketService, \
|
||||
Time, TimeTraits, TimerService>* connect(ASIO_VARIADIC_PARAMS(n)) \
|
||||
{ \
|
||||
init_buffers(); \
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_); \
|
||||
typedef typename Protocol::resolver resolver_type; \
|
||||
typedef typename resolver_type::query resolver_query; \
|
||||
resolver_query query(ASIO_VARIADIC_ARGS(n)); \
|
||||
resolve_and_connect(query); \
|
||||
return !ec_ ? this : 0; \
|
||||
} \
|
||||
/**/
|
||||
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// A separate base class is used to ensure that the io_service is initialised
|
||||
// prior to the basic_socket_streambuf's basic_socket base class.
|
||||
class socket_streambuf_base
|
||||
{
|
||||
protected:
|
||||
io_service io_service_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// Iostream streambuf for a socket.
|
||||
template <typename Protocol,
|
||||
typename StreamSocketService = stream_socket_service<Protocol>,
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
typename Time = boost::posix_time::ptime,
|
||||
typename TimeTraits = asio::time_traits<Time>,
|
||||
typename TimerService = deadline_timer_service<Time, TimeTraits> >
|
||||
#else
|
||||
typename Time = steady_timer::clock_type,
|
||||
typename TimeTraits = steady_timer::traits_type,
|
||||
typename TimerService = steady_timer::service_type>
|
||||
#endif
|
||||
class basic_socket_streambuf
|
||||
: public std::streambuf,
|
||||
private detail::socket_streambuf_base,
|
||||
public basic_socket<Protocol, StreamSocketService>
|
||||
{
|
||||
private:
|
||||
// These typedefs are intended keep this class's implementation independent
|
||||
// of whether it's using Boost.DateTime, Boost.Chrono or std::chrono.
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
typedef TimeTraits traits_helper;
|
||||
#else
|
||||
typedef detail::chrono_time_traits<Time, TimeTraits> traits_helper;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The time type.
|
||||
typedef typename TimeTraits::time_type time_type;
|
||||
|
||||
/// The duration type.
|
||||
typedef typename TimeTraits::duration_type duration_type;
|
||||
#else
|
||||
typedef typename traits_helper::time_type time_type;
|
||||
typedef typename traits_helper::duration_type duration_type;
|
||||
#endif
|
||||
|
||||
/// Construct a basic_socket_streambuf without establishing a connection.
|
||||
basic_socket_streambuf()
|
||||
: basic_socket<Protocol, StreamSocketService>(
|
||||
this->detail::socket_streambuf_base::io_service_),
|
||||
unbuffered_(false),
|
||||
timer_service_(0),
|
||||
timer_state_(no_timer)
|
||||
{
|
||||
init_buffers();
|
||||
}
|
||||
|
||||
/// Destructor flushes buffered data.
|
||||
virtual ~basic_socket_streambuf()
|
||||
{
|
||||
if (pptr() != pbase())
|
||||
overflow(traits_type::eof());
|
||||
|
||||
destroy_timer();
|
||||
}
|
||||
|
||||
/// Establish a connection.
|
||||
/**
|
||||
* This function establishes a connection to the specified endpoint.
|
||||
*
|
||||
* @return \c this if a connection was successfully established, a null
|
||||
* pointer otherwise.
|
||||
*/
|
||||
basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService>* connect(
|
||||
const endpoint_type& endpoint)
|
||||
{
|
||||
init_buffers();
|
||||
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
|
||||
if (timer_state_ == timer_has_expired)
|
||||
{
|
||||
ec_ = asio::error::operation_aborted;
|
||||
return 0;
|
||||
}
|
||||
|
||||
io_handler handler = { this };
|
||||
this->basic_socket<Protocol, StreamSocketService>::async_connect(
|
||||
endpoint, handler);
|
||||
|
||||
ec_ = asio::error::would_block;
|
||||
this->get_service().get_io_service().reset();
|
||||
do this->get_service().get_io_service().run_one();
|
||||
while (ec_ == asio::error::would_block);
|
||||
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Establish a connection.
|
||||
/**
|
||||
* This function automatically establishes a connection based on the supplied
|
||||
* resolver query parameters. The arguments are used to construct a resolver
|
||||
* query object.
|
||||
*
|
||||
* @return \c this if a connection was successfully established, a null
|
||||
* pointer otherwise.
|
||||
*/
|
||||
template <typename T1, ..., typename TN>
|
||||
basic_socket_streambuf<Protocol, StreamSocketService>* connect(
|
||||
T1 t1, ..., TN tn);
|
||||
#elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
template <typename... T>
|
||||
basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService>* connect(T... x)
|
||||
{
|
||||
init_buffers();
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
typedef typename Protocol::resolver resolver_type;
|
||||
typedef typename resolver_type::query resolver_query;
|
||||
resolver_query query(x...);
|
||||
resolve_and_connect(query);
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
#else
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_CONNECT_DEF)
|
||||
#endif
|
||||
|
||||
/// Close the connection.
|
||||
/**
|
||||
* @return \c this if a connection was successfully established, a null
|
||||
* pointer otherwise.
|
||||
*/
|
||||
basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService>* close()
|
||||
{
|
||||
sync();
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
if (!ec_)
|
||||
init_buffers();
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
|
||||
/// Get the last error associated with the stream buffer.
|
||||
/**
|
||||
* @return An \c error_code corresponding to the last error from the stream
|
||||
* buffer.
|
||||
*/
|
||||
const asio::error_code& puberror() const
|
||||
{
|
||||
return error();
|
||||
}
|
||||
|
||||
/// Get the stream buffer's expiry time as an absolute time.
|
||||
/**
|
||||
* @return An absolute time value representing the stream buffer's expiry
|
||||
* time.
|
||||
*/
|
||||
time_type expires_at() const
|
||||
{
|
||||
return timer_service_
|
||||
? timer_service_->expires_at(timer_implementation_)
|
||||
: time_type();
|
||||
}
|
||||
|
||||
/// Set the stream buffer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the stream.
|
||||
*/
|
||||
void expires_at(const time_type& expiry_time)
|
||||
{
|
||||
construct_timer();
|
||||
|
||||
asio::error_code ec;
|
||||
timer_service_->expires_at(timer_implementation_, expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
|
||||
start_timer();
|
||||
}
|
||||
|
||||
/// Get the stream buffer's expiry time relative to now.
|
||||
/**
|
||||
* @return A relative time value representing the stream buffer's expiry time.
|
||||
*/
|
||||
duration_type expires_from_now() const
|
||||
{
|
||||
return traits_helper::subtract(expires_at(), traits_helper::now());
|
||||
}
|
||||
|
||||
/// Set the stream buffer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*/
|
||||
void expires_from_now(const duration_type& expiry_time)
|
||||
{
|
||||
construct_timer();
|
||||
|
||||
asio::error_code ec;
|
||||
timer_service_->expires_from_now(timer_implementation_, expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_from_now");
|
||||
|
||||
start_timer();
|
||||
}
|
||||
|
||||
protected:
|
||||
int_type underflow()
|
||||
{
|
||||
if (gptr() == egptr())
|
||||
{
|
||||
if (timer_state_ == timer_has_expired)
|
||||
{
|
||||
ec_ = asio::error::operation_aborted;
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
io_handler handler = { this };
|
||||
this->get_service().async_receive(this->get_implementation(),
|
||||
asio::buffer(asio::buffer(get_buffer_) + putback_max),
|
||||
0, handler);
|
||||
|
||||
ec_ = asio::error::would_block;
|
||||
this->get_service().get_io_service().reset();
|
||||
do this->get_service().get_io_service().run_one();
|
||||
while (ec_ == asio::error::would_block);
|
||||
if (ec_)
|
||||
return traits_type::eof();
|
||||
|
||||
setg(&get_buffer_[0], &get_buffer_[0] + putback_max,
|
||||
&get_buffer_[0] + putback_max + bytes_transferred_);
|
||||
return traits_type::to_int_type(*gptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
return traits_type::eof();
|
||||
}
|
||||
}
|
||||
|
||||
int_type overflow(int_type c)
|
||||
{
|
||||
if (unbuffered_)
|
||||
{
|
||||
if (traits_type::eq_int_type(c, traits_type::eof()))
|
||||
{
|
||||
// Nothing to do.
|
||||
return traits_type::not_eof(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timer_state_ == timer_has_expired)
|
||||
{
|
||||
ec_ = asio::error::operation_aborted;
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
// Send the single character immediately.
|
||||
char_type ch = traits_type::to_char_type(c);
|
||||
io_handler handler = { this };
|
||||
this->get_service().async_send(this->get_implementation(),
|
||||
asio::buffer(&ch, sizeof(char_type)), 0, handler);
|
||||
|
||||
ec_ = asio::error::would_block;
|
||||
this->get_service().get_io_service().reset();
|
||||
do this->get_service().get_io_service().run_one();
|
||||
while (ec_ == asio::error::would_block);
|
||||
if (ec_)
|
||||
return traits_type::eof();
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send all data in the output buffer.
|
||||
asio::const_buffer buffer =
|
||||
asio::buffer(pbase(), pptr() - pbase());
|
||||
while (asio::buffer_size(buffer) > 0)
|
||||
{
|
||||
if (timer_state_ == timer_has_expired)
|
||||
{
|
||||
ec_ = asio::error::operation_aborted;
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
io_handler handler = { this };
|
||||
this->get_service().async_send(this->get_implementation(),
|
||||
asio::buffer(buffer), 0, handler);
|
||||
|
||||
ec_ = asio::error::would_block;
|
||||
this->get_service().get_io_service().reset();
|
||||
do this->get_service().get_io_service().run_one();
|
||||
while (ec_ == asio::error::would_block);
|
||||
if (ec_)
|
||||
return traits_type::eof();
|
||||
|
||||
buffer = buffer + bytes_transferred_;
|
||||
}
|
||||
setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size());
|
||||
|
||||
// If the new character is eof then our work here is done.
|
||||
if (traits_type::eq_int_type(c, traits_type::eof()))
|
||||
return traits_type::not_eof(c);
|
||||
|
||||
// Add the new character to the output buffer.
|
||||
*pptr() = traits_type::to_char_type(c);
|
||||
pbump(1);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
int sync()
|
||||
{
|
||||
return overflow(traits_type::eof());
|
||||
}
|
||||
|
||||
std::streambuf* setbuf(char_type* s, std::streamsize n)
|
||||
{
|
||||
if (pptr() == pbase() && s == 0 && n == 0)
|
||||
{
|
||||
unbuffered_ = true;
|
||||
setp(0, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Get the last error associated with the stream buffer.
|
||||
/**
|
||||
* @return An \c error_code corresponding to the last error from the stream
|
||||
* buffer.
|
||||
*/
|
||||
virtual const asio::error_code& error() const
|
||||
{
|
||||
return ec_;
|
||||
}
|
||||
|
||||
private:
|
||||
void init_buffers()
|
||||
{
|
||||
setg(&get_buffer_[0],
|
||||
&get_buffer_[0] + putback_max,
|
||||
&get_buffer_[0] + putback_max);
|
||||
if (unbuffered_)
|
||||
setp(0, 0);
|
||||
else
|
||||
setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size());
|
||||
}
|
||||
|
||||
template <typename ResolverQuery>
|
||||
void resolve_and_connect(const ResolverQuery& query)
|
||||
{
|
||||
typedef typename Protocol::resolver resolver_type;
|
||||
typedef typename resolver_type::iterator iterator_type;
|
||||
resolver_type resolver(detail::socket_streambuf_base::io_service_);
|
||||
iterator_type i = resolver.resolve(query, ec_);
|
||||
if (!ec_)
|
||||
{
|
||||
iterator_type end;
|
||||
ec_ = asio::error::host_not_found;
|
||||
while (ec_ && i != end)
|
||||
{
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
|
||||
if (timer_state_ == timer_has_expired)
|
||||
{
|
||||
ec_ = asio::error::operation_aborted;
|
||||
return;
|
||||
}
|
||||
|
||||
io_handler handler = { this };
|
||||
this->basic_socket<Protocol, StreamSocketService>::async_connect(
|
||||
*i, handler);
|
||||
|
||||
ec_ = asio::error::would_block;
|
||||
this->get_service().get_io_service().reset();
|
||||
do this->get_service().get_io_service().run_one();
|
||||
while (ec_ == asio::error::would_block);
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct io_handler;
|
||||
friend struct io_handler;
|
||||
struct io_handler
|
||||
{
|
||||
basic_socket_streambuf* this_;
|
||||
|
||||
void operator()(const asio::error_code& ec,
|
||||
std::size_t bytes_transferred = 0)
|
||||
{
|
||||
this_->ec_ = ec;
|
||||
this_->bytes_transferred_ = bytes_transferred;
|
||||
}
|
||||
};
|
||||
|
||||
struct timer_handler;
|
||||
friend struct timer_handler;
|
||||
struct timer_handler
|
||||
{
|
||||
basic_socket_streambuf* this_;
|
||||
|
||||
void operator()(const asio::error_code&)
|
||||
{
|
||||
time_type now = traits_helper::now();
|
||||
|
||||
time_type expiry_time = this_->timer_service_->expires_at(
|
||||
this_->timer_implementation_);
|
||||
|
||||
if (traits_helper::less_than(now, expiry_time))
|
||||
{
|
||||
this_->timer_state_ = timer_is_pending;
|
||||
this_->timer_service_->async_wait(this_->timer_implementation_, *this);
|
||||
}
|
||||
else
|
||||
{
|
||||
this_->timer_state_ = timer_has_expired;
|
||||
asio::error_code ec;
|
||||
this_->basic_socket<Protocol, StreamSocketService>::close(ec);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void construct_timer()
|
||||
{
|
||||
if (timer_service_ == 0)
|
||||
{
|
||||
TimerService& timer_service = use_service<TimerService>(
|
||||
detail::socket_streambuf_base::io_service_);
|
||||
timer_service.construct(timer_implementation_);
|
||||
timer_service_ = &timer_service;
|
||||
}
|
||||
}
|
||||
|
||||
void destroy_timer()
|
||||
{
|
||||
if (timer_service_)
|
||||
timer_service_->destroy(timer_implementation_);
|
||||
}
|
||||
|
||||
void start_timer()
|
||||
{
|
||||
if (timer_state_ != timer_is_pending)
|
||||
{
|
||||
timer_handler handler = { this };
|
||||
handler(asio::error_code());
|
||||
}
|
||||
}
|
||||
|
||||
enum { putback_max = 8 };
|
||||
enum { buffer_size = 512 };
|
||||
asio::detail::array<char, buffer_size> get_buffer_;
|
||||
asio::detail::array<char, buffer_size> put_buffer_;
|
||||
bool unbuffered_;
|
||||
asio::error_code ec_;
|
||||
std::size_t bytes_transferred_;
|
||||
TimerService* timer_service_;
|
||||
typename TimerService::implementation_type timer_implementation_;
|
||||
enum state { no_timer, timer_is_pending, timer_has_expired } timer_state_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
# undef ASIO_PRIVATE_CONNECT_DEF
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // ASIO_BASIC_SOCKET_STREAMBUF_HPP
|
|
@ -1,852 +0,0 @@
|
|||
//
|
||||
// basic_stream_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_STREAM_SOCKET_HPP
|
||||
#define ASIO_BASIC_STREAM_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/stream_socket_service.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides stream-oriented socket functionality.
|
||||
/**
|
||||
* The basic_stream_socket class template provides asynchronous and blocking
|
||||
* stream-oriented socket functionality.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Concepts:
|
||||
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
|
||||
*/
|
||||
template <typename Protocol,
|
||||
typename StreamSocketService = stream_socket_service<Protocol> >
|
||||
class basic_stream_socket
|
||||
: public basic_socket<Protocol, StreamSocketService>
|
||||
{
|
||||
public:
|
||||
/// (Deprecated: Use native_handle_type.) The native representation of a
|
||||
/// socket.
|
||||
typedef typename StreamSocketService::native_handle_type native_type;
|
||||
|
||||
/// The native representation of a socket.
|
||||
typedef typename StreamSocketService::native_handle_type native_handle_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// Construct a basic_stream_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a stream socket without opening it. The socket
|
||||
* needs to be opened and then connected or accepted before data can be sent
|
||||
* or received on it.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*/
|
||||
explicit basic_stream_socket(asio::io_service& io_service)
|
||||
: basic_socket<Protocol, StreamSocketService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_stream_socket.
|
||||
/**
|
||||
* This constructor creates and opens a stream socket. The socket needs to be
|
||||
* connected or accepted before data can be sent or received on it.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(asio::io_service& io_service,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol, StreamSocketService>(io_service, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_stream_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
* This constructor creates a stream socket and automatically opens it bound
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the stream
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(asio::io_service& io_service,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, StreamSocketService>(io_service, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_stream_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a stream socket object to hold an existing native
|
||||
* socket.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(asio::io_service& io_service,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol, StreamSocketService>(
|
||||
io_service, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_stream_socket from another.
|
||||
/**
|
||||
* This constructor moves a stream socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_stream_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_stream_socket(basic_stream_socket&& other)
|
||||
: basic_socket<Protocol, StreamSocketService>(
|
||||
ASIO_MOVE_CAST(basic_stream_socket)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_stream_socket from another.
|
||||
/**
|
||||
* This assignment operator moves a stream socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_stream_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_stream_socket& operator=(basic_stream_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol, StreamSocketService>::operator=(
|
||||
ASIO_MOVE_CAST(basic_stream_socket)(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Move-construct a basic_stream_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This constructor moves a stream socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_stream_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename StreamSocketService1>
|
||||
basic_stream_socket(
|
||||
basic_stream_socket<Protocol1, StreamSocketService1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol, StreamSocketService>(
|
||||
ASIO_MOVE_CAST2(basic_stream_socket<
|
||||
Protocol1, StreamSocketService1>)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_stream_socket from a socket of another protocol type.
|
||||
/**
|
||||
* This assignment operator moves a stream socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_stream_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename StreamSocketService1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_stream_socket>::type& operator=(
|
||||
basic_stream_socket<Protocol1, StreamSocketService1>&& other)
|
||||
{
|
||||
basic_socket<Protocol, StreamSocketService>::operator=(
|
||||
ASIO_MOVE_CAST2(basic_stream_socket<
|
||||
Protocol1, StreamSocketService1>)(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the stream socket. The function
|
||||
* call will block until one or more bytes of the data has been sent
|
||||
* successfully, or an until error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref write function if you need to ensure that all data
|
||||
* is written before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.send(asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the stream socket. The function
|
||||
* call will block until one or more bytes of the data has been sent
|
||||
* successfully, or an until error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref write function if you need to ensure that all data
|
||||
* is written before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.send(asio::buffer(data, size), 0);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the stream socket. The function
|
||||
* call will block until one or more bytes of the data has been sent
|
||||
* successfully, or an until error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref write function if you need to ensure that all data
|
||||
* is written before the blocking operation completes.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the stream socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
* data is written before the asynchronous operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_send(asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(
|
||||
this->get_implementation(), buffers, 0,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the stream socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
* data is written before the asynchronous operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_send(asio::buffer(data, size), 0, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(
|
||||
this->get_implementation(), buffers, flags,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
/**
|
||||
* This function is used to receive data on the stream socket. The function
|
||||
* call will block until one or more bytes of data has been received
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.receive(asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
/**
|
||||
* This function is used to receive data on the stream socket. The function
|
||||
* call will block until one or more bytes of data has been received
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.receive(asio::buffer(data, size), 0);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the stream socket. The function
|
||||
* call will block until one or more bytes of data has been received
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the stream
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref async_read function if you need to ensure
|
||||
* that the requested amount of data is received before the asynchronous
|
||||
* operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the stream
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref async_read function if you need to ensure
|
||||
* that the requested amount of data is received before the asynchronous
|
||||
* operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(asio::buffer(data, size), 0, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Write some data to the socket.
|
||||
/**
|
||||
* This function is used to write data to the stream socket. The function call
|
||||
* will block until one or more bytes of the data has been written
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the socket.
|
||||
*
|
||||
* @returns The number of bytes written.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The write_some operation may not transmit all of the data to the
|
||||
* peer. Consider using the @ref write function if you need to ensure that
|
||||
* all data is written before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.write_some(asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on writing multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "write_some");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Write some data to the socket.
|
||||
/**
|
||||
* This function is used to write data to the stream socket. The function call
|
||||
* will block until one or more bytes of the data has been written
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the socket.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes written. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The write_some operation may not transmit all of the data to the
|
||||
* peer. Consider using the @ref write function if you need to ensure that
|
||||
* all data is written before the blocking operation completes.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(this->get_implementation(), buffers, 0, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write.
|
||||
/**
|
||||
* This function is used to asynchronously write data to the stream socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the socket.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the write operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes written.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The write operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
* data is written before the asynchronous operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_write_some(asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on writing multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Read some data from the socket.
|
||||
/**
|
||||
* This function is used to read data from the stream socket. The function
|
||||
* call will block until one or more bytes of data has been read successfully,
|
||||
* or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
*
|
||||
* @returns The number of bytes read.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. An error code of
|
||||
* asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The read_some operation may not read all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that
|
||||
* the requested amount of data is read before the blocking operation
|
||||
* completes.
|
||||
*
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.read_some(asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on reading into multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
asio::detail::throw_error(ec, "read_some");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Read some data from the socket.
|
||||
/**
|
||||
* This function is used to read data from the stream socket. The function
|
||||
* call will block until one or more bytes of data has been read successfully,
|
||||
* or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes read. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The read_some operation may not read all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that
|
||||
* the requested amount of data is read before the blocking operation
|
||||
* completes.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read.
|
||||
/**
|
||||
* This function is used to asynchronously read data from the stream socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the read operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes read.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note The read operation may not read all of the requested number of bytes.
|
||||
* Consider using the @ref async_read function if you need to ensure that the
|
||||
* requested amount of data is read before the asynchronous operation
|
||||
* completes.
|
||||
*
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_read_some(asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on reading into multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BASIC_STREAM_SOCKET_HPP
|
|
@ -1,369 +0,0 @@
|
|||
//
|
||||
// basic_streambuf.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_STREAMBUF_HPP
|
||||
#define ASIO_BASIC_STREAMBUF_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <streambuf>
|
||||
#include <vector>
|
||||
#include "asio/basic_streambuf_fwd.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/limits.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/throw_exception.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Automatically resizable buffer class based on std::streambuf.
|
||||
/**
|
||||
* The @c basic_streambuf class is derived from @c std::streambuf to associate
|
||||
* the streambuf's input and output sequences with one or more character
|
||||
* arrays. These character arrays are internal to the @c basic_streambuf
|
||||
* object, but direct access to the array elements is provided to permit them
|
||||
* to be used efficiently with I/O operations. Characters written to the output
|
||||
* sequence of a @c basic_streambuf object are appended to the input sequence
|
||||
* of the same object.
|
||||
*
|
||||
* The @c basic_streambuf class's public interface is intended to permit the
|
||||
* following implementation strategies:
|
||||
*
|
||||
* @li A single contiguous character array, which is reallocated as necessary
|
||||
* to accommodate changes in the size of the character sequence. This is the
|
||||
* implementation approach currently used in Asio.
|
||||
*
|
||||
* @li A sequence of one or more character arrays, where each array is of the
|
||||
* same size. Additional character array objects are appended to the sequence
|
||||
* to accommodate changes in the size of the character sequence.
|
||||
*
|
||||
* @li A sequence of one or more character arrays of varying sizes. Additional
|
||||
* character array objects are appended to the sequence to accommodate changes
|
||||
* in the size of the character sequence.
|
||||
*
|
||||
* The constructor for basic_streambuf accepts a @c size_t argument specifying
|
||||
* the maximum of the sum of the sizes of the input sequence and output
|
||||
* sequence. During the lifetime of the @c basic_streambuf object, the following
|
||||
* invariant holds:
|
||||
* @code size() <= max_size()@endcode
|
||||
* Any member function that would, if successful, cause the invariant to be
|
||||
* violated shall throw an exception of class @c std::length_error.
|
||||
*
|
||||
* The constructor for @c basic_streambuf takes an Allocator argument. A copy
|
||||
* of this argument is used for any memory allocation performed, by the
|
||||
* constructor and by all member functions, during the lifetime of each @c
|
||||
* basic_streambuf object.
|
||||
*
|
||||
* @par Examples
|
||||
* Writing directly from an streambuf to a socket:
|
||||
* @code
|
||||
* asio::streambuf b;
|
||||
* std::ostream os(&b);
|
||||
* os << "Hello, World!\n";
|
||||
*
|
||||
* // try sending some data in input sequence
|
||||
* size_t n = sock.send(b.data());
|
||||
*
|
||||
* b.consume(n); // sent data is removed from input sequence
|
||||
* @endcode
|
||||
*
|
||||
* Reading from a socket directly into a streambuf:
|
||||
* @code
|
||||
* asio::streambuf b;
|
||||
*
|
||||
* // reserve 512 bytes in output sequence
|
||||
* asio::streambuf::mutable_buffers_type bufs = b.prepare(512);
|
||||
*
|
||||
* size_t n = sock.receive(bufs);
|
||||
*
|
||||
* // received data is "committed" from output sequence to input sequence
|
||||
* b.commit(n);
|
||||
*
|
||||
* std::istream is(&b);
|
||||
* std::string s;
|
||||
* is >> s;
|
||||
* @endcode
|
||||
*/
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
template <typename Allocator = std::allocator<char> >
|
||||
#else
|
||||
template <typename Allocator>
|
||||
#endif
|
||||
class basic_streambuf
|
||||
: public std::streambuf,
|
||||
private noncopyable
|
||||
{
|
||||
public:
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The type used to represent the input sequence as a list of buffers.
|
||||
typedef implementation_defined const_buffers_type;
|
||||
|
||||
/// The type used to represent the output sequence as a list of buffers.
|
||||
typedef implementation_defined mutable_buffers_type;
|
||||
#else
|
||||
typedef asio::const_buffers_1 const_buffers_type;
|
||||
typedef asio::mutable_buffers_1 mutable_buffers_type;
|
||||
#endif
|
||||
|
||||
/// Construct a basic_streambuf object.
|
||||
/**
|
||||
* Constructs a streambuf with the specified maximum size. The initial size
|
||||
* of the streambuf's input sequence is 0.
|
||||
*/
|
||||
explicit basic_streambuf(
|
||||
std::size_t maximum_size = (std::numeric_limits<std::size_t>::max)(),
|
||||
const Allocator& allocator = Allocator())
|
||||
: max_size_(maximum_size),
|
||||
buffer_(allocator)
|
||||
{
|
||||
std::size_t pend = (std::min<std::size_t>)(max_size_, buffer_delta);
|
||||
buffer_.resize((std::max<std::size_t>)(pend, 1));
|
||||
setg(&buffer_[0], &buffer_[0], &buffer_[0]);
|
||||
setp(&buffer_[0], &buffer_[0] + pend);
|
||||
}
|
||||
|
||||
/// Get the size of the input sequence.
|
||||
/**
|
||||
* @returns The size of the input sequence. The value is equal to that
|
||||
* calculated for @c s in the following code:
|
||||
* @code
|
||||
* size_t s = 0;
|
||||
* const_buffers_type bufs = data();
|
||||
* const_buffers_type::const_iterator i = bufs.begin();
|
||||
* while (i != bufs.end())
|
||||
* {
|
||||
* const_buffer buf(*i++);
|
||||
* s += buffer_size(buf);
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
std::size_t size() const
|
||||
{
|
||||
return pptr() - gptr();
|
||||
}
|
||||
|
||||
/// Get the maximum size of the basic_streambuf.
|
||||
/**
|
||||
* @returns The allowed maximum of the sum of the sizes of the input sequence
|
||||
* and output sequence.
|
||||
*/
|
||||
std::size_t max_size() const
|
||||
{
|
||||
return max_size_;
|
||||
}
|
||||
|
||||
/// Get a list of buffers that represents the input sequence.
|
||||
/**
|
||||
* @returns An object of type @c const_buffers_type that satisfies
|
||||
* ConstBufferSequence requirements, representing all character arrays in the
|
||||
* input sequence.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c basic_streambuf member
|
||||
* function that modifies the input sequence or output sequence.
|
||||
*/
|
||||
const_buffers_type data() const
|
||||
{
|
||||
return asio::buffer(asio::const_buffer(gptr(),
|
||||
(pptr() - gptr()) * sizeof(char_type)));
|
||||
}
|
||||
|
||||
/// Get a list of buffers that represents the output sequence, with the given
|
||||
/// size.
|
||||
/**
|
||||
* Ensures that the output sequence can accommodate @c n characters,
|
||||
* reallocating character array objects as necessary.
|
||||
*
|
||||
* @returns An object of type @c mutable_buffers_type that satisfies
|
||||
* MutableBufferSequence requirements, representing character array objects
|
||||
* at the start of the output sequence such that the sum of the buffer sizes
|
||||
* is @c n.
|
||||
*
|
||||
* @throws std::length_error If <tt>size() + n > max_size()</tt>.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c basic_streambuf member
|
||||
* function that modifies the input sequence or output sequence.
|
||||
*/
|
||||
mutable_buffers_type prepare(std::size_t n)
|
||||
{
|
||||
reserve(n);
|
||||
return asio::buffer(asio::mutable_buffer(
|
||||
pptr(), n * sizeof(char_type)));
|
||||
}
|
||||
|
||||
/// Move characters from the output sequence to the input sequence.
|
||||
/**
|
||||
* Appends @c n characters from the start of the output sequence to the input
|
||||
* sequence. The beginning of the output sequence is advanced by @c n
|
||||
* characters.
|
||||
*
|
||||
* Requires a preceding call <tt>prepare(x)</tt> where <tt>x >= n</tt>, and
|
||||
* no intervening operations that modify the input or output sequence.
|
||||
*
|
||||
* @note If @c n is greater than the size of the output sequence, the entire
|
||||
* output sequence is moved to the input sequence and no error is issued.
|
||||
*/
|
||||
void commit(std::size_t n)
|
||||
{
|
||||
if (pptr() + n > epptr())
|
||||
n = epptr() - pptr();
|
||||
pbump(static_cast<int>(n));
|
||||
setg(eback(), gptr(), pptr());
|
||||
}
|
||||
|
||||
/// Remove characters from the input sequence.
|
||||
/**
|
||||
* Removes @c n characters from the beginning of the input sequence.
|
||||
*
|
||||
* @note If @c n is greater than the size of the input sequence, the entire
|
||||
* input sequence is consumed and no error is issued.
|
||||
*/
|
||||
void consume(std::size_t n)
|
||||
{
|
||||
if (egptr() < pptr())
|
||||
setg(&buffer_[0], gptr(), pptr());
|
||||
if (gptr() + n > pptr())
|
||||
n = pptr() - gptr();
|
||||
gbump(static_cast<int>(n));
|
||||
}
|
||||
|
||||
protected:
|
||||
enum { buffer_delta = 128 };
|
||||
|
||||
/// Override std::streambuf behaviour.
|
||||
/**
|
||||
* Behaves according to the specification of @c std::streambuf::underflow().
|
||||
*/
|
||||
int_type underflow()
|
||||
{
|
||||
if (gptr() < pptr())
|
||||
{
|
||||
setg(&buffer_[0], gptr(), pptr());
|
||||
return traits_type::to_int_type(*gptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
return traits_type::eof();
|
||||
}
|
||||
}
|
||||
|
||||
/// Override std::streambuf behaviour.
|
||||
/**
|
||||
* Behaves according to the specification of @c std::streambuf::overflow(),
|
||||
* with the specialisation that @c std::length_error is thrown if appending
|
||||
* the character to the input sequence would require the condition
|
||||
* <tt>size() > max_size()</tt> to be true.
|
||||
*/
|
||||
int_type overflow(int_type c)
|
||||
{
|
||||
if (!traits_type::eq_int_type(c, traits_type::eof()))
|
||||
{
|
||||
if (pptr() == epptr())
|
||||
{
|
||||
std::size_t buffer_size = pptr() - gptr();
|
||||
if (buffer_size < max_size_ && max_size_ - buffer_size < buffer_delta)
|
||||
{
|
||||
reserve(max_size_ - buffer_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
reserve(buffer_delta);
|
||||
}
|
||||
}
|
||||
|
||||
*pptr() = traits_type::to_char_type(c);
|
||||
pbump(1);
|
||||
return c;
|
||||
}
|
||||
|
||||
return traits_type::not_eof(c);
|
||||
}
|
||||
|
||||
void reserve(std::size_t n)
|
||||
{
|
||||
// Get current stream positions as offsets.
|
||||
std::size_t gnext = gptr() - &buffer_[0];
|
||||
std::size_t pnext = pptr() - &buffer_[0];
|
||||
std::size_t pend = epptr() - &buffer_[0];
|
||||
|
||||
// Check if there is already enough space in the put area.
|
||||
if (n <= pend - pnext)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Shift existing contents of get area to start of buffer.
|
||||
if (gnext > 0)
|
||||
{
|
||||
pnext -= gnext;
|
||||
std::memmove(&buffer_[0], &buffer_[0] + gnext, pnext);
|
||||
}
|
||||
|
||||
// Ensure buffer is large enough to hold at least the specified size.
|
||||
if (n > pend - pnext)
|
||||
{
|
||||
if (n <= max_size_ && pnext <= max_size_ - n)
|
||||
{
|
||||
pend = pnext + n;
|
||||
buffer_.resize((std::max<std::size_t>)(pend, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::length_error ex("asio::streambuf too long");
|
||||
asio::detail::throw_exception(ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Update stream positions.
|
||||
setg(&buffer_[0], &buffer_[0], &buffer_[0] + pnext);
|
||||
setp(&buffer_[0] + pnext, &buffer_[0] + pend);
|
||||
}
|
||||
|
||||
private:
|
||||
std::size_t max_size_;
|
||||
std::vector<char_type, Allocator> buffer_;
|
||||
|
||||
// Helper function to get the preferred size for reading data.
|
||||
friend std::size_t read_size_helper(
|
||||
basic_streambuf& sb, std::size_t max_size)
|
||||
{
|
||||
return std::min<std::size_t>(
|
||||
std::max<std::size_t>(512, sb.buffer_.capacity() - sb.size()),
|
||||
std::min<std::size_t>(max_size, sb.max_size() - sb.size()));
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function to get the preferred size for reading data. Used for any
|
||||
// user-provided specialisations of basic_streambuf.
|
||||
template <typename Allocator>
|
||||
inline std::size_t read_size_helper(
|
||||
basic_streambuf<Allocator>& sb, std::size_t max_size)
|
||||
{
|
||||
return std::min<std::size_t>(512,
|
||||
std::min<std::size_t>(max_size, sb.max_size() - sb.size()));
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // ASIO_BASIC_STREAMBUF_HPP
|
|
@ -1,33 +0,0 @@
|
|||
//
|
||||
// basic_streambuf_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_STREAMBUF_FWD_HPP
|
||||
#define ASIO_BASIC_STREAMBUF_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename Allocator = std::allocator<char> >
|
||||
class basic_streambuf;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // ASIO_BASIC_STREAMBUF_FWD_HPP
|
|
@ -1,519 +0,0 @@
|
|||
//
|
||||
// basic_waitable_timer.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BASIC_WAITABLE_TIMER_HPP
|
||||
#define ASIO_BASIC_WAITABLE_TIMER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/basic_io_object.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/wait_traits.hpp"
|
||||
#include "asio/waitable_timer_service.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Provides waitable timer functionality.
|
||||
/**
|
||||
* The basic_waitable_timer class template provides the ability to perform a
|
||||
* blocking or asynchronous wait for a timer to expire.
|
||||
*
|
||||
* A waitable timer is always in one of two states: "expired" or "not expired".
|
||||
* If the wait() or async_wait() function is called on an expired timer, the
|
||||
* wait operation will complete immediately.
|
||||
*
|
||||
* Most applications will use one of the asio::steady_timer,
|
||||
* asio::system_timer or asio::high_resolution_timer typedefs.
|
||||
*
|
||||
* @note This waitable timer functionality is for use with the C++11 standard
|
||||
* library's @c <chrono> facility, or with the Boost.Chrono library.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Examples
|
||||
* Performing a blocking wait (C++11):
|
||||
* @code
|
||||
* // Construct a timer without setting an expiry time.
|
||||
* asio::steady_timer timer(io_service);
|
||||
*
|
||||
* // Set an expiry time relative to now.
|
||||
* timer.expires_from_now(std::chrono::seconds(5));
|
||||
*
|
||||
* // Wait for the timer to expire.
|
||||
* timer.wait();
|
||||
* @endcode
|
||||
*
|
||||
* @par
|
||||
* Performing an asynchronous wait (C++11):
|
||||
* @code
|
||||
* void handler(const asio::error_code& error)
|
||||
* {
|
||||
* if (!error)
|
||||
* {
|
||||
* // Timer expired.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* // Construct a timer with an absolute expiry time.
|
||||
* asio::steady_timer timer(io_service,
|
||||
* std::chrono::steady_clock::now() + std::chrono::seconds(60));
|
||||
*
|
||||
* // Start an asynchronous wait.
|
||||
* timer.async_wait(handler);
|
||||
* @endcode
|
||||
*
|
||||
* @par Changing an active waitable timer's expiry time
|
||||
*
|
||||
* Changing the expiry time of a timer while there are pending asynchronous
|
||||
* waits causes those wait operations to be cancelled. To ensure that the action
|
||||
* associated with the timer is performed only once, use something like this:
|
||||
* used:
|
||||
*
|
||||
* @code
|
||||
* void on_some_event()
|
||||
* {
|
||||
* if (my_timer.expires_from_now(seconds(5)) > 0)
|
||||
* {
|
||||
* // We managed to cancel the timer. Start new asynchronous wait.
|
||||
* my_timer.async_wait(on_timeout);
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // Too late, timer has already expired!
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* void on_timeout(const asio::error_code& e)
|
||||
* {
|
||||
* if (e != asio::error::operation_aborted)
|
||||
* {
|
||||
* // Timer was not cancelled, take necessary action.
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @li The asio::basic_waitable_timer::expires_from_now() function
|
||||
* cancels any pending asynchronous waits, and returns the number of
|
||||
* asynchronous waits that were cancelled. If it returns 0 then you were too
|
||||
* late and the wait handler has already been executed, or will soon be
|
||||
* executed. If it returns 1 then the wait handler was successfully cancelled.
|
||||
*
|
||||
* @li If a wait handler is cancelled, the asio::error_code passed to
|
||||
* it contains the value asio::error::operation_aborted.
|
||||
*/
|
||||
template <typename Clock,
|
||||
typename WaitTraits = asio::wait_traits<Clock>,
|
||||
typename WaitableTimerService = waitable_timer_service<Clock, WaitTraits> >
|
||||
class basic_waitable_timer
|
||||
: public basic_io_object<WaitableTimerService>
|
||||
{
|
||||
public:
|
||||
/// The clock type.
|
||||
typedef Clock clock_type;
|
||||
|
||||
/// The duration type of the clock.
|
||||
typedef typename clock_type::duration duration;
|
||||
|
||||
/// The time point type of the clock.
|
||||
typedef typename clock_type::time_point time_point;
|
||||
|
||||
/// The wait traits type.
|
||||
typedef WaitTraits traits_type;
|
||||
|
||||
/// Constructor.
|
||||
/**
|
||||
* This constructor creates a timer without setting an expiry time. The
|
||||
* expires_at() or expires_from_now() functions must be called to set an
|
||||
* expiry time before the timer can be waited on.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*/
|
||||
explicit basic_waitable_timer(asio::io_service& io_service)
|
||||
: basic_io_object<WaitableTimerService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time as an absolute time.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, expressed
|
||||
* as an absolute time.
|
||||
*/
|
||||
basic_waitable_timer(asio::io_service& io_service,
|
||||
const time_point& expiry_time)
|
||||
: basic_io_object<WaitableTimerService>(io_service)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.expires_at(this->implementation, expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time relative to now.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, relative to
|
||||
* now.
|
||||
*/
|
||||
basic_waitable_timer(asio::io_service& io_service,
|
||||
const duration& expiry_time)
|
||||
: basic_io_object<WaitableTimerService>(io_service)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.expires_from_now(this->implementation, expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_from_now");
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->service.cancel(this->implementation, ec);
|
||||
asio::detail::throw_error(ec, "cancel");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel(asio::error_code& ec)
|
||||
{
|
||||
return this->service.cancel(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one()
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->service.cancel_one(this->implementation, ec);
|
||||
asio::detail::throw_error(ec, "cancel_one");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one(asio::error_code& ec)
|
||||
{
|
||||
return this->service.cancel_one(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
time_point expires_at() const
|
||||
{
|
||||
return this->service.expires_at(this->implementation);
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_point& expiry_time)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->service.expires_at(
|
||||
this->implementation, expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_at");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_point& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->service.expires_at(this->implementation, expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
duration expires_from_now() const
|
||||
{
|
||||
return this->service.expires_from_now(this->implementation);
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration& expiry_time)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t s = this->service.expires_from_now(
|
||||
this->implementation, expiry_time, ec);
|
||||
asio::detail::throw_error(ec, "expires_from_now");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration& expiry_time,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return this->service.expires_from_now(
|
||||
this->implementation, expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure.
|
||||
*/
|
||||
void wait()
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->service.wait(this->implementation, ec);
|
||||
asio::detail::throw_error(ec, "wait");
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
void wait(asio::error_code& ec)
|
||||
{
|
||||
this->service.wait(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous wait on the timer.
|
||||
/**
|
||||
* This function may be used to initiate an asynchronous wait against the
|
||||
* timer. It always returns immediately.
|
||||
*
|
||||
* For each call to async_wait(), the supplied handler will be called exactly
|
||||
* once. The handler will be called when:
|
||||
*
|
||||
* @li The timer has expired.
|
||||
*
|
||||
* @li The timer was cancelled, in which case the handler is passed the error
|
||||
* code asio::error::operation_aborted.
|
||||
*
|
||||
* @param handler The handler to be called when the timer expires. Copies
|
||||
* will be made of the handler as required. The function signature of the
|
||||
* handler must be:
|
||||
* @code void handler(
|
||||
* const asio::error_code& error // Result of operation.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*/
|
||||
template <typename WaitHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WaitHandler,
|
||||
void (asio::error_code))
|
||||
async_wait(ASIO_MOVE_ARG(WaitHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WaitHandler.
|
||||
ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
|
||||
|
||||
return this->service.async_wait(this->implementation,
|
||||
ASIO_MOVE_CAST(WaitHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BASIC_WAITABLE_TIMER_HPP
|
File diff suppressed because it is too large
Load Diff
|
@ -1,244 +0,0 @@
|
|||
//
|
||||
// buffered_read_stream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BUFFERED_READ_STREAM_HPP
|
||||
#define ASIO_BUFFERED_READ_STREAM_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/buffered_read_stream_fwd.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/bind_handler.hpp"
|
||||
#include "asio/detail/buffer_resize_guard.hpp"
|
||||
#include "asio/detail/buffered_stream_storage.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Adds buffering to the read-related operations of a stream.
|
||||
/**
|
||||
* The buffered_read_stream class template can be used to add buffering to the
|
||||
* synchronous and asynchronous read operations of a stream.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Concepts:
|
||||
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
|
||||
*/
|
||||
template <typename Stream>
|
||||
class buffered_read_stream
|
||||
: private noncopyable
|
||||
{
|
||||
public:
|
||||
/// The type of the next layer.
|
||||
typedef typename remove_reference<Stream>::type next_layer_type;
|
||||
|
||||
/// The type of the lowest layer.
|
||||
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The default buffer size.
|
||||
static const std::size_t default_buffer_size = implementation_defined;
|
||||
#else
|
||||
ASIO_STATIC_CONSTANT(std::size_t, default_buffer_size = 1024);
|
||||
#endif
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
explicit buffered_read_stream(Arg& a)
|
||||
: next_layer_(a),
|
||||
storage_(default_buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
buffered_read_stream(Arg& a, std::size_t buffer_size)
|
||||
: next_layer_(a),
|
||||
storage_(buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Get a reference to the next layer.
|
||||
next_layer_type& next_layer()
|
||||
{
|
||||
return next_layer_;
|
||||
}
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return next_layer_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get a const reference to the lowest layer.
|
||||
const lowest_layer_type& lowest_layer() const
|
||||
{
|
||||
return next_layer_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get the io_service associated with the object.
|
||||
asio::io_service& get_io_service()
|
||||
{
|
||||
return next_layer_.get_io_service();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
void close()
|
||||
{
|
||||
next_layer_.close();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
asio::error_code close(asio::error_code& ec)
|
||||
{
|
||||
return next_layer_.close(ec);
|
||||
}
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written.
|
||||
/// Throws an exception on failure.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
return next_layer_.write_some(buffers);
|
||||
}
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written,
|
||||
/// or 0 if an error occurred.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return next_layer_.write_some(buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write. The data being written must be valid for the
|
||||
/// lifetime of the asynchronous operation.
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
detail::async_result_init<
|
||||
WriteHandler, void (asio::error_code, std::size_t)> init(
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
|
||||
next_layer_.async_write_some(buffers,
|
||||
ASIO_MOVE_CAST(ASIO_HANDLER_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t)))(init.handler));
|
||||
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
/// Fill the buffer with some data. Returns the number of bytes placed in the
|
||||
/// buffer as a result of the operation. Throws an exception on failure.
|
||||
std::size_t fill();
|
||||
|
||||
/// Fill the buffer with some data. Returns the number of bytes placed in the
|
||||
/// buffer as a result of the operation, or 0 if an error occurred.
|
||||
std::size_t fill(asio::error_code& ec);
|
||||
|
||||
/// Start an asynchronous fill.
|
||||
template <typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_fill(ASIO_MOVE_ARG(ReadHandler) handler);
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read. Throws
|
||||
/// an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers);
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read or 0 if
|
||||
/// an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec);
|
||||
|
||||
/// Start an asynchronous read. The buffer into which the data will be read
|
||||
/// must be valid for the lifetime of the asynchronous operation.
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler);
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read.
|
||||
/// Throws an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers);
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read,
|
||||
/// or 0 if an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec);
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail()
|
||||
{
|
||||
return storage_.size();
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail(asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
return storage_.size();
|
||||
}
|
||||
|
||||
private:
|
||||
/// Copy data out of the internal buffer to the specified target buffer.
|
||||
/// Returns the number of bytes copied.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t copy(const MutableBufferSequence& buffers)
|
||||
{
|
||||
std::size_t bytes_copied = asio::buffer_copy(
|
||||
buffers, storage_.data(), storage_.size());
|
||||
storage_.consume(bytes_copied);
|
||||
return bytes_copied;
|
||||
}
|
||||
|
||||
/// Copy data from the internal buffer to the specified target buffer, without
|
||||
/// removing the data from the internal buffer. Returns the number of bytes
|
||||
/// copied.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek_copy(const MutableBufferSequence& buffers)
|
||||
{
|
||||
return asio::buffer_copy(buffers, storage_.data(), storage_.size());
|
||||
}
|
||||
|
||||
/// The next layer.
|
||||
Stream next_layer_;
|
||||
|
||||
// The data in the buffer.
|
||||
detail::buffered_stream_storage storage_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/impl/buffered_read_stream.hpp"
|
||||
|
||||
#endif // ASIO_BUFFERED_READ_STREAM_HPP
|
|
@ -1,25 +0,0 @@
|
|||
//
|
||||
// buffered_read_stream_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BUFFERED_READ_STREAM_FWD_HPP
|
||||
#define ASIO_BUFFERED_READ_STREAM_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename Stream>
|
||||
class buffered_read_stream;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_BUFFERED_READ_STREAM_FWD_HPP
|
|
@ -1,258 +0,0 @@
|
|||
//
|
||||
// buffered_stream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BUFFERED_STREAM_HPP
|
||||
#define ASIO_BUFFERED_STREAM_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/buffered_read_stream.hpp"
|
||||
#include "asio/buffered_write_stream.hpp"
|
||||
#include "asio/buffered_stream_fwd.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Adds buffering to the read- and write-related operations of a stream.
|
||||
/**
|
||||
* The buffered_stream class template can be used to add buffering to the
|
||||
* synchronous and asynchronous read and write operations of a stream.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Concepts:
|
||||
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
|
||||
*/
|
||||
template <typename Stream>
|
||||
class buffered_stream
|
||||
: private noncopyable
|
||||
{
|
||||
public:
|
||||
/// The type of the next layer.
|
||||
typedef typename remove_reference<Stream>::type next_layer_type;
|
||||
|
||||
/// The type of the lowest layer.
|
||||
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
explicit buffered_stream(Arg& a)
|
||||
: inner_stream_impl_(a),
|
||||
stream_impl_(inner_stream_impl_)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
explicit buffered_stream(Arg& a, std::size_t read_buffer_size,
|
||||
std::size_t write_buffer_size)
|
||||
: inner_stream_impl_(a, write_buffer_size),
|
||||
stream_impl_(inner_stream_impl_, read_buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Get a reference to the next layer.
|
||||
next_layer_type& next_layer()
|
||||
{
|
||||
return stream_impl_.next_layer().next_layer();
|
||||
}
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return stream_impl_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get a const reference to the lowest layer.
|
||||
const lowest_layer_type& lowest_layer() const
|
||||
{
|
||||
return stream_impl_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get the io_service associated with the object.
|
||||
asio::io_service& get_io_service()
|
||||
{
|
||||
return stream_impl_.get_io_service();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
void close()
|
||||
{
|
||||
stream_impl_.close();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
asio::error_code close(asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.close(ec);
|
||||
}
|
||||
|
||||
/// Flush all data from the buffer to the next layer. Returns the number of
|
||||
/// bytes written to the next layer on the last write operation. Throws an
|
||||
/// exception on failure.
|
||||
std::size_t flush()
|
||||
{
|
||||
return stream_impl_.next_layer().flush();
|
||||
}
|
||||
|
||||
/// Flush all data from the buffer to the next layer. Returns the number of
|
||||
/// bytes written to the next layer on the last write operation, or 0 if an
|
||||
/// error occurred.
|
||||
std::size_t flush(asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.next_layer().flush(ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous flush.
|
||||
template <typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_flush(ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
return stream_impl_.next_layer().async_flush(
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written.
|
||||
/// Throws an exception on failure.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
return stream_impl_.write_some(buffers);
|
||||
}
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written,
|
||||
/// or 0 if an error occurred.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.write_some(buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write. The data being written must be valid for the
|
||||
/// lifetime of the asynchronous operation.
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
return stream_impl_.async_write_some(buffers,
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Fill the buffer with some data. Returns the number of bytes placed in the
|
||||
/// buffer as a result of the operation. Throws an exception on failure.
|
||||
std::size_t fill()
|
||||
{
|
||||
return stream_impl_.fill();
|
||||
}
|
||||
|
||||
/// Fill the buffer with some data. Returns the number of bytes placed in the
|
||||
/// buffer as a result of the operation, or 0 if an error occurred.
|
||||
std::size_t fill(asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.fill(ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous fill.
|
||||
template <typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_fill(ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
return stream_impl_.async_fill(ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read. Throws
|
||||
/// an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
return stream_impl_.read_some(buffers);
|
||||
}
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read or 0 if
|
||||
/// an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.read_some(buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read. The buffer into which the data will be read
|
||||
/// must be valid for the lifetime of the asynchronous operation.
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
return stream_impl_.async_read_some(buffers,
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read.
|
||||
/// Throws an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers)
|
||||
{
|
||||
return stream_impl_.peek(buffers);
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read,
|
||||
/// or 0 if an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.peek(buffers, ec);
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail()
|
||||
{
|
||||
return stream_impl_.in_avail();
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail(asio::error_code& ec)
|
||||
{
|
||||
return stream_impl_.in_avail(ec);
|
||||
}
|
||||
|
||||
private:
|
||||
// The buffered write stream.
|
||||
typedef buffered_write_stream<Stream> write_stream_type;
|
||||
write_stream_type inner_stream_impl_;
|
||||
|
||||
// The buffered read stream.
|
||||
typedef buffered_read_stream<write_stream_type&> read_stream_type;
|
||||
read_stream_type stream_impl_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BUFFERED_STREAM_HPP
|
|
@ -1,25 +0,0 @@
|
|||
//
|
||||
// buffered_stream_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BUFFERED_STREAM_FWD_HPP
|
||||
#define ASIO_BUFFERED_STREAM_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename Stream>
|
||||
class buffered_stream;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_BUFFERED_STREAM_FWD_HPP
|
|
@ -1,236 +0,0 @@
|
|||
//
|
||||
// buffered_write_stream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BUFFERED_WRITE_STREAM_HPP
|
||||
#define ASIO_BUFFERED_WRITE_STREAM_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/buffered_write_stream_fwd.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/completion_condition.hpp"
|
||||
#include "asio/detail/bind_handler.hpp"
|
||||
#include "asio/detail/buffered_stream_storage.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
#include "asio/write.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Adds buffering to the write-related operations of a stream.
|
||||
/**
|
||||
* The buffered_write_stream class template can be used to add buffering to the
|
||||
* synchronous and asynchronous write operations of a stream.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Concepts:
|
||||
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
|
||||
*/
|
||||
template <typename Stream>
|
||||
class buffered_write_stream
|
||||
: private noncopyable
|
||||
{
|
||||
public:
|
||||
/// The type of the next layer.
|
||||
typedef typename remove_reference<Stream>::type next_layer_type;
|
||||
|
||||
/// The type of the lowest layer.
|
||||
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The default buffer size.
|
||||
static const std::size_t default_buffer_size = implementation_defined;
|
||||
#else
|
||||
ASIO_STATIC_CONSTANT(std::size_t, default_buffer_size = 1024);
|
||||
#endif
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
explicit buffered_write_stream(Arg& a)
|
||||
: next_layer_(a),
|
||||
storage_(default_buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct, passing the specified argument to initialise the next layer.
|
||||
template <typename Arg>
|
||||
buffered_write_stream(Arg& a, std::size_t buffer_size)
|
||||
: next_layer_(a),
|
||||
storage_(buffer_size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Get a reference to the next layer.
|
||||
next_layer_type& next_layer()
|
||||
{
|
||||
return next_layer_;
|
||||
}
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return next_layer_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get a const reference to the lowest layer.
|
||||
const lowest_layer_type& lowest_layer() const
|
||||
{
|
||||
return next_layer_.lowest_layer();
|
||||
}
|
||||
|
||||
/// Get the io_service associated with the object.
|
||||
asio::io_service& get_io_service()
|
||||
{
|
||||
return next_layer_.get_io_service();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
void close()
|
||||
{
|
||||
next_layer_.close();
|
||||
}
|
||||
|
||||
/// Close the stream.
|
||||
asio::error_code close(asio::error_code& ec)
|
||||
{
|
||||
return next_layer_.close(ec);
|
||||
}
|
||||
|
||||
/// Flush all data from the buffer to the next layer. Returns the number of
|
||||
/// bytes written to the next layer on the last write operation. Throws an
|
||||
/// exception on failure.
|
||||
std::size_t flush();
|
||||
|
||||
/// Flush all data from the buffer to the next layer. Returns the number of
|
||||
/// bytes written to the next layer on the last write operation, or 0 if an
|
||||
/// error occurred.
|
||||
std::size_t flush(asio::error_code& ec);
|
||||
|
||||
/// Start an asynchronous flush.
|
||||
template <typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_flush(ASIO_MOVE_ARG(WriteHandler) handler);
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written.
|
||||
/// Throws an exception on failure.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers);
|
||||
|
||||
/// Write the given data to the stream. Returns the number of bytes written,
|
||||
/// or 0 if an error occurred and the error handler did not throw.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
asio::error_code& ec);
|
||||
|
||||
/// Start an asynchronous write. The data being written must be valid for the
|
||||
/// lifetime of the asynchronous operation.
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler);
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read. Throws
|
||||
/// an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
return next_layer_.read_some(buffers);
|
||||
}
|
||||
|
||||
/// Read some data from the stream. Returns the number of bytes read or 0 if
|
||||
/// an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return next_layer_.read_some(buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read. The buffer into which the data will be read
|
||||
/// must be valid for the lifetime of the asynchronous operation.
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
detail::async_result_init<
|
||||
ReadHandler, void (asio::error_code, std::size_t)> init(
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
|
||||
next_layer_.async_read_some(buffers,
|
||||
ASIO_MOVE_CAST(ASIO_HANDLER_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t)))(init.handler));
|
||||
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read.
|
||||
/// Throws an exception on failure.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers)
|
||||
{
|
||||
return next_layer_.peek(buffers);
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream. Returns the number of bytes read,
|
||||
/// or 0 if an error occurred.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t peek(const MutableBufferSequence& buffers,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return next_layer_.peek(buffers, ec);
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail()
|
||||
{
|
||||
return next_layer_.in_avail();
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
std::size_t in_avail(asio::error_code& ec)
|
||||
{
|
||||
return next_layer_.in_avail(ec);
|
||||
}
|
||||
|
||||
private:
|
||||
/// Copy data into the internal buffer from the specified source buffer.
|
||||
/// Returns the number of bytes copied.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t copy(const ConstBufferSequence& buffers);
|
||||
|
||||
/// The next layer.
|
||||
Stream next_layer_;
|
||||
|
||||
// The data in the buffer.
|
||||
detail::buffered_stream_storage storage_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/impl/buffered_write_stream.hpp"
|
||||
|
||||
#endif // ASIO_BUFFERED_WRITE_STREAM_HPP
|
|
@ -1,25 +0,0 @@
|
|||
//
|
||||
// buffered_write_stream_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BUFFERED_WRITE_STREAM_FWD_HPP
|
||||
#define ASIO_BUFFERED_WRITE_STREAM_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename Stream>
|
||||
class buffered_write_stream;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_BUFFERED_WRITE_STREAM_FWD_HPP
|
|
@ -1,481 +0,0 @@
|
|||
//
|
||||
// buffers_iterator.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_BUFFERS_ITERATOR_HPP
|
||||
#define ASIO_BUFFERS_ITERATOR_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/assert.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <bool IsMutable>
|
||||
struct buffers_iterator_types_helper;
|
||||
|
||||
template <>
|
||||
struct buffers_iterator_types_helper<false>
|
||||
{
|
||||
typedef const_buffer buffer_type;
|
||||
template <typename ByteType>
|
||||
struct byte_type
|
||||
{
|
||||
typedef typename add_const<ByteType>::type type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct buffers_iterator_types_helper<true>
|
||||
{
|
||||
typedef mutable_buffer buffer_type;
|
||||
template <typename ByteType>
|
||||
struct byte_type
|
||||
{
|
||||
typedef ByteType type;
|
||||
};
|
||||
};
|
||||
|
||||
template <typename BufferSequence, typename ByteType>
|
||||
struct buffers_iterator_types
|
||||
{
|
||||
enum
|
||||
{
|
||||
is_mutable = is_convertible<
|
||||
typename BufferSequence::value_type,
|
||||
mutable_buffer>::value
|
||||
};
|
||||
typedef buffers_iterator_types_helper<is_mutable> helper;
|
||||
typedef typename helper::buffer_type buffer_type;
|
||||
typedef typename helper::template byte_type<ByteType>::type byte_type;
|
||||
};
|
||||
}
|
||||
|
||||
/// A random access iterator over the bytes in a buffer sequence.
|
||||
template <typename BufferSequence, typename ByteType = char>
|
||||
class buffers_iterator
|
||||
{
|
||||
private:
|
||||
typedef typename detail::buffers_iterator_types<
|
||||
BufferSequence, ByteType>::buffer_type buffer_type;
|
||||
|
||||
public:
|
||||
/// The type used for the distance between two iterators.
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
/// The type of the value pointed to by the iterator.
|
||||
typedef ByteType value_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The type of the result of applying operator->() to the iterator.
|
||||
/**
|
||||
* If the buffer sequence stores buffer objects that are convertible to
|
||||
* mutable_buffer, this is a pointer to a non-const ByteType. Otherwise, a
|
||||
* pointer to a const ByteType.
|
||||
*/
|
||||
typedef const_or_non_const_ByteType* pointer;
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
typedef typename detail::buffers_iterator_types<
|
||||
BufferSequence, ByteType>::byte_type* pointer;
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The type of the result of applying operator*() to the iterator.
|
||||
/**
|
||||
* If the buffer sequence stores buffer objects that are convertible to
|
||||
* mutable_buffer, this is a reference to a non-const ByteType. Otherwise, a
|
||||
* reference to a const ByteType.
|
||||
*/
|
||||
typedef const_or_non_const_ByteType& reference;
|
||||
#else // defined(GENERATING_DOCUMENTATION)
|
||||
typedef typename detail::buffers_iterator_types<
|
||||
BufferSequence, ByteType>::byte_type& reference;
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// The iterator category.
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
|
||||
/// Default constructor. Creates an iterator in an undefined state.
|
||||
buffers_iterator()
|
||||
: current_buffer_(),
|
||||
current_buffer_position_(0),
|
||||
begin_(),
|
||||
current_(),
|
||||
end_(),
|
||||
position_(0)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct an iterator representing the beginning of the buffers' data.
|
||||
static buffers_iterator begin(const BufferSequence& buffers)
|
||||
#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3)
|
||||
__attribute__ ((__noinline__))
|
||||
#endif // defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3)
|
||||
{
|
||||
buffers_iterator new_iter;
|
||||
new_iter.begin_ = buffers.begin();
|
||||
new_iter.current_ = buffers.begin();
|
||||
new_iter.end_ = buffers.end();
|
||||
while (new_iter.current_ != new_iter.end_)
|
||||
{
|
||||
new_iter.current_buffer_ = *new_iter.current_;
|
||||
if (asio::buffer_size(new_iter.current_buffer_) > 0)
|
||||
break;
|
||||
++new_iter.current_;
|
||||
}
|
||||
return new_iter;
|
||||
}
|
||||
|
||||
/// Construct an iterator representing the end of the buffers' data.
|
||||
static buffers_iterator end(const BufferSequence& buffers)
|
||||
#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3)
|
||||
__attribute__ ((__noinline__))
|
||||
#endif // defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3)
|
||||
{
|
||||
buffers_iterator new_iter;
|
||||
new_iter.begin_ = buffers.begin();
|
||||
new_iter.current_ = buffers.begin();
|
||||
new_iter.end_ = buffers.end();
|
||||
while (new_iter.current_ != new_iter.end_)
|
||||
{
|
||||
buffer_type buffer = *new_iter.current_;
|
||||
new_iter.position_ += asio::buffer_size(buffer);
|
||||
++new_iter.current_;
|
||||
}
|
||||
return new_iter;
|
||||
}
|
||||
|
||||
/// Dereference an iterator.
|
||||
reference operator*() const
|
||||
{
|
||||
return dereference();
|
||||
}
|
||||
|
||||
/// Dereference an iterator.
|
||||
pointer operator->() const
|
||||
{
|
||||
return &dereference();
|
||||
}
|
||||
|
||||
/// Access an individual element.
|
||||
reference operator[](std::ptrdiff_t difference) const
|
||||
{
|
||||
buffers_iterator tmp(*this);
|
||||
tmp.advance(difference);
|
||||
return *tmp;
|
||||
}
|
||||
|
||||
/// Increment operator (prefix).
|
||||
buffers_iterator& operator++()
|
||||
{
|
||||
increment();
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Increment operator (postfix).
|
||||
buffers_iterator operator++(int)
|
||||
{
|
||||
buffers_iterator tmp(*this);
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Decrement operator (prefix).
|
||||
buffers_iterator& operator--()
|
||||
{
|
||||
decrement();
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Decrement operator (postfix).
|
||||
buffers_iterator operator--(int)
|
||||
{
|
||||
buffers_iterator tmp(*this);
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Addition operator.
|
||||
buffers_iterator& operator+=(std::ptrdiff_t difference)
|
||||
{
|
||||
advance(difference);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Subtraction operator.
|
||||
buffers_iterator& operator-=(std::ptrdiff_t difference)
|
||||
{
|
||||
advance(-difference);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Addition operator.
|
||||
friend buffers_iterator operator+(const buffers_iterator& iter,
|
||||
std::ptrdiff_t difference)
|
||||
{
|
||||
buffers_iterator tmp(iter);
|
||||
tmp.advance(difference);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Addition operator.
|
||||
friend buffers_iterator operator+(std::ptrdiff_t difference,
|
||||
const buffers_iterator& iter)
|
||||
{
|
||||
buffers_iterator tmp(iter);
|
||||
tmp.advance(difference);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Subtraction operator.
|
||||
friend buffers_iterator operator-(const buffers_iterator& iter,
|
||||
std::ptrdiff_t difference)
|
||||
{
|
||||
buffers_iterator tmp(iter);
|
||||
tmp.advance(-difference);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Subtraction operator.
|
||||
friend std::ptrdiff_t operator-(const buffers_iterator& a,
|
||||
const buffers_iterator& b)
|
||||
{
|
||||
return b.distance_to(a);
|
||||
}
|
||||
|
||||
/// Test two iterators for equality.
|
||||
friend bool operator==(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return a.equal(b);
|
||||
}
|
||||
|
||||
/// Test two iterators for inequality.
|
||||
friend bool operator!=(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return !a.equal(b);
|
||||
}
|
||||
|
||||
/// Compare two iterators.
|
||||
friend bool operator<(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return a.distance_to(b) > 0;
|
||||
}
|
||||
|
||||
/// Compare two iterators.
|
||||
friend bool operator<=(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return !(b < a);
|
||||
}
|
||||
|
||||
/// Compare two iterators.
|
||||
friend bool operator>(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return b < a;
|
||||
}
|
||||
|
||||
/// Compare two iterators.
|
||||
friend bool operator>=(const buffers_iterator& a, const buffers_iterator& b)
|
||||
{
|
||||
return !(a < b);
|
||||
}
|
||||
|
||||
private:
|
||||
// Dereference the iterator.
|
||||
reference dereference() const
|
||||
{
|
||||
return buffer_cast<pointer>(current_buffer_)[current_buffer_position_];
|
||||
}
|
||||
|
||||
// Compare two iterators for equality.
|
||||
bool equal(const buffers_iterator& other) const
|
||||
{
|
||||
return position_ == other.position_;
|
||||
}
|
||||
|
||||
// Increment the iterator.
|
||||
void increment()
|
||||
{
|
||||
ASIO_ASSERT(current_ != end_ && "iterator out of bounds");
|
||||
++position_;
|
||||
|
||||
// Check if the increment can be satisfied by the current buffer.
|
||||
++current_buffer_position_;
|
||||
if (current_buffer_position_ != asio::buffer_size(current_buffer_))
|
||||
return;
|
||||
|
||||
// Find the next non-empty buffer.
|
||||
++current_;
|
||||
current_buffer_position_ = 0;
|
||||
while (current_ != end_)
|
||||
{
|
||||
current_buffer_ = *current_;
|
||||
if (asio::buffer_size(current_buffer_) > 0)
|
||||
return;
|
||||
++current_;
|
||||
}
|
||||
}
|
||||
|
||||
// Decrement the iterator.
|
||||
void decrement()
|
||||
{
|
||||
ASIO_ASSERT(position_ > 0 && "iterator out of bounds");
|
||||
--position_;
|
||||
|
||||
// Check if the decrement can be satisfied by the current buffer.
|
||||
if (current_buffer_position_ != 0)
|
||||
{
|
||||
--current_buffer_position_;
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the previous non-empty buffer.
|
||||
typename BufferSequence::const_iterator iter = current_;
|
||||
while (iter != begin_)
|
||||
{
|
||||
--iter;
|
||||
buffer_type buffer = *iter;
|
||||
std::size_t buffer_size = asio::buffer_size(buffer);
|
||||
if (buffer_size > 0)
|
||||
{
|
||||
current_ = iter;
|
||||
current_buffer_ = buffer;
|
||||
current_buffer_position_ = buffer_size - 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Advance the iterator by the specified distance.
|
||||
void advance(std::ptrdiff_t n)
|
||||
{
|
||||
if (n > 0)
|
||||
{
|
||||
ASIO_ASSERT(current_ != end_ && "iterator out of bounds");
|
||||
for (;;)
|
||||
{
|
||||
std::ptrdiff_t current_buffer_balance
|
||||
= asio::buffer_size(current_buffer_)
|
||||
- current_buffer_position_;
|
||||
|
||||
// Check if the advance can be satisfied by the current buffer.
|
||||
if (current_buffer_balance > n)
|
||||
{
|
||||
position_ += n;
|
||||
current_buffer_position_ += n;
|
||||
return;
|
||||
}
|
||||
|
||||
// Update position.
|
||||
n -= current_buffer_balance;
|
||||
position_ += current_buffer_balance;
|
||||
|
||||
// Move to next buffer. If it is empty then it will be skipped on the
|
||||
// next iteration of this loop.
|
||||
if (++current_ == end_)
|
||||
{
|
||||
ASIO_ASSERT(n == 0 && "iterator out of bounds");
|
||||
current_buffer_ = buffer_type();
|
||||
current_buffer_position_ = 0;
|
||||
return;
|
||||
}
|
||||
current_buffer_ = *current_;
|
||||
current_buffer_position_ = 0;
|
||||
}
|
||||
}
|
||||
else if (n < 0)
|
||||
{
|
||||
std::size_t abs_n = -n;
|
||||
ASIO_ASSERT(position_ >= abs_n && "iterator out of bounds");
|
||||
for (;;)
|
||||
{
|
||||
// Check if the advance can be satisfied by the current buffer.
|
||||
if (current_buffer_position_ >= abs_n)
|
||||
{
|
||||
position_ -= abs_n;
|
||||
current_buffer_position_ -= abs_n;
|
||||
return;
|
||||
}
|
||||
|
||||
// Update position.
|
||||
abs_n -= current_buffer_position_;
|
||||
position_ -= current_buffer_position_;
|
||||
|
||||
// Check if we've reached the beginning of the buffers.
|
||||
if (current_ == begin_)
|
||||
{
|
||||
ASIO_ASSERT(abs_n == 0 && "iterator out of bounds");
|
||||
current_buffer_position_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the previous non-empty buffer.
|
||||
typename BufferSequence::const_iterator iter = current_;
|
||||
while (iter != begin_)
|
||||
{
|
||||
--iter;
|
||||
buffer_type buffer = *iter;
|
||||
std::size_t buffer_size = asio::buffer_size(buffer);
|
||||
if (buffer_size > 0)
|
||||
{
|
||||
current_ = iter;
|
||||
current_buffer_ = buffer;
|
||||
current_buffer_position_ = buffer_size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the distance between two iterators.
|
||||
std::ptrdiff_t distance_to(const buffers_iterator& other) const
|
||||
{
|
||||
return other.position_ - position_;
|
||||
}
|
||||
|
||||
buffer_type current_buffer_;
|
||||
std::size_t current_buffer_position_;
|
||||
typename BufferSequence::const_iterator begin_;
|
||||
typename BufferSequence::const_iterator current_;
|
||||
typename BufferSequence::const_iterator end_;
|
||||
std::size_t position_;
|
||||
};
|
||||
|
||||
/// Construct an iterator representing the beginning of the buffers' data.
|
||||
template <typename BufferSequence>
|
||||
inline buffers_iterator<BufferSequence> buffers_begin(
|
||||
const BufferSequence& buffers)
|
||||
{
|
||||
return buffers_iterator<BufferSequence>::begin(buffers);
|
||||
}
|
||||
|
||||
/// Construct an iterator representing the end of the buffers' data.
|
||||
template <typename BufferSequence>
|
||||
inline buffers_iterator<BufferSequence> buffers_end(
|
||||
const BufferSequence& buffers)
|
||||
{
|
||||
return buffers_iterator<BufferSequence>::end(buffers);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_BUFFERS_ITERATOR_HPP
|
|
@ -1,218 +0,0 @@
|
|||
//
|
||||
// completion_condition.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_COMPLETION_CONDITION_HPP
|
||||
#define ASIO_COMPLETION_CONDITION_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
namespace detail {
|
||||
|
||||
// The default maximum number of bytes to transfer in a single operation.
|
||||
enum { default_max_transfer_size = 65536 };
|
||||
|
||||
// Adapt result of old-style completion conditions (which had a bool result
|
||||
// where true indicated that the operation was complete).
|
||||
inline std::size_t adapt_completion_condition_result(bool result)
|
||||
{
|
||||
return result ? 0 : default_max_transfer_size;
|
||||
}
|
||||
|
||||
// Adapt result of current completion conditions (which have a size_t result
|
||||
// where 0 means the operation is complete, and otherwise the result is the
|
||||
// maximum number of bytes to transfer on the next underlying operation).
|
||||
inline std::size_t adapt_completion_condition_result(std::size_t result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
class transfer_all_t
|
||||
{
|
||||
public:
|
||||
typedef std::size_t result_type;
|
||||
|
||||
template <typename Error>
|
||||
std::size_t operator()(const Error& err, std::size_t)
|
||||
{
|
||||
return !!err ? 0 : default_max_transfer_size;
|
||||
}
|
||||
};
|
||||
|
||||
class transfer_at_least_t
|
||||
{
|
||||
public:
|
||||
typedef std::size_t result_type;
|
||||
|
||||
explicit transfer_at_least_t(std::size_t minimum)
|
||||
: minimum_(minimum)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Error>
|
||||
std::size_t operator()(const Error& err, std::size_t bytes_transferred)
|
||||
{
|
||||
return (!!err || bytes_transferred >= minimum_)
|
||||
? 0 : default_max_transfer_size;
|
||||
}
|
||||
|
||||
private:
|
||||
std::size_t minimum_;
|
||||
};
|
||||
|
||||
class transfer_exactly_t
|
||||
{
|
||||
public:
|
||||
typedef std::size_t result_type;
|
||||
|
||||
explicit transfer_exactly_t(std::size_t size)
|
||||
: size_(size)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Error>
|
||||
std::size_t operator()(const Error& err, std::size_t bytes_transferred)
|
||||
{
|
||||
return (!!err || bytes_transferred >= size_) ? 0 :
|
||||
(size_ - bytes_transferred < default_max_transfer_size
|
||||
? size_ - bytes_transferred : std::size_t(default_max_transfer_size));
|
||||
}
|
||||
|
||||
private:
|
||||
std::size_t size_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* @defgroup completion_condition Completion Condition Function Objects
|
||||
*
|
||||
* Function objects used for determining when a read or write operation should
|
||||
* complete.
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/// Return a completion condition function object that indicates that a read or
|
||||
/// write operation should continue until all of the data has been transferred,
|
||||
/// or until an error occurs.
|
||||
/**
|
||||
* This function is used to create an object, of unspecified type, that meets
|
||||
* CompletionCondition requirements.
|
||||
*
|
||||
* @par Example
|
||||
* Reading until a buffer is full:
|
||||
* @code
|
||||
* boost::array<char, 128> buf;
|
||||
* asio::error_code ec;
|
||||
* std::size_t n = asio::read(
|
||||
* sock, asio::buffer(buf),
|
||||
* asio::transfer_all(), ec);
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // n == 128
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
unspecified transfer_all();
|
||||
#else
|
||||
inline detail::transfer_all_t transfer_all()
|
||||
{
|
||||
return detail::transfer_all_t();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Return a completion condition function object that indicates that a read or
|
||||
/// write operation should continue until a minimum number of bytes has been
|
||||
/// transferred, or until an error occurs.
|
||||
/**
|
||||
* This function is used to create an object, of unspecified type, that meets
|
||||
* CompletionCondition requirements.
|
||||
*
|
||||
* @par Example
|
||||
* Reading until a buffer is full or contains at least 64 bytes:
|
||||
* @code
|
||||
* boost::array<char, 128> buf;
|
||||
* asio::error_code ec;
|
||||
* std::size_t n = asio::read(
|
||||
* sock, asio::buffer(buf),
|
||||
* asio::transfer_at_least(64), ec);
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // n >= 64 && n <= 128
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
unspecified transfer_at_least(std::size_t minimum);
|
||||
#else
|
||||
inline detail::transfer_at_least_t transfer_at_least(std::size_t minimum)
|
||||
{
|
||||
return detail::transfer_at_least_t(minimum);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Return a completion condition function object that indicates that a read or
|
||||
/// write operation should continue until an exact number of bytes has been
|
||||
/// transferred, or until an error occurs.
|
||||
/**
|
||||
* This function is used to create an object, of unspecified type, that meets
|
||||
* CompletionCondition requirements.
|
||||
*
|
||||
* @par Example
|
||||
* Reading until a buffer is full or contains exactly 64 bytes:
|
||||
* @code
|
||||
* boost::array<char, 128> buf;
|
||||
* asio::error_code ec;
|
||||
* std::size_t n = asio::read(
|
||||
* sock, asio::buffer(buf),
|
||||
* asio::transfer_exactly(64), ec);
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // n == 64
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
unspecified transfer_exactly(std::size_t size);
|
||||
#else
|
||||
inline detail::transfer_exactly_t transfer_exactly(std::size_t size)
|
||||
{
|
||||
return detail::transfer_exactly_t(size);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*@}*/
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_COMPLETION_CONDITION_HPP
|
|
@ -1,823 +0,0 @@
|
|||
//
|
||||
// connect.hpp
|
||||
// ~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_CONNECT_HPP
|
||||
#define ASIO_CONNECT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/basic_socket.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/**
|
||||
* @defgroup connect asio::connect
|
||||
*
|
||||
* @brief Establishes a socket connection by trying each endpoint in a sequence.
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
* function, once for each endpoint in the sequence, until a connection is
|
||||
* successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @returns On success, an iterator denoting the successfully connected
|
||||
* endpoint. Otherwise, the end iterator.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. If the sequence is
|
||||
* empty, the associated @c error_code is asio::error::not_found.
|
||||
* Otherwise, contains the error from the last connection attempt.
|
||||
*
|
||||
* @note This overload assumes that a default constructed object of type @c
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_service);
|
||||
* asio::connect(s, r.resolve(q)); @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin);
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
* function, once for each endpoint in the sequence, until a connection is
|
||||
* successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any. If the sequence is
|
||||
* empty, set to asio::error::not_found. Otherwise, contains the error
|
||||
* from the last connection attempt.
|
||||
*
|
||||
* @returns On success, an iterator denoting the successfully connected
|
||||
* endpoint. Otherwise, the end iterator.
|
||||
*
|
||||
* @note This overload assumes that a default constructed object of type @c
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_service);
|
||||
* asio::error_code ec;
|
||||
* asio::connect(s, r.resolve(q), ec);
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s,
|
||||
Iterator begin, asio::error_code& ec);
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
* function, once for each endpoint in the sequence, until a connection is
|
||||
* successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param end An iterator pointing to the end of a sequence of endpoints.
|
||||
*
|
||||
* @returns On success, an iterator denoting the successfully connected
|
||||
* endpoint. Otherwise, the end iterator.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. If the sequence is
|
||||
* empty, the associated @c error_code is asio::error::not_found.
|
||||
* Otherwise, contains the error from the last connection attempt.
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::resolver::iterator i = r.resolve(q), end;
|
||||
* tcp::socket s(io_service);
|
||||
* asio::connect(s, i, end); @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s,
|
||||
Iterator begin, Iterator end);
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
* function, once for each endpoint in the sequence, until a connection is
|
||||
* successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param end An iterator pointing to the end of a sequence of endpoints.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any. If the sequence is
|
||||
* empty, set to asio::error::not_found. Otherwise, contains the error
|
||||
* from the last connection attempt.
|
||||
*
|
||||
* @returns On success, an iterator denoting the successfully connected
|
||||
* endpoint. Otherwise, the end iterator.
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::resolver::iterator i = r.resolve(q), end;
|
||||
* tcp::socket s(io_service);
|
||||
* asio::error_code ec;
|
||||
* asio::connect(s, i, end, ec);
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s,
|
||||
Iterator begin, Iterator end, asio::error_code& ec);
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
* function, once for each endpoint in the sequence, until a connection is
|
||||
* successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param connect_condition A function object that is called prior to each
|
||||
* connection attempt. The signature of the function object must be:
|
||||
* @code Iterator connect_condition(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next); @endcode
|
||||
* The @c ec parameter contains the result from the most recent connect
|
||||
* operation. Before the first connection attempt, @c ec is always set to
|
||||
* indicate success. The @c next parameter is an iterator pointing to the next
|
||||
* endpoint to be tried. The function object should return the next iterator,
|
||||
* but is permitted to return a different iterator so that endpoints may be
|
||||
* skipped. The implementation guarantees that the function object will never
|
||||
* be called with the end iterator.
|
||||
*
|
||||
* @returns On success, an iterator denoting the successfully connected
|
||||
* endpoint. Otherwise, the end iterator.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. If the sequence is
|
||||
* empty, the associated @c error_code is asio::error::not_found.
|
||||
* Otherwise, contains the error from the last connection attempt.
|
||||
*
|
||||
* @note This overload assumes that a default constructed object of type @c
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*
|
||||
* @par Example
|
||||
* The following connect condition function object can be used to output
|
||||
* information about the individual connection attempts:
|
||||
* @code struct my_connect_condition
|
||||
* {
|
||||
* template <typename Iterator>
|
||||
* Iterator operator()(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next)
|
||||
* {
|
||||
* if (ec) std::cout << "Error: " << ec.message() << std::endl;
|
||||
* std::cout << "Trying: " << next->endpoint() << std::endl;
|
||||
* return next;
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_service);
|
||||
* tcp::resolver::iterator i = asio::connect(
|
||||
* s, r.resolve(q), my_connect_condition());
|
||||
* std::cout << "Connected to: " << i->endpoint() << std::endl; @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s,
|
||||
Iterator begin, ConnectCondition connect_condition);
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
* function, once for each endpoint in the sequence, until a connection is
|
||||
* successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param connect_condition A function object that is called prior to each
|
||||
* connection attempt. The signature of the function object must be:
|
||||
* @code Iterator connect_condition(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next); @endcode
|
||||
* The @c ec parameter contains the result from the most recent connect
|
||||
* operation. Before the first connection attempt, @c ec is always set to
|
||||
* indicate success. The @c next parameter is an iterator pointing to the next
|
||||
* endpoint to be tried. The function object should return the next iterator,
|
||||
* but is permitted to return a different iterator so that endpoints may be
|
||||
* skipped. The implementation guarantees that the function object will never
|
||||
* be called with the end iterator.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any. If the sequence is
|
||||
* empty, set to asio::error::not_found. Otherwise, contains the error
|
||||
* from the last connection attempt.
|
||||
*
|
||||
* @returns On success, an iterator denoting the successfully connected
|
||||
* endpoint. Otherwise, the end iterator.
|
||||
*
|
||||
* @note This overload assumes that a default constructed object of type @c
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*
|
||||
* @par Example
|
||||
* The following connect condition function object can be used to output
|
||||
* information about the individual connection attempts:
|
||||
* @code struct my_connect_condition
|
||||
* {
|
||||
* template <typename Iterator>
|
||||
* Iterator operator()(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next)
|
||||
* {
|
||||
* if (ec) std::cout << "Error: " << ec.message() << std::endl;
|
||||
* std::cout << "Trying: " << next->endpoint() << std::endl;
|
||||
* return next;
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_service);
|
||||
* asio::error_code ec;
|
||||
* tcp::resolver::iterator i = asio::connect(
|
||||
* s, r.resolve(q), my_connect_condition(), ec);
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* std::cout << "Connected to: " << i->endpoint() << std::endl;
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
|
||||
ConnectCondition connect_condition, asio::error_code& ec);
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
* function, once for each endpoint in the sequence, until a connection is
|
||||
* successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param end An iterator pointing to the end of a sequence of endpoints.
|
||||
*
|
||||
* @param connect_condition A function object that is called prior to each
|
||||
* connection attempt. The signature of the function object must be:
|
||||
* @code Iterator connect_condition(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next); @endcode
|
||||
* The @c ec parameter contains the result from the most recent connect
|
||||
* operation. Before the first connection attempt, @c ec is always set to
|
||||
* indicate success. The @c next parameter is an iterator pointing to the next
|
||||
* endpoint to be tried. The function object should return the next iterator,
|
||||
* but is permitted to return a different iterator so that endpoints may be
|
||||
* skipped. The implementation guarantees that the function object will never
|
||||
* be called with the end iterator.
|
||||
*
|
||||
* @returns On success, an iterator denoting the successfully connected
|
||||
* endpoint. Otherwise, the end iterator.
|
||||
*
|
||||
* @throws asio::system_error Thrown on failure. If the sequence is
|
||||
* empty, the associated @c error_code is asio::error::not_found.
|
||||
* Otherwise, contains the error from the last connection attempt.
|
||||
*
|
||||
* @par Example
|
||||
* The following connect condition function object can be used to output
|
||||
* information about the individual connection attempts:
|
||||
* @code struct my_connect_condition
|
||||
* {
|
||||
* template <typename Iterator>
|
||||
* Iterator operator()(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next)
|
||||
* {
|
||||
* if (ec) std::cout << "Error: " << ec.message() << std::endl;
|
||||
* std::cout << "Trying: " << next->endpoint() << std::endl;
|
||||
* return next;
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::resolver::iterator i = r.resolve(q), end;
|
||||
* tcp::socket s(io_service);
|
||||
* i = asio::connect(s, i, end, my_connect_condition());
|
||||
* std::cout << "Connected to: " << i->endpoint() << std::endl; @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
|
||||
Iterator end, ConnectCondition connect_condition);
|
||||
|
||||
/// Establishes a socket connection by trying each endpoint in a sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c connect member
|
||||
* function, once for each endpoint in the sequence, until a connection is
|
||||
* successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param end An iterator pointing to the end of a sequence of endpoints.
|
||||
*
|
||||
* @param connect_condition A function object that is called prior to each
|
||||
* connection attempt. The signature of the function object must be:
|
||||
* @code Iterator connect_condition(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next); @endcode
|
||||
* The @c ec parameter contains the result from the most recent connect
|
||||
* operation. Before the first connection attempt, @c ec is always set to
|
||||
* indicate success. The @c next parameter is an iterator pointing to the next
|
||||
* endpoint to be tried. The function object should return the next iterator,
|
||||
* but is permitted to return a different iterator so that endpoints may be
|
||||
* skipped. The implementation guarantees that the function object will never
|
||||
* be called with the end iterator.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any. If the sequence is
|
||||
* empty, set to asio::error::not_found. Otherwise, contains the error
|
||||
* from the last connection attempt.
|
||||
*
|
||||
* @returns On success, an iterator denoting the successfully connected
|
||||
* endpoint. Otherwise, the end iterator.
|
||||
*
|
||||
* @par Example
|
||||
* The following connect condition function object can be used to output
|
||||
* information about the individual connection attempts:
|
||||
* @code struct my_connect_condition
|
||||
* {
|
||||
* template <typename Iterator>
|
||||
* Iterator operator()(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next)
|
||||
* {
|
||||
* if (ec) std::cout << "Error: " << ec.message() << std::endl;
|
||||
* std::cout << "Trying: " << next->endpoint() << std::endl;
|
||||
* return next;
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::resolver::iterator i = r.resolve(q), end;
|
||||
* tcp::socket s(io_service);
|
||||
* asio::error_code ec;
|
||||
* i = asio::connect(s, i, end, my_connect_condition(), ec);
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* std::cout << "Connected to: " << i->endpoint() << std::endl;
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s,
|
||||
Iterator begin, Iterator end, ConnectCondition connect_condition,
|
||||
asio::error_code& ec);
|
||||
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* @defgroup async_connect asio::async_connect
|
||||
*
|
||||
* @brief Asynchronously establishes a socket connection by trying each
|
||||
* endpoint in a sequence.
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/// Asynchronously establishes a socket connection by trying each endpoint in a
|
||||
/// sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c async_connect
|
||||
* member function, once for each endpoint in the sequence, until a connection
|
||||
* is successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param handler The handler to be called when the connect operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* // Result of operation. if the sequence is empty, set to
|
||||
* // asio::error::not_found. Otherwise, contains the
|
||||
* // error from the last connection attempt.
|
||||
* const asio::error_code& error,
|
||||
*
|
||||
* // On success, an iterator denoting the successfully
|
||||
* // connected endpoint. Otherwise, the end iterator.
|
||||
* Iterator iterator
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note This overload assumes that a default constructed object of type @c
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_service);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* r.async_resolve(q, resolve_handler);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* void resolve_handler(
|
||||
* const asio::error_code& ec,
|
||||
* tcp::resolver::iterator i)
|
||||
* {
|
||||
* if (!ec)
|
||||
* {
|
||||
* asio::async_connect(s, i, connect_handler);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* void connect_handler(
|
||||
* const asio::error_code& ec,
|
||||
* tcp::resolver::iterator i)
|
||||
* {
|
||||
* // ...
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService,
|
||||
typename Iterator, typename ComposedConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol, SocketService>& s,
|
||||
Iterator begin, ASIO_MOVE_ARG(ComposedConnectHandler) handler);
|
||||
|
||||
/// Asynchronously establishes a socket connection by trying each endpoint in a
|
||||
/// sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c async_connect
|
||||
* member function, once for each endpoint in the sequence, until a connection
|
||||
* is successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param end An iterator pointing to the end of a sequence of endpoints.
|
||||
*
|
||||
* @param handler The handler to be called when the connect operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* // Result of operation. if the sequence is empty, set to
|
||||
* // asio::error::not_found. Otherwise, contains the
|
||||
* // error from the last connection attempt.
|
||||
* const asio::error_code& error,
|
||||
*
|
||||
* // On success, an iterator denoting the successfully
|
||||
* // connected endpoint. Otherwise, the end iterator.
|
||||
* Iterator iterator
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_service);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* r.async_resolve(q, resolve_handler);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* void resolve_handler(
|
||||
* const asio::error_code& ec,
|
||||
* tcp::resolver::iterator i)
|
||||
* {
|
||||
* if (!ec)
|
||||
* {
|
||||
* tcp::resolver::iterator end;
|
||||
* asio::async_connect(s, i, end, connect_handler);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* void connect_handler(
|
||||
* const asio::error_code& ec,
|
||||
* tcp::resolver::iterator i)
|
||||
* {
|
||||
* // ...
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService,
|
||||
typename Iterator, typename ComposedConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol, SocketService>& s,
|
||||
Iterator begin, Iterator end,
|
||||
ASIO_MOVE_ARG(ComposedConnectHandler) handler);
|
||||
|
||||
/// Asynchronously establishes a socket connection by trying each endpoint in a
|
||||
/// sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c async_connect
|
||||
* member function, once for each endpoint in the sequence, until a connection
|
||||
* is successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param connect_condition A function object that is called prior to each
|
||||
* connection attempt. The signature of the function object must be:
|
||||
* @code Iterator connect_condition(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next); @endcode
|
||||
* The @c ec parameter contains the result from the most recent connect
|
||||
* operation. Before the first connection attempt, @c ec is always set to
|
||||
* indicate success. The @c next parameter is an iterator pointing to the next
|
||||
* endpoint to be tried. The function object should return the next iterator,
|
||||
* but is permitted to return a different iterator so that endpoints may be
|
||||
* skipped. The implementation guarantees that the function object will never
|
||||
* be called with the end iterator.
|
||||
*
|
||||
* @param handler The handler to be called when the connect operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* // Result of operation. if the sequence is empty, set to
|
||||
* // asio::error::not_found. Otherwise, contains the
|
||||
* // error from the last connection attempt.
|
||||
* const asio::error_code& error,
|
||||
*
|
||||
* // On success, an iterator denoting the successfully
|
||||
* // connected endpoint. Otherwise, the end iterator.
|
||||
* Iterator iterator
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @note This overload assumes that a default constructed object of type @c
|
||||
* Iterator represents the end of the sequence. This is a valid assumption for
|
||||
* iterator types such as @c asio::ip::tcp::resolver::iterator.
|
||||
*
|
||||
* @par Example
|
||||
* The following connect condition function object can be used to output
|
||||
* information about the individual connection attempts:
|
||||
* @code struct my_connect_condition
|
||||
* {
|
||||
* template <typename Iterator>
|
||||
* Iterator operator()(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next)
|
||||
* {
|
||||
* if (ec) std::cout << "Error: " << ec.message() << std::endl;
|
||||
* std::cout << "Trying: " << next->endpoint() << std::endl;
|
||||
* return next;
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_service);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* r.async_resolve(q, resolve_handler);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* void resolve_handler(
|
||||
* const asio::error_code& ec,
|
||||
* tcp::resolver::iterator i)
|
||||
* {
|
||||
* if (!ec)
|
||||
* {
|
||||
* asio::async_connect(s, i,
|
||||
* my_connect_condition(),
|
||||
* connect_handler);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* void connect_handler(
|
||||
* const asio::error_code& ec,
|
||||
* tcp::resolver::iterator i)
|
||||
* {
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* std::cout << "Connected to: " << i->endpoint() << std::endl;
|
||||
* }
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService, typename Iterator,
|
||||
typename ConnectCondition, typename ComposedConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
|
||||
ConnectCondition connect_condition,
|
||||
ASIO_MOVE_ARG(ComposedConnectHandler) handler);
|
||||
|
||||
/// Asynchronously establishes a socket connection by trying each endpoint in a
|
||||
/// sequence.
|
||||
/**
|
||||
* This function attempts to connect a socket to one of a sequence of
|
||||
* endpoints. It does this by repeated calls to the socket's @c async_connect
|
||||
* member function, once for each endpoint in the sequence, until a connection
|
||||
* is successfully established.
|
||||
*
|
||||
* @param s The socket to be connected. If the socket is already open, it will
|
||||
* be closed.
|
||||
*
|
||||
* @param begin An iterator pointing to the start of a sequence of endpoints.
|
||||
*
|
||||
* @param end An iterator pointing to the end of a sequence of endpoints.
|
||||
*
|
||||
* @param connect_condition A function object that is called prior to each
|
||||
* connection attempt. The signature of the function object must be:
|
||||
* @code Iterator connect_condition(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next); @endcode
|
||||
* The @c ec parameter contains the result from the most recent connect
|
||||
* operation. Before the first connection attempt, @c ec is always set to
|
||||
* indicate success. The @c next parameter is an iterator pointing to the next
|
||||
* endpoint to be tried. The function object should return the next iterator,
|
||||
* but is permitted to return a different iterator so that endpoints may be
|
||||
* skipped. The implementation guarantees that the function object will never
|
||||
* be called with the end iterator.
|
||||
*
|
||||
* @param handler The handler to be called when the connect operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* // Result of operation. if the sequence is empty, set to
|
||||
* // asio::error::not_found. Otherwise, contains the
|
||||
* // error from the last connection attempt.
|
||||
* const asio::error_code& error,
|
||||
*
|
||||
* // On success, an iterator denoting the successfully
|
||||
* // connected endpoint. Otherwise, the end iterator.
|
||||
* Iterator iterator
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* The following connect condition function object can be used to output
|
||||
* information about the individual connection attempts:
|
||||
* @code struct my_connect_condition
|
||||
* {
|
||||
* template <typename Iterator>
|
||||
* Iterator operator()(
|
||||
* const asio::error_code& ec,
|
||||
* Iterator next)
|
||||
* {
|
||||
* if (ec) std::cout << "Error: " << ec.message() << std::endl;
|
||||
* std::cout << "Trying: " << next->endpoint() << std::endl;
|
||||
* return next;
|
||||
* }
|
||||
* }; @endcode
|
||||
* It would be used with the asio::connect function as follows:
|
||||
* @code tcp::resolver r(io_service);
|
||||
* tcp::resolver::query q("host", "service");
|
||||
* tcp::socket s(io_service);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* r.async_resolve(q, resolve_handler);
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* void resolve_handler(
|
||||
* const asio::error_code& ec,
|
||||
* tcp::resolver::iterator i)
|
||||
* {
|
||||
* if (!ec)
|
||||
* {
|
||||
* tcp::resolver::iterator end;
|
||||
* asio::async_connect(s, i, end,
|
||||
* my_connect_condition(),
|
||||
* connect_handler);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* void connect_handler(
|
||||
* const asio::error_code& ec,
|
||||
* tcp::resolver::iterator i)
|
||||
* {
|
||||
* if (ec)
|
||||
* {
|
||||
* // An error occurred.
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* std::cout << "Connected to: " << i->endpoint() << std::endl;
|
||||
* }
|
||||
* } @endcode
|
||||
*/
|
||||
template <typename Protocol, typename SocketService, typename Iterator,
|
||||
typename ConnectCondition, typename ComposedConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol, SocketService>& s,
|
||||
Iterator begin, Iterator end, ConnectCondition connect_condition,
|
||||
ASIO_MOVE_ARG(ComposedConnectHandler) handler);
|
||||
|
||||
/*@}*/
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/impl/connect.hpp"
|
||||
|
||||
#endif
|
|
@ -1,328 +0,0 @@
|
|||
//
|
||||
// coroutine.hpp
|
||||
// ~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_COROUTINE_HPP
|
||||
#define ASIO_COROUTINE_HPP
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class coroutine_ref;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// Provides support for implementing stackless coroutines.
|
||||
/**
|
||||
* The @c coroutine class may be used to implement stackless coroutines. The
|
||||
* class itself is used to store the current state of the coroutine.
|
||||
*
|
||||
* Coroutines are copy-constructible and assignable, and the space overhead is
|
||||
* a single int. They can be used as a base class:
|
||||
*
|
||||
* @code class session : coroutine
|
||||
* {
|
||||
* ...
|
||||
* }; @endcode
|
||||
*
|
||||
* or as a data member:
|
||||
*
|
||||
* @code class session
|
||||
* {
|
||||
* ...
|
||||
* coroutine coro_;
|
||||
* }; @endcode
|
||||
*
|
||||
* or even bound in as a function argument using lambdas or @c bind(). The
|
||||
* important thing is that as the application maintains a copy of the object
|
||||
* for as long as the coroutine must be kept alive.
|
||||
*
|
||||
* @par Pseudo-keywords
|
||||
*
|
||||
* A coroutine is used in conjunction with certain "pseudo-keywords", which
|
||||
* are implemented as macros. These macros are defined by a header file:
|
||||
*
|
||||
* @code #include <asio/yield.hpp>@endcode
|
||||
*
|
||||
* and may conversely be undefined as follows:
|
||||
*
|
||||
* @code #include <asio/unyield.hpp>@endcode
|
||||
*
|
||||
* <b>reenter</b>
|
||||
*
|
||||
* The @c reenter macro is used to define the body of a coroutine. It takes a
|
||||
* single argument: a pointer or reference to a coroutine object. For example,
|
||||
* if the base class is a coroutine object you may write:
|
||||
*
|
||||
* @code reenter (this)
|
||||
* {
|
||||
* ... coroutine body ...
|
||||
* } @endcode
|
||||
*
|
||||
* and if a data member or other variable you can write:
|
||||
*
|
||||
* @code reenter (coro_)
|
||||
* {
|
||||
* ... coroutine body ...
|
||||
* } @endcode
|
||||
*
|
||||
* When @c reenter is executed at runtime, control jumps to the location of the
|
||||
* last @c yield or @c fork.
|
||||
*
|
||||
* The coroutine body may also be a single statement, such as:
|
||||
*
|
||||
* @code reenter (this) for (;;)
|
||||
* {
|
||||
* ...
|
||||
* } @endcode
|
||||
*
|
||||
* @b Limitation: The @c reenter macro is implemented using a switch. This
|
||||
* means that you must take care when using local variables within the
|
||||
* coroutine body. The local variable is not allowed in a position where
|
||||
* reentering the coroutine could bypass the variable definition.
|
||||
*
|
||||
* <b>yield <em>statement</em></b>
|
||||
*
|
||||
* This form of the @c yield keyword is often used with asynchronous operations:
|
||||
*
|
||||
* @code yield socket_->async_read_some(buffer(*buffer_), *this); @endcode
|
||||
*
|
||||
* This divides into four logical steps:
|
||||
*
|
||||
* @li @c yield saves the current state of the coroutine.
|
||||
* @li The statement initiates the asynchronous operation.
|
||||
* @li The resume point is defined immediately following the statement.
|
||||
* @li Control is transferred to the end of the coroutine body.
|
||||
*
|
||||
* When the asynchronous operation completes, the function object is invoked
|
||||
* and @c reenter causes control to transfer to the resume point. It is
|
||||
* important to remember to carry the coroutine state forward with the
|
||||
* asynchronous operation. In the above snippet, the current class is a
|
||||
* function object object with a coroutine object as base class or data member.
|
||||
*
|
||||
* The statement may also be a compound statement, and this permits us to
|
||||
* define local variables with limited scope:
|
||||
*
|
||||
* @code yield
|
||||
* {
|
||||
* mutable_buffers_1 b = buffer(*buffer_);
|
||||
* socket_->async_read_some(b, *this);
|
||||
* } @endcode
|
||||
*
|
||||
* <b>yield return <em>expression</em> ;</b>
|
||||
*
|
||||
* This form of @c yield is often used in generators or coroutine-based parsers.
|
||||
* For example, the function object:
|
||||
*
|
||||
* @code struct interleave : coroutine
|
||||
* {
|
||||
* istream& is1;
|
||||
* istream& is2;
|
||||
* char operator()(char c)
|
||||
* {
|
||||
* reenter (this) for (;;)
|
||||
* {
|
||||
* yield return is1.get();
|
||||
* yield return is2.get();
|
||||
* }
|
||||
* }
|
||||
* }; @endcode
|
||||
*
|
||||
* defines a trivial coroutine that interleaves the characters from two input
|
||||
* streams.
|
||||
*
|
||||
* This type of @c yield divides into three logical steps:
|
||||
*
|
||||
* @li @c yield saves the current state of the coroutine.
|
||||
* @li The resume point is defined immediately following the semicolon.
|
||||
* @li The value of the expression is returned from the function.
|
||||
*
|
||||
* <b>yield ;</b>
|
||||
*
|
||||
* This form of @c yield is equivalent to the following steps:
|
||||
*
|
||||
* @li @c yield saves the current state of the coroutine.
|
||||
* @li The resume point is defined immediately following the semicolon.
|
||||
* @li Control is transferred to the end of the coroutine body.
|
||||
*
|
||||
* This form might be applied when coroutines are used for cooperative
|
||||
* threading and scheduling is explicitly managed. For example:
|
||||
*
|
||||
* @code struct task : coroutine
|
||||
* {
|
||||
* ...
|
||||
* void operator()()
|
||||
* {
|
||||
* reenter (this)
|
||||
* {
|
||||
* while (... not finished ...)
|
||||
* {
|
||||
* ... do something ...
|
||||
* yield;
|
||||
* ... do some more ...
|
||||
* yield;
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ...
|
||||
* };
|
||||
* ...
|
||||
* task t1, t2;
|
||||
* for (;;)
|
||||
* {
|
||||
* t1();
|
||||
* t2();
|
||||
* } @endcode
|
||||
*
|
||||
* <b>yield break ;</b>
|
||||
*
|
||||
* The final form of @c yield is used to explicitly terminate the coroutine.
|
||||
* This form is comprised of two steps:
|
||||
*
|
||||
* @li @c yield sets the coroutine state to indicate termination.
|
||||
* @li Control is transferred to the end of the coroutine body.
|
||||
*
|
||||
* Once terminated, calls to is_complete() return true and the coroutine cannot
|
||||
* be reentered.
|
||||
*
|
||||
* Note that a coroutine may also be implicitly terminated if the coroutine
|
||||
* body is exited without a yield, e.g. by return, throw or by running to the
|
||||
* end of the body.
|
||||
*
|
||||
* <b>fork <em>statement</em></b>
|
||||
*
|
||||
* The @c fork pseudo-keyword is used when "forking" a coroutine, i.e. splitting
|
||||
* it into two (or more) copies. One use of @c fork is in a server, where a new
|
||||
* coroutine is created to handle each client connection:
|
||||
*
|
||||
* @code reenter (this)
|
||||
* {
|
||||
* do
|
||||
* {
|
||||
* socket_.reset(new tcp::socket(io_service_));
|
||||
* yield acceptor->async_accept(*socket_, *this);
|
||||
* fork server(*this)();
|
||||
* } while (is_parent());
|
||||
* ... client-specific handling follows ...
|
||||
* } @endcode
|
||||
*
|
||||
* The logical steps involved in a @c fork are:
|
||||
*
|
||||
* @li @c fork saves the current state of the coroutine.
|
||||
* @li The statement creates a copy of the coroutine and either executes it
|
||||
* immediately or schedules it for later execution.
|
||||
* @li The resume point is defined immediately following the semicolon.
|
||||
* @li For the "parent", control immediately continues from the next line.
|
||||
*
|
||||
* The functions is_parent() and is_child() can be used to differentiate
|
||||
* between parent and child. You would use these functions to alter subsequent
|
||||
* control flow.
|
||||
*
|
||||
* Note that @c fork doesn't do the actual forking by itself. It is the
|
||||
* application's responsibility to create a clone of the coroutine and call it.
|
||||
* The clone can be called immediately, as above, or scheduled for delayed
|
||||
* execution using something like io_service::post().
|
||||
*
|
||||
* @par Alternate macro names
|
||||
*
|
||||
* If preferred, an application can use macro names that follow a more typical
|
||||
* naming convention, rather than the pseudo-keywords. These are:
|
||||
*
|
||||
* @li @c ASIO_CORO_REENTER instead of @c reenter
|
||||
* @li @c ASIO_CORO_YIELD instead of @c yield
|
||||
* @li @c ASIO_CORO_FORK instead of @c fork
|
||||
*/
|
||||
class coroutine
|
||||
{
|
||||
public:
|
||||
/// Constructs a coroutine in its initial state.
|
||||
coroutine() : value_(0) {}
|
||||
|
||||
/// Returns true if the coroutine is the child of a fork.
|
||||
bool is_child() const { return value_ < 0; }
|
||||
|
||||
/// Returns true if the coroutine is the parent of a fork.
|
||||
bool is_parent() const { return !is_child(); }
|
||||
|
||||
/// Returns true if the coroutine has reached its terminal state.
|
||||
bool is_complete() const { return value_ == -1; }
|
||||
|
||||
private:
|
||||
friend class detail::coroutine_ref;
|
||||
int value_;
|
||||
};
|
||||
|
||||
|
||||
namespace detail {
|
||||
|
||||
class coroutine_ref
|
||||
{
|
||||
public:
|
||||
coroutine_ref(coroutine& c) : value_(c.value_), modified_(false) {}
|
||||
coroutine_ref(coroutine* c) : value_(c->value_), modified_(false) {}
|
||||
~coroutine_ref() { if (!modified_) value_ = -1; }
|
||||
operator int() const { return value_; }
|
||||
int& operator=(int v) { modified_ = true; return value_ = v; }
|
||||
private:
|
||||
void operator=(const coroutine_ref&);
|
||||
int& value_;
|
||||
bool modified_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#define ASIO_CORO_REENTER(c) \
|
||||
switch (::asio::detail::coroutine_ref _coro_value = c) \
|
||||
case -1: if (_coro_value) \
|
||||
{ \
|
||||
goto terminate_coroutine; \
|
||||
terminate_coroutine: \
|
||||
_coro_value = -1; \
|
||||
goto bail_out_of_coroutine; \
|
||||
bail_out_of_coroutine: \
|
||||
break; \
|
||||
} \
|
||||
else case 0:
|
||||
|
||||
#define ASIO_CORO_YIELD_IMPL(n) \
|
||||
for (_coro_value = (n);;) \
|
||||
if (_coro_value == 0) \
|
||||
{ \
|
||||
case (n): ; \
|
||||
break; \
|
||||
} \
|
||||
else \
|
||||
switch (_coro_value ? 0 : 1) \
|
||||
for (;;) \
|
||||
case -1: if (_coro_value) \
|
||||
goto terminate_coroutine; \
|
||||
else for (;;) \
|
||||
case 1: if (_coro_value) \
|
||||
goto bail_out_of_coroutine; \
|
||||
else case 0:
|
||||
|
||||
#define ASIO_CORO_FORK_IMPL(n) \
|
||||
for (_coro_value = -(n);; _coro_value = (n)) \
|
||||
if (_coro_value == (n)) \
|
||||
{ \
|
||||
case -(n): ; \
|
||||
break; \
|
||||
} \
|
||||
else
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# define ASIO_CORO_YIELD ASIO_CORO_YIELD_IMPL(__COUNTER__ + 1)
|
||||
# define ASIO_CORO_FORK ASIO_CORO_FORK_IMPL(__COUNTER__ + 1)
|
||||
#else // defined(_MSC_VER)
|
||||
# define ASIO_CORO_YIELD ASIO_CORO_YIELD_IMPL(__LINE__)
|
||||
# define ASIO_CORO_FORK ASIO_CORO_FORK_IMPL(__LINE__)
|
||||
#endif // defined(_MSC_VER)
|
||||
|
||||
#endif // ASIO_COROUTINE_HPP
|
|
@ -1,432 +0,0 @@
|
|||
//
|
||||
// datagram_socket_service.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DATAGRAM_SOCKET_SERVICE_HPP
|
||||
#define ASIO_DATAGRAM_SOCKET_SERVICE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
# include "asio/detail/null_socket_service.hpp"
|
||||
#elif defined(ASIO_HAS_IOCP)
|
||||
# include "asio/detail/win_iocp_socket_service.hpp"
|
||||
#else
|
||||
# include "asio/detail/reactive_socket_service.hpp"
|
||||
#endif
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Default service implementation for a datagram socket.
|
||||
template <typename Protocol>
|
||||
class datagram_socket_service
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
: public asio::io_service::service
|
||||
#else
|
||||
: public asio::detail::service_base<datagram_socket_service<Protocol> >
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The unique service identifier.
|
||||
static asio::io_service::id id;
|
||||
#endif
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
private:
|
||||
// The type of the platform-specific implementation.
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
typedef detail::null_socket_service<Protocol> service_impl_type;
|
||||
#elif defined(ASIO_HAS_IOCP)
|
||||
typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
|
||||
#else
|
||||
typedef detail::reactive_socket_service<Protocol> service_impl_type;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/// The type of a datagram socket.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef implementation_defined implementation_type;
|
||||
#else
|
||||
typedef typename service_impl_type::implementation_type implementation_type;
|
||||
#endif
|
||||
|
||||
/// (Deprecated: Use native_handle_type.) The native socket type.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef implementation_defined native_type;
|
||||
#else
|
||||
typedef typename service_impl_type::native_handle_type native_type;
|
||||
#endif
|
||||
|
||||
/// The native socket type.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef implementation_defined native_handle_type;
|
||||
#else
|
||||
typedef typename service_impl_type::native_handle_type native_handle_type;
|
||||
#endif
|
||||
|
||||
/// Construct a new datagram socket service for the specified io_service.
|
||||
explicit datagram_socket_service(asio::io_service& io_service)
|
||||
: asio::detail::service_base<
|
||||
datagram_socket_service<Protocol> >(io_service),
|
||||
service_impl_(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a new datagram socket implementation.
|
||||
void construct(implementation_type& impl)
|
||||
{
|
||||
service_impl_.construct(impl);
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a new datagram socket implementation.
|
||||
void move_construct(implementation_type& impl,
|
||||
implementation_type& other_impl)
|
||||
{
|
||||
service_impl_.move_construct(impl, other_impl);
|
||||
}
|
||||
|
||||
/// Move-assign from another datagram socket implementation.
|
||||
void move_assign(implementation_type& impl,
|
||||
datagram_socket_service& other_service,
|
||||
implementation_type& other_impl)
|
||||
{
|
||||
service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
|
||||
}
|
||||
|
||||
/// Move-construct a new datagram socket implementation from another protocol
|
||||
/// type.
|
||||
template <typename Protocol1>
|
||||
void converting_move_construct(implementation_type& impl,
|
||||
typename datagram_socket_service<
|
||||
Protocol1>::implementation_type& other_impl,
|
||||
typename enable_if<is_convertible<
|
||||
Protocol1, Protocol>::value>::type* = 0)
|
||||
{
|
||||
service_impl_.template converting_move_construct<Protocol1>(
|
||||
impl, other_impl);
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Destroy a datagram socket implementation.
|
||||
void destroy(implementation_type& impl)
|
||||
{
|
||||
service_impl_.destroy(impl);
|
||||
}
|
||||
|
||||
// Open a new datagram socket implementation.
|
||||
asio::error_code open(implementation_type& impl,
|
||||
const protocol_type& protocol, asio::error_code& ec)
|
||||
{
|
||||
if (protocol.type() == ASIO_OS_DEF(SOCK_DGRAM))
|
||||
service_impl_.open(impl, protocol, ec);
|
||||
else
|
||||
ec = asio::error::invalid_argument;
|
||||
return ec;
|
||||
}
|
||||
|
||||
/// Assign an existing native socket to a datagram socket.
|
||||
asio::error_code assign(implementation_type& impl,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.assign(impl, protocol, native_socket, ec);
|
||||
}
|
||||
|
||||
/// Determine whether the socket is open.
|
||||
bool is_open(const implementation_type& impl) const
|
||||
{
|
||||
return service_impl_.is_open(impl);
|
||||
}
|
||||
|
||||
/// Close a datagram socket implementation.
|
||||
asio::error_code close(implementation_type& impl,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.close(impl, ec);
|
||||
}
|
||||
|
||||
/// (Deprecated: Use native_handle().) Get the native socket implementation.
|
||||
native_type native(implementation_type& impl)
|
||||
{
|
||||
return service_impl_.native_handle(impl);
|
||||
}
|
||||
|
||||
/// Get the native socket implementation.
|
||||
native_handle_type native_handle(implementation_type& impl)
|
||||
{
|
||||
return service_impl_.native_handle(impl);
|
||||
}
|
||||
|
||||
/// Cancel all asynchronous operations associated with the socket.
|
||||
asio::error_code cancel(implementation_type& impl,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.cancel(impl, ec);
|
||||
}
|
||||
|
||||
/// Determine whether the socket is at the out-of-band data mark.
|
||||
bool at_mark(const implementation_type& impl,
|
||||
asio::error_code& ec) const
|
||||
{
|
||||
return service_impl_.at_mark(impl, ec);
|
||||
}
|
||||
|
||||
/// Determine the number of bytes available for reading.
|
||||
std::size_t available(const implementation_type& impl,
|
||||
asio::error_code& ec) const
|
||||
{
|
||||
return service_impl_.available(impl, ec);
|
||||
}
|
||||
|
||||
// Bind the datagram socket to the specified local endpoint.
|
||||
asio::error_code bind(implementation_type& impl,
|
||||
const endpoint_type& endpoint, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.bind(impl, endpoint, ec);
|
||||
}
|
||||
|
||||
/// Connect the datagram socket to the specified endpoint.
|
||||
asio::error_code connect(implementation_type& impl,
|
||||
const endpoint_type& peer_endpoint, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.connect(impl, peer_endpoint, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous connect.
|
||||
template <typename ConnectHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ConnectHandler,
|
||||
void (asio::error_code))
|
||||
async_connect(implementation_type& impl,
|
||||
const endpoint_type& peer_endpoint,
|
||||
ASIO_MOVE_ARG(ConnectHandler) handler)
|
||||
{
|
||||
detail::async_result_init<
|
||||
ConnectHandler, void (asio::error_code)> init(
|
||||
ASIO_MOVE_CAST(ConnectHandler)(handler));
|
||||
|
||||
service_impl_.async_connect(impl, peer_endpoint, init.handler);
|
||||
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
/// Set a socket option.
|
||||
template <typename SettableSocketOption>
|
||||
asio::error_code set_option(implementation_type& impl,
|
||||
const SettableSocketOption& option, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.set_option(impl, option, ec);
|
||||
}
|
||||
|
||||
/// Get a socket option.
|
||||
template <typename GettableSocketOption>
|
||||
asio::error_code get_option(const implementation_type& impl,
|
||||
GettableSocketOption& option, asio::error_code& ec) const
|
||||
{
|
||||
return service_impl_.get_option(impl, option, ec);
|
||||
}
|
||||
|
||||
/// Perform an IO control command on the socket.
|
||||
template <typename IoControlCommand>
|
||||
asio::error_code io_control(implementation_type& impl,
|
||||
IoControlCommand& command, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.io_control(impl, command, ec);
|
||||
}
|
||||
|
||||
/// Gets the non-blocking mode of the socket.
|
||||
bool non_blocking(const implementation_type& impl) const
|
||||
{
|
||||
return service_impl_.non_blocking(impl);
|
||||
}
|
||||
|
||||
/// Sets the non-blocking mode of the socket.
|
||||
asio::error_code non_blocking(implementation_type& impl,
|
||||
bool mode, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.non_blocking(impl, mode, ec);
|
||||
}
|
||||
|
||||
/// Gets the non-blocking mode of the native socket implementation.
|
||||
bool native_non_blocking(const implementation_type& impl) const
|
||||
{
|
||||
return service_impl_.native_non_blocking(impl);
|
||||
}
|
||||
|
||||
/// Sets the non-blocking mode of the native socket implementation.
|
||||
asio::error_code native_non_blocking(implementation_type& impl,
|
||||
bool mode, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.native_non_blocking(impl, mode, ec);
|
||||
}
|
||||
|
||||
/// Get the local endpoint.
|
||||
endpoint_type local_endpoint(const implementation_type& impl,
|
||||
asio::error_code& ec) const
|
||||
{
|
||||
return service_impl_.local_endpoint(impl, ec);
|
||||
}
|
||||
|
||||
/// Get the remote endpoint.
|
||||
endpoint_type remote_endpoint(const implementation_type& impl,
|
||||
asio::error_code& ec) const
|
||||
{
|
||||
return service_impl_.remote_endpoint(impl, ec);
|
||||
}
|
||||
|
||||
/// Disable sends or receives on the socket.
|
||||
asio::error_code shutdown(implementation_type& impl,
|
||||
socket_base::shutdown_type what, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.shutdown(impl, what, ec);
|
||||
}
|
||||
|
||||
/// Send the given data to the peer.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(implementation_type& impl,
|
||||
const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.send(impl, buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send(implementation_type& impl, const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
detail::async_result_init<
|
||||
WriteHandler, void (asio::error_code, std::size_t)> init(
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
|
||||
service_impl_.async_send(impl, buffers, flags, init.handler);
|
||||
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(implementation_type& impl,
|
||||
const ConstBufferSequence& buffers, const endpoint_type& destination,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.send_to(impl, buffers, destination, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_send_to(implementation_type& impl,
|
||||
const ConstBufferSequence& buffers, const endpoint_type& destination,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
detail::async_result_init<
|
||||
WriteHandler, void (asio::error_code, std::size_t)> init(
|
||||
ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
|
||||
service_impl_.async_send_to(impl, buffers,
|
||||
destination, flags, init.handler);
|
||||
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
/// Receive some data from the peer.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(implementation_type& impl,
|
||||
const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.receive(impl, buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive(implementation_type& impl,
|
||||
const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
detail::async_result_init<
|
||||
ReadHandler, void (asio::error_code, std::size_t)> init(
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
|
||||
service_impl_.async_receive(impl, buffers, flags, init.handler);
|
||||
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(implementation_type& impl,
|
||||
const MutableBufferSequence& buffers, endpoint_type& sender_endpoint,
|
||||
socket_base::message_flags flags, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.receive_from(impl, buffers, sender_endpoint, flags,
|
||||
ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive that will get the endpoint of the sender.
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_receive_from(implementation_type& impl,
|
||||
const MutableBufferSequence& buffers, endpoint_type& sender_endpoint,
|
||||
socket_base::message_flags flags,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
detail::async_result_init<
|
||||
ReadHandler, void (asio::error_code, std::size_t)> init(
|
||||
ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
|
||||
service_impl_.async_receive_from(impl, buffers,
|
||||
sender_endpoint, flags, init.handler);
|
||||
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
private:
|
||||
// Destroy all user-defined handler objects owned by the service.
|
||||
void shutdown_service()
|
||||
{
|
||||
service_impl_.shutdown_service();
|
||||
}
|
||||
|
||||
// The platform-specific implementation.
|
||||
service_impl_type service_impl_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DATAGRAM_SOCKET_SERVICE_HPP
|
|
@ -1,63 +0,0 @@
|
|||
//
|
||||
// deadline_timer.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DEADLINE_TIMER_HPP
|
||||
#define ASIO_DEADLINE_TIMER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
|| defined(ASIO_CPP11_DATE_TIME) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include "asio/detail/socket_types.hpp" // Must come before posix_time.
|
||||
#include "asio/basic_deadline_timer.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#elif defined(ASIO_CPP11_DATE_TIME)
|
||||
|
||||
#include "asio/detail/chrono_time_traits.hpp"
|
||||
#include "asio/wait_traits.hpp"
|
||||
#include <chrono>
|
||||
|
||||
#endif
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
/// Typedef for the typical usage of timer. Uses a UTC clock.
|
||||
typedef basic_deadline_timer<boost::posix_time::ptime> deadline_timer;
|
||||
|
||||
#elif defined(ASIO_CPP11_DATE_TIME)
|
||||
|
||||
typedef basic_deadline_timer<
|
||||
std::chrono::system_clock,
|
||||
detail::chrono_time_traits<std::chrono::system_clock,
|
||||
wait_traits<std::chrono::system_clock>>>
|
||||
deadline_timer;
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// || defined(ASIO_CPP11_DATE_TIME)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // ASIO_DEADLINE_TIMER_HPP
|
|
@ -1,173 +0,0 @@
|
|||
//
|
||||
// deadline_timer_service.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DEADLINE_TIMER_SERVICE_HPP
|
||||
#define ASIO_DEADLINE_TIMER_SERVICE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME) \
|
||||
|| defined(ASIO_CPP11_DATE_TIME) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include <cstddef>
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/detail/deadline_timer_service.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
#include "asio/time_traits.hpp"
|
||||
#include "asio/detail/timer_queue_ptime.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Default service implementation for a timer.
|
||||
template <typename TimeType,
|
||||
typename TimeTraits = asio::time_traits<TimeType> >
|
||||
class deadline_timer_service
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
: public asio::io_service::service
|
||||
#else
|
||||
: public asio::detail::service_base<
|
||||
deadline_timer_service<TimeType, TimeTraits> >
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The unique service identifier.
|
||||
static asio::io_service::id id;
|
||||
#endif
|
||||
|
||||
/// The time traits type.
|
||||
typedef TimeTraits traits_type;
|
||||
|
||||
/// The time type.
|
||||
typedef typename traits_type::time_type time_type;
|
||||
|
||||
/// The duration type.
|
||||
typedef typename traits_type::duration_type duration_type;
|
||||
|
||||
private:
|
||||
// The type of the platform-specific implementation.
|
||||
typedef detail::deadline_timer_service<traits_type> service_impl_type;
|
||||
|
||||
public:
|
||||
/// The implementation type of the deadline timer.
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
typedef implementation_defined implementation_type;
|
||||
#else
|
||||
typedef typename service_impl_type::implementation_type implementation_type;
|
||||
#endif
|
||||
|
||||
/// Construct a new timer service for the specified io_service.
|
||||
explicit deadline_timer_service(asio::io_service& io_service)
|
||||
: asio::detail::service_base<
|
||||
deadline_timer_service<TimeType, TimeTraits> >(io_service),
|
||||
service_impl_(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a new timer implementation.
|
||||
void construct(implementation_type& impl)
|
||||
{
|
||||
service_impl_.construct(impl);
|
||||
}
|
||||
|
||||
/// Destroy a timer implementation.
|
||||
void destroy(implementation_type& impl)
|
||||
{
|
||||
service_impl_.destroy(impl);
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous wait operations associated with the timer.
|
||||
std::size_t cancel(implementation_type& impl, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.cancel(impl, ec);
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous wait operation associated with the timer.
|
||||
std::size_t cancel_one(implementation_type& impl,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.cancel_one(impl, ec);
|
||||
}
|
||||
|
||||
/// Get the expiry time for the timer as an absolute time.
|
||||
time_type expires_at(const implementation_type& impl) const
|
||||
{
|
||||
return service_impl_.expires_at(impl);
|
||||
}
|
||||
|
||||
/// Set the expiry time for the timer as an absolute time.
|
||||
std::size_t expires_at(implementation_type& impl,
|
||||
const time_type& expiry_time, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.expires_at(impl, expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Get the expiry time for the timer relative to now.
|
||||
duration_type expires_from_now(const implementation_type& impl) const
|
||||
{
|
||||
return service_impl_.expires_from_now(impl);
|
||||
}
|
||||
|
||||
/// Set the expiry time for the timer relative to now.
|
||||
std::size_t expires_from_now(implementation_type& impl,
|
||||
const duration_type& expiry_time, asio::error_code& ec)
|
||||
{
|
||||
return service_impl_.expires_from_now(impl, expiry_time, ec);
|
||||
}
|
||||
|
||||
// Perform a blocking wait on the timer.
|
||||
void wait(implementation_type& impl, asio::error_code& ec)
|
||||
{
|
||||
service_impl_.wait(impl, ec);
|
||||
}
|
||||
|
||||
// Start an asynchronous wait on the timer.
|
||||
template <typename WaitHandler>
|
||||
ASIO_INITFN_RESULT_TYPE(WaitHandler,
|
||||
void (asio::error_code))
|
||||
async_wait(implementation_type& impl,
|
||||
ASIO_MOVE_ARG(WaitHandler) handler)
|
||||
{
|
||||
detail::async_result_init<
|
||||
WaitHandler, void (asio::error_code)> init(
|
||||
ASIO_MOVE_CAST(WaitHandler)(handler));
|
||||
|
||||
service_impl_.async_wait(impl, init.handler);
|
||||
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
private:
|
||||
// Destroy all user-defined handler objects owned by the service.
|
||||
void shutdown_service()
|
||||
{
|
||||
service_impl_.shutdown_service();
|
||||
}
|
||||
|
||||
// The platform-specific implementation.
|
||||
service_impl_type service_impl_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
// || defined(ASIO_CPP11_DATE_TIME)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // ASIO_DEADLINE_TIMER_SERVICE_HPP
|
|
@ -1,38 +0,0 @@
|
|||
//
|
||||
// detail/addressof.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_ADDRESSOF_HPP
|
||||
#define ASIO_DETAIL_ADDRESSOF_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_STD_ADDRESSOF)
|
||||
# include <memory>
|
||||
#else // defined(ASIO_HAS_STD_ADDRESSOF)
|
||||
# include <boost/utility/addressof.hpp>
|
||||
#endif // defined(ASIO_HAS_STD_ADDRESSOF)
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
#if defined(ASIO_HAS_STD_ADDRESSOF)
|
||||
using std::addressof;
|
||||
#else // defined(ASIO_HAS_STD_ADDRESSOF)
|
||||
using boost::addressof;
|
||||
#endif // defined(ASIO_HAS_STD_ADDRESSOF)
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_DETAIL_ADDRESSOF_HPP
|
|
@ -1,38 +0,0 @@
|
|||
//
|
||||
// detail/array.hpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_ARRAY_HPP
|
||||
#define ASIO_DETAIL_ARRAY_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
# include <array>
|
||||
#else // defined(ASIO_HAS_STD_ARRAY)
|
||||
# include <boost/array.hpp>
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
using std::array;
|
||||
#else // defined(ASIO_HAS_STD_ARRAY)
|
||||
using boost::array;
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_DETAIL_ARRAY_HPP
|
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// detail/array_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_ARRAY_FWD_HPP
|
||||
#define ASIO_DETAIL_ARRAY_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T, std::size_t N>
|
||||
class array;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
// Standard library components can't be forward declared, so we'll have to
|
||||
// include the array header. Fortunately, it's fairly lightweight and doesn't
|
||||
// add significantly to the compile time.
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
# include <array>
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
#endif // ASIO_DETAIL_ARRAY_FWD_HPP
|
|
@ -1,32 +0,0 @@
|
|||
//
|
||||
// detail/assert.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_ASSERT_HPP
|
||||
#define ASIO_DETAIL_ASSERT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_ASSERT)
|
||||
# include <boost/assert.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_ASSERT)
|
||||
# include <cassert>
|
||||
#endif // defined(ASIO_HAS_BOOST_ASSERT)
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_ASSERT)
|
||||
# define ASIO_ASSERT(expr) BOOST_ASSERT(expr)
|
||||
#else // defined(ASIO_HAS_BOOST_ASSERT)
|
||||
# define ASIO_ASSERT(expr) assert(expr)
|
||||
#endif // defined(ASIO_HAS_BOOST_ASSERT)
|
||||
|
||||
#endif // ASIO_DETAIL_ASSERT_HPP
|
|
@ -1,45 +0,0 @@
|
|||
//
|
||||
// detail/atomic_count.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_ATOMIC_COUNT_HPP
|
||||
#define ASIO_DETAIL_ATOMIC_COUNT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_HAS_THREADS)
|
||||
// Nothing to include.
|
||||
#elif defined(ASIO_HAS_STD_ATOMIC)
|
||||
# include <atomic>
|
||||
#else // defined(ASIO_HAS_STD_ATOMIC)
|
||||
# include <boost/detail/atomic_count.hpp>
|
||||
#endif // defined(ASIO_HAS_STD_ATOMIC)
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
#if !defined(ASIO_HAS_THREADS)
|
||||
typedef long atomic_count;
|
||||
inline void increment(atomic_count& a, long b) { a += b; }
|
||||
#elif defined(ASIO_HAS_STD_ATOMIC)
|
||||
typedef std::atomic<long> atomic_count;
|
||||
inline void increment(atomic_count& a, long b) { a += b; }
|
||||
#else // defined(ASIO_HAS_STD_ATOMIC)
|
||||
typedef boost::detail::atomic_count atomic_count;
|
||||
inline void increment(atomic_count& a, long b) { while (b > 0) ++a, --b; }
|
||||
#endif // defined(ASIO_HAS_STD_ATOMIC)
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_DETAIL_ATOMIC_COUNT_HPP
|
|
@ -1,68 +0,0 @@
|
|||
//
|
||||
// detail/base_from_completion_cond.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
|
||||
#define ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/completion_condition.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename CompletionCondition>
|
||||
class base_from_completion_cond
|
||||
{
|
||||
protected:
|
||||
explicit base_from_completion_cond(CompletionCondition completion_condition)
|
||||
: completion_condition_(completion_condition)
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t check_for_completion(
|
||||
const asio::error_code& ec,
|
||||
std::size_t total_transferred)
|
||||
{
|
||||
return detail::adapt_completion_condition_result(
|
||||
completion_condition_(ec, total_transferred));
|
||||
}
|
||||
|
||||
private:
|
||||
CompletionCondition completion_condition_;
|
||||
};
|
||||
|
||||
template <>
|
||||
class base_from_completion_cond<transfer_all_t>
|
||||
{
|
||||
protected:
|
||||
explicit base_from_completion_cond(transfer_all_t)
|
||||
{
|
||||
}
|
||||
|
||||
static std::size_t check_for_completion(
|
||||
const asio::error_code& ec,
|
||||
std::size_t total_transferred)
|
||||
{
|
||||
return transfer_all_t()(ec, total_transferred);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
|
|
@ -1,489 +0,0 @@
|
|||
//
|
||||
// detail/bind_handler.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_BIND_HANDLER_HPP
|
||||
#define ASIO_DETAIL_BIND_HANDLER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_cont_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
class binder1
|
||||
{
|
||||
public:
|
||||
binder1(const Handler& handler, const Arg1& arg1)
|
||||
: handler_(handler),
|
||||
arg1_(arg1)
|
||||
{
|
||||
}
|
||||
|
||||
binder1(Handler& handler, const Arg1& arg1)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
handler_(arg1_);
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline bool asio_handler_is_continuation(
|
||||
binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
binder1<Handler, Arg1>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1>
|
||||
inline binder1<Handler, Arg1> bind_handler(Handler handler,
|
||||
const Arg1& arg1)
|
||||
{
|
||||
return binder1<Handler, Arg1>(handler, arg1);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
class binder2
|
||||
{
|
||||
public:
|
||||
binder2(const Handler& handler, const Arg1& arg1, const Arg2& arg2)
|
||||
: handler_(handler),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2)
|
||||
{
|
||||
}
|
||||
|
||||
binder2(Handler& handler, const Arg1& arg1, const Arg2& arg2)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_),
|
||||
static_cast<const Arg2&>(arg2_));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
handler_(arg1_, arg2_);
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
Arg2 arg2_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline bool asio_handler_is_continuation(
|
||||
binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
binder2<Handler, Arg1, Arg2>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2>
|
||||
inline binder2<Handler, Arg1, Arg2> bind_handler(Handler handler,
|
||||
const Arg1& arg1, const Arg2& arg2)
|
||||
{
|
||||
return binder2<Handler, Arg1, Arg2>(handler, arg1, arg2);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
|
||||
class binder3
|
||||
{
|
||||
public:
|
||||
binder3(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
|
||||
const Arg3& arg3)
|
||||
: handler_(handler),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3)
|
||||
{
|
||||
}
|
||||
|
||||
binder3(Handler& handler, const Arg1& arg1, const Arg2& arg2,
|
||||
const Arg3& arg3)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_),
|
||||
static_cast<const Arg2&>(arg2_),
|
||||
static_cast<const Arg3&>(arg3_));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
handler_(arg1_, arg2_, arg3_);
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
Arg2 arg2_;
|
||||
Arg3 arg3_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
|
||||
inline bool asio_handler_is_continuation(
|
||||
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
|
||||
inline binder3<Handler, Arg1, Arg2, Arg3> bind_handler(Handler handler,
|
||||
const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
|
||||
{
|
||||
return binder3<Handler, Arg1, Arg2, Arg3>(handler, arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
|
||||
typename Arg4>
|
||||
class binder4
|
||||
{
|
||||
public:
|
||||
binder4(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
|
||||
const Arg3& arg3, const Arg4& arg4)
|
||||
: handler_(handler),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3),
|
||||
arg4_(arg4)
|
||||
{
|
||||
}
|
||||
|
||||
binder4(Handler& handler, const Arg1& arg1, const Arg2& arg2,
|
||||
const Arg3& arg3, const Arg4& arg4)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3),
|
||||
arg4_(arg4)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_),
|
||||
static_cast<const Arg2&>(arg2_),
|
||||
static_cast<const Arg3&>(arg3_),
|
||||
static_cast<const Arg4&>(arg4_));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
handler_(arg1_, arg2_, arg3_, arg4_);
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
Arg2 arg2_;
|
||||
Arg3 arg3_;
|
||||
Arg4 arg4_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
|
||||
typename Arg4>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
|
||||
typename Arg4>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
|
||||
typename Arg4>
|
||||
inline bool asio_handler_is_continuation(
|
||||
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3, typename Arg4>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3, typename Arg4>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
|
||||
typename Arg4>
|
||||
inline binder4<Handler, Arg1, Arg2, Arg3, Arg4> bind_handler(
|
||||
Handler handler, const Arg1& arg1, const Arg2& arg2,
|
||||
const Arg3& arg3, const Arg4& arg4)
|
||||
{
|
||||
return binder4<Handler, Arg1, Arg2, Arg3, Arg4>(handler, arg1, arg2, arg3,
|
||||
arg4);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
|
||||
typename Arg4, typename Arg5>
|
||||
class binder5
|
||||
{
|
||||
public:
|
||||
binder5(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
|
||||
const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
|
||||
: handler_(handler),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3),
|
||||
arg4_(arg4),
|
||||
arg5_(arg5)
|
||||
{
|
||||
}
|
||||
|
||||
binder5(Handler& handler, const Arg1& arg1, const Arg2& arg2,
|
||||
const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
|
||||
: handler_(ASIO_MOVE_CAST(Handler)(handler)),
|
||||
arg1_(arg1),
|
||||
arg2_(arg2),
|
||||
arg3_(arg3),
|
||||
arg4_(arg4),
|
||||
arg5_(arg5)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_(static_cast<const Arg1&>(arg1_),
|
||||
static_cast<const Arg2&>(arg2_),
|
||||
static_cast<const Arg3&>(arg3_),
|
||||
static_cast<const Arg4&>(arg4_),
|
||||
static_cast<const Arg5&>(arg5_));
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
handler_(arg1_, arg2_, arg3_, arg4_, arg5_);
|
||||
}
|
||||
|
||||
//private:
|
||||
Handler handler_;
|
||||
Arg1 arg1_;
|
||||
Arg2 arg2_;
|
||||
Arg3 arg3_;
|
||||
Arg4 arg4_;
|
||||
Arg5 arg5_;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
|
||||
typename Arg4, typename Arg5>
|
||||
inline void* asio_handler_allocate(std::size_t size,
|
||||
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
|
||||
{
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
|
||||
typename Arg4, typename Arg5>
|
||||
inline void asio_handler_deallocate(void* pointer, std::size_t size,
|
||||
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
|
||||
typename Arg4, typename Arg5>
|
||||
inline bool asio_handler_is_continuation(
|
||||
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
|
||||
{
|
||||
return asio_handler_cont_helpers::is_continuation(
|
||||
this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3, typename Arg4, typename Arg5>
|
||||
inline void asio_handler_invoke(Function& function,
|
||||
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Function, typename Handler, typename Arg1, typename Arg2,
|
||||
typename Arg3, typename Arg4, typename Arg5>
|
||||
inline void asio_handler_invoke(const Function& function,
|
||||
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
|
||||
typename Arg4, typename Arg5>
|
||||
inline binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5> bind_handler(
|
||||
Handler handler, const Arg1& arg1, const Arg2& arg2,
|
||||
const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
|
||||
{
|
||||
return binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>(handler, arg1, arg2,
|
||||
arg3, arg4, arg5);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_BIND_HANDLER_HPP
|
|
@ -1,66 +0,0 @@
|
|||
//
|
||||
// detail/buffer_resize_guard.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
|
||||
#define ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/detail/limits.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// Helper class to manage buffer resizing in an exception safe way.
|
||||
template <typename Buffer>
|
||||
class buffer_resize_guard
|
||||
{
|
||||
public:
|
||||
// Constructor.
|
||||
buffer_resize_guard(Buffer& buffer)
|
||||
: buffer_(buffer),
|
||||
old_size_(buffer.size())
|
||||
{
|
||||
}
|
||||
|
||||
// Destructor rolls back the buffer resize unless commit was called.
|
||||
~buffer_resize_guard()
|
||||
{
|
||||
if (old_size_ != (std::numeric_limits<size_t>::max)())
|
||||
{
|
||||
buffer_.resize(old_size_);
|
||||
}
|
||||
}
|
||||
|
||||
// Commit the resize transaction.
|
||||
void commit()
|
||||
{
|
||||
old_size_ = (std::numeric_limits<size_t>::max)();
|
||||
}
|
||||
|
||||
private:
|
||||
// The buffer being managed.
|
||||
Buffer& buffer_;
|
||||
|
||||
// The size of the buffer at the time the guard was constructed.
|
||||
size_t old_size_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
|
|
@ -1,383 +0,0 @@
|
|||
//
|
||||
// detail/buffer_sequence_adapter.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP
|
||||
#define ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/array_fwd.hpp"
|
||||
#include "asio/detail/socket_types.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class buffer_sequence_adapter_base
|
||||
{
|
||||
protected:
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
// The maximum number of buffers to support in a single operation.
|
||||
enum { max_buffers = 1 };
|
||||
|
||||
typedef Windows::Storage::Streams::IBuffer^ native_buffer_type;
|
||||
|
||||
ASIO_DECL static void init_native_buffer(
|
||||
native_buffer_type& buf,
|
||||
const asio::mutable_buffer& buffer);
|
||||
|
||||
ASIO_DECL static void init_native_buffer(
|
||||
native_buffer_type& buf,
|
||||
const asio::const_buffer& buffer);
|
||||
#elif defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
// The maximum number of buffers to support in a single operation.
|
||||
enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len };
|
||||
|
||||
typedef WSABUF native_buffer_type;
|
||||
|
||||
static void init_native_buffer(WSABUF& buf,
|
||||
const asio::mutable_buffer& buffer)
|
||||
{
|
||||
buf.buf = asio::buffer_cast<char*>(buffer);
|
||||
buf.len = static_cast<ULONG>(asio::buffer_size(buffer));
|
||||
}
|
||||
|
||||
static void init_native_buffer(WSABUF& buf,
|
||||
const asio::const_buffer& buffer)
|
||||
{
|
||||
buf.buf = const_cast<char*>(asio::buffer_cast<const char*>(buffer));
|
||||
buf.len = static_cast<ULONG>(asio::buffer_size(buffer));
|
||||
}
|
||||
#else // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
// The maximum number of buffers to support in a single operation.
|
||||
enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len };
|
||||
|
||||
typedef iovec native_buffer_type;
|
||||
|
||||
static void init_iov_base(void*& base, void* addr)
|
||||
{
|
||||
base = addr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void init_iov_base(T& base, void* addr)
|
||||
{
|
||||
base = static_cast<T>(addr);
|
||||
}
|
||||
|
||||
static void init_native_buffer(iovec& iov,
|
||||
const asio::mutable_buffer& buffer)
|
||||
{
|
||||
init_iov_base(iov.iov_base, asio::buffer_cast<void*>(buffer));
|
||||
iov.iov_len = asio::buffer_size(buffer);
|
||||
}
|
||||
|
||||
static void init_native_buffer(iovec& iov,
|
||||
const asio::const_buffer& buffer)
|
||||
{
|
||||
init_iov_base(iov.iov_base, const_cast<void*>(
|
||||
asio::buffer_cast<const void*>(buffer)));
|
||||
iov.iov_len = asio::buffer_size(buffer);
|
||||
}
|
||||
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
};
|
||||
|
||||
// Helper class to translate buffers into the native buffer representation.
|
||||
template <typename Buffer, typename Buffers>
|
||||
class buffer_sequence_adapter
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(const Buffers& buffer_sequence)
|
||||
: count_(0), total_buffer_size_(0)
|
||||
{
|
||||
typename Buffers::const_iterator iter = buffer_sequence.begin();
|
||||
typename Buffers::const_iterator end = buffer_sequence.end();
|
||||
for (; iter != end && count_ < max_buffers; ++iter, ++count_)
|
||||
{
|
||||
Buffer buffer(*iter);
|
||||
init_native_buffer(buffers_[count_], buffer);
|
||||
total_buffer_size_ += asio::buffer_size(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return buffers_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return count_;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const Buffers& buffer_sequence)
|
||||
{
|
||||
typename Buffers::const_iterator iter = buffer_sequence.begin();
|
||||
typename Buffers::const_iterator end = buffer_sequence.end();
|
||||
std::size_t i = 0;
|
||||
for (; iter != end && i < max_buffers; ++iter, ++i)
|
||||
if (asio::buffer_size(Buffer(*iter)) > 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void validate(const Buffers& buffer_sequence)
|
||||
{
|
||||
typename Buffers::const_iterator iter = buffer_sequence.begin();
|
||||
typename Buffers::const_iterator end = buffer_sequence.end();
|
||||
for (; iter != end; ++iter)
|
||||
{
|
||||
Buffer buffer(*iter);
|
||||
asio::buffer_cast<const void*>(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
static Buffer first(const Buffers& buffer_sequence)
|
||||
{
|
||||
typename Buffers::const_iterator iter = buffer_sequence.begin();
|
||||
typename Buffers::const_iterator end = buffer_sequence.end();
|
||||
for (; iter != end; ++iter)
|
||||
{
|
||||
Buffer buffer(*iter);
|
||||
if (asio::buffer_size(buffer) != 0)
|
||||
return buffer;
|
||||
}
|
||||
return Buffer();
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffers_[max_buffers];
|
||||
std::size_t count_;
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
template <typename Buffer>
|
||||
class buffer_sequence_adapter<Buffer, asio::mutable_buffers_1>
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(
|
||||
const asio::mutable_buffers_1& buffer_sequence)
|
||||
{
|
||||
init_native_buffer(buffer_, Buffer(buffer_sequence));
|
||||
total_buffer_size_ = asio::buffer_size(buffer_sequence);
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return &buffer_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const asio::mutable_buffers_1& buffer_sequence)
|
||||
{
|
||||
return asio::buffer_size(buffer_sequence) == 0;
|
||||
}
|
||||
|
||||
static void validate(const asio::mutable_buffers_1& buffer_sequence)
|
||||
{
|
||||
asio::buffer_cast<const void*>(buffer_sequence);
|
||||
}
|
||||
|
||||
static Buffer first(const asio::mutable_buffers_1& buffer_sequence)
|
||||
{
|
||||
return Buffer(buffer_sequence);
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffer_;
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
template <typename Buffer>
|
||||
class buffer_sequence_adapter<Buffer, asio::const_buffers_1>
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(
|
||||
const asio::const_buffers_1& buffer_sequence)
|
||||
{
|
||||
init_native_buffer(buffer_, Buffer(buffer_sequence));
|
||||
total_buffer_size_ = asio::buffer_size(buffer_sequence);
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return &buffer_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const asio::const_buffers_1& buffer_sequence)
|
||||
{
|
||||
return asio::buffer_size(buffer_sequence) == 0;
|
||||
}
|
||||
|
||||
static void validate(const asio::const_buffers_1& buffer_sequence)
|
||||
{
|
||||
asio::buffer_cast<const void*>(buffer_sequence);
|
||||
}
|
||||
|
||||
static Buffer first(const asio::const_buffers_1& buffer_sequence)
|
||||
{
|
||||
return Buffer(buffer_sequence);
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffer_;
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
template <typename Buffer, typename Elem>
|
||||
class buffer_sequence_adapter<Buffer, boost::array<Elem, 2> >
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(
|
||||
const boost::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
init_native_buffer(buffers_[0], Buffer(buffer_sequence[0]));
|
||||
init_native_buffer(buffers_[1], Buffer(buffer_sequence[1]));
|
||||
total_buffer_size_ = asio::buffer_size(buffer_sequence[0])
|
||||
+ asio::buffer_size(buffer_sequence[1]);
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return buffers_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const boost::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
return asio::buffer_size(buffer_sequence[0]) == 0
|
||||
&& asio::buffer_size(buffer_sequence[1]) == 0;
|
||||
}
|
||||
|
||||
static void validate(const boost::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
asio::buffer_cast<const void*>(buffer_sequence[0]);
|
||||
asio::buffer_cast<const void*>(buffer_sequence[1]);
|
||||
}
|
||||
|
||||
static Buffer first(const boost::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
return Buffer(asio::buffer_size(buffer_sequence[0]) != 0
|
||||
? buffer_sequence[0] : buffer_sequence[1]);
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffers_[2];
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
template <typename Buffer, typename Elem>
|
||||
class buffer_sequence_adapter<Buffer, std::array<Elem, 2> >
|
||||
: buffer_sequence_adapter_base
|
||||
{
|
||||
public:
|
||||
explicit buffer_sequence_adapter(
|
||||
const std::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
init_native_buffer(buffers_[0], Buffer(buffer_sequence[0]));
|
||||
init_native_buffer(buffers_[1], Buffer(buffer_sequence[1]));
|
||||
total_buffer_size_ = asio::buffer_size(buffer_sequence[0])
|
||||
+ asio::buffer_size(buffer_sequence[1]);
|
||||
}
|
||||
|
||||
native_buffer_type* buffers()
|
||||
{
|
||||
return buffers_;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
bool all_empty() const
|
||||
{
|
||||
return total_buffer_size_ == 0;
|
||||
}
|
||||
|
||||
static bool all_empty(const std::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
return asio::buffer_size(buffer_sequence[0]) == 0
|
||||
&& asio::buffer_size(buffer_sequence[1]) == 0;
|
||||
}
|
||||
|
||||
static void validate(const std::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
asio::buffer_cast<const void*>(buffer_sequence[0]);
|
||||
asio::buffer_cast<const void*>(buffer_sequence[1]);
|
||||
}
|
||||
|
||||
static Buffer first(const std::array<Elem, 2>& buffer_sequence)
|
||||
{
|
||||
return Buffer(asio::buffer_size(buffer_sequence[0]) != 0
|
||||
? buffer_sequence[0] : buffer_sequence[1]);
|
||||
}
|
||||
|
||||
private:
|
||||
native_buffer_type buffers_[2];
|
||||
std::size_t total_buffer_size_;
|
||||
};
|
||||
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if defined(ASIO_HEADER_ONLY)
|
||||
# include "asio/detail/impl/buffer_sequence_adapter.ipp"
|
||||
#endif // defined(ASIO_HEADER_ONLY)
|
||||
|
||||
#endif // ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP
|
|
@ -1,126 +0,0 @@
|
|||
//
|
||||
// detail/buffered_stream_storage.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
|
||||
#define ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/assert.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class buffered_stream_storage
|
||||
{
|
||||
public:
|
||||
// The type of the bytes stored in the buffer.
|
||||
typedef unsigned char byte_type;
|
||||
|
||||
// The type used for offsets into the buffer.
|
||||
typedef std::size_t size_type;
|
||||
|
||||
// Constructor.
|
||||
explicit buffered_stream_storage(std::size_t buffer_capacity)
|
||||
: begin_offset_(0),
|
||||
end_offset_(0),
|
||||
buffer_(buffer_capacity)
|
||||
{
|
||||
}
|
||||
|
||||
/// Clear the buffer.
|
||||
void clear()
|
||||
{
|
||||
begin_offset_ = 0;
|
||||
end_offset_ = 0;
|
||||
}
|
||||
|
||||
// Return a pointer to the beginning of the unread data.
|
||||
mutable_buffer data()
|
||||
{
|
||||
return asio::buffer(buffer_) + begin_offset_;
|
||||
}
|
||||
|
||||
// Return a pointer to the beginning of the unread data.
|
||||
const_buffer data() const
|
||||
{
|
||||
return asio::buffer(buffer_) + begin_offset_;
|
||||
}
|
||||
|
||||
// Is there no unread data in the buffer.
|
||||
bool empty() const
|
||||
{
|
||||
return begin_offset_ == end_offset_;
|
||||
}
|
||||
|
||||
// Return the amount of unread data the is in the buffer.
|
||||
size_type size() const
|
||||
{
|
||||
return end_offset_ - begin_offset_;
|
||||
}
|
||||
|
||||
// Resize the buffer to the specified length.
|
||||
void resize(size_type length)
|
||||
{
|
||||
ASIO_ASSERT(length <= capacity());
|
||||
if (begin_offset_ + length <= capacity())
|
||||
{
|
||||
end_offset_ = begin_offset_ + length;
|
||||
}
|
||||
else
|
||||
{
|
||||
using namespace std; // For memmove.
|
||||
memmove(&buffer_[0], &buffer_[0] + begin_offset_, size());
|
||||
end_offset_ = length;
|
||||
begin_offset_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the maximum size for data in the buffer.
|
||||
size_type capacity() const
|
||||
{
|
||||
return buffer_.size();
|
||||
}
|
||||
|
||||
// Consume multiple bytes from the beginning of the buffer.
|
||||
void consume(size_type count)
|
||||
{
|
||||
ASIO_ASSERT(begin_offset_ + count <= end_offset_);
|
||||
begin_offset_ += count;
|
||||
if (empty())
|
||||
clear();
|
||||
}
|
||||
|
||||
private:
|
||||
// The offset to the beginning of the unread data.
|
||||
size_type begin_offset_;
|
||||
|
||||
// The offset to the end of the unread data.
|
||||
size_type end_offset_;
|
||||
|
||||
// The data in the buffer.
|
||||
std::vector<byte_type> buffer_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
|
|
@ -1,125 +0,0 @@
|
|||
//
|
||||
// detail/call_stack.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_CALL_STACK_HPP
|
||||
#define ASIO_DETAIL_CALL_STACK_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/tss_ptr.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// Helper class to determine whether or not the current thread is inside an
|
||||
// invocation of io_service::run() for a specified io_service object.
|
||||
template <typename Key, typename Value = unsigned char>
|
||||
class call_stack
|
||||
{
|
||||
public:
|
||||
// Context class automatically pushes the key/value pair on to the stack.
|
||||
class context
|
||||
: private noncopyable
|
||||
{
|
||||
public:
|
||||
// Push the key on to the stack.
|
||||
explicit context(Key* k)
|
||||
: key_(k),
|
||||
next_(call_stack<Key, Value>::top_)
|
||||
{
|
||||
value_ = reinterpret_cast<unsigned char*>(this);
|
||||
call_stack<Key, Value>::top_ = this;
|
||||
}
|
||||
|
||||
// Push the key/value pair on to the stack.
|
||||
context(Key* k, Value& v)
|
||||
: key_(k),
|
||||
value_(&v),
|
||||
next_(call_stack<Key, Value>::top_)
|
||||
{
|
||||
call_stack<Key, Value>::top_ = this;
|
||||
}
|
||||
|
||||
// Pop the key/value pair from the stack.
|
||||
~context()
|
||||
{
|
||||
call_stack<Key, Value>::top_ = next_;
|
||||
}
|
||||
|
||||
// Find the next context with the same key.
|
||||
Value* next_by_key() const
|
||||
{
|
||||
context* elem = next_;
|
||||
while (elem)
|
||||
{
|
||||
if (elem->key_ == key_)
|
||||
return elem->value_;
|
||||
elem = elem->next_;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class call_stack<Key, Value>;
|
||||
|
||||
// The key associated with the context.
|
||||
Key* key_;
|
||||
|
||||
// The value associated with the context.
|
||||
Value* value_;
|
||||
|
||||
// The next element in the stack.
|
||||
context* next_;
|
||||
};
|
||||
|
||||
friend class context;
|
||||
|
||||
// Determine whether the specified owner is on the stack. Returns address of
|
||||
// key if present, 0 otherwise.
|
||||
static Value* contains(Key* k)
|
||||
{
|
||||
context* elem = top_;
|
||||
while (elem)
|
||||
{
|
||||
if (elem->key_ == k)
|
||||
return elem->value_;
|
||||
elem = elem->next_;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Obtain the value at the top of the stack.
|
||||
static Value* top()
|
||||
{
|
||||
context* elem = top_;
|
||||
return elem ? elem->value_ : 0;
|
||||
}
|
||||
|
||||
private:
|
||||
// The top of the stack of calls for the current thread.
|
||||
static tss_ptr<context> top_;
|
||||
};
|
||||
|
||||
template <typename Key, typename Value>
|
||||
tss_ptr<typename call_stack<Key, Value>::context>
|
||||
call_stack<Key, Value>::top_;
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_CALL_STACK_HPP
|
|
@ -1,190 +0,0 @@
|
|||
//
|
||||
// detail/chrono_time_traits.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_CHRONO_TIME_TRAITS_HPP
|
||||
#define ASIO_DETAIL_CHRONO_TIME_TRAITS_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/cstdint.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// Helper template to compute the greatest common divisor.
|
||||
template <int64_t v1, int64_t v2>
|
||||
struct gcd { enum { value = gcd<v2, v1 % v2>::value }; };
|
||||
|
||||
template <int64_t v1>
|
||||
struct gcd<v1, 0> { enum { value = v1 }; };
|
||||
|
||||
// Adapts std::chrono clocks for use with a deadline timer.
|
||||
template <typename Clock, typename WaitTraits>
|
||||
struct chrono_time_traits
|
||||
{
|
||||
// The clock type.
|
||||
typedef Clock clock_type;
|
||||
|
||||
// The duration type of the clock.
|
||||
typedef typename clock_type::duration duration_type;
|
||||
|
||||
// The time point type of the clock.
|
||||
typedef typename clock_type::time_point time_type;
|
||||
|
||||
// The period of the clock.
|
||||
typedef typename duration_type::period period_type;
|
||||
|
||||
// Get the current time.
|
||||
static time_type now()
|
||||
{
|
||||
return clock_type::now();
|
||||
}
|
||||
|
||||
// Add a duration to a time.
|
||||
static time_type add(const time_type& t, const duration_type& d)
|
||||
{
|
||||
const time_type epoch;
|
||||
if (t >= epoch)
|
||||
{
|
||||
if ((time_type::max)() - t < d)
|
||||
return (time_type::max)();
|
||||
}
|
||||
else // t < epoch
|
||||
{
|
||||
if (-(t - (time_type::min)()) > d)
|
||||
return (time_type::min)();
|
||||
}
|
||||
|
||||
return t + d;
|
||||
}
|
||||
|
||||
// Subtract one time from another.
|
||||
static duration_type subtract(const time_type& t1, const time_type& t2)
|
||||
{
|
||||
const time_type epoch;
|
||||
if (t1 >= epoch)
|
||||
{
|
||||
if (t2 >= epoch)
|
||||
{
|
||||
return t1 - t2;
|
||||
}
|
||||
else if (t2 == (time_type::min)())
|
||||
{
|
||||
return (duration_type::max)();
|
||||
}
|
||||
else if ((time_type::max)() - t1 < epoch - t2)
|
||||
{
|
||||
return (duration_type::max)();
|
||||
}
|
||||
else
|
||||
{
|
||||
return t1 - t2;
|
||||
}
|
||||
}
|
||||
else // t1 < epoch
|
||||
{
|
||||
if (t2 < epoch)
|
||||
{
|
||||
return t1 - t2;
|
||||
}
|
||||
else if (t1 == (time_type::min)())
|
||||
{
|
||||
return (duration_type::min)();
|
||||
}
|
||||
else if ((time_type::max)() - t2 < epoch - t1)
|
||||
{
|
||||
return (duration_type::min)();
|
||||
}
|
||||
else
|
||||
{
|
||||
return -(t2 - t1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test whether one time is less than another.
|
||||
static bool less_than(const time_type& t1, const time_type& t2)
|
||||
{
|
||||
return t1 < t2;
|
||||
}
|
||||
|
||||
// Implement just enough of the posix_time::time_duration interface to supply
|
||||
// what the timer_queue requires.
|
||||
class posix_time_duration
|
||||
{
|
||||
public:
|
||||
explicit posix_time_duration(const duration_type& d)
|
||||
: d_(d)
|
||||
{
|
||||
}
|
||||
|
||||
int64_t ticks() const
|
||||
{
|
||||
return d_.count();
|
||||
}
|
||||
|
||||
int64_t total_seconds() const
|
||||
{
|
||||
return duration_cast<1, 1>();
|
||||
}
|
||||
|
||||
int64_t total_milliseconds() const
|
||||
{
|
||||
return duration_cast<1, 1000>();
|
||||
}
|
||||
|
||||
int64_t total_microseconds() const
|
||||
{
|
||||
return duration_cast<1, 1000000>();
|
||||
}
|
||||
|
||||
private:
|
||||
template <int64_t Num, int64_t Den>
|
||||
int64_t duration_cast() const
|
||||
{
|
||||
const int64_t num1 = period_type::num / gcd<period_type::num, Num>::value;
|
||||
const int64_t num2 = Num / gcd<period_type::num, Num>::value;
|
||||
|
||||
const int64_t den1 = period_type::den / gcd<period_type::den, Den>::value;
|
||||
const int64_t den2 = Den / gcd<period_type::den, Den>::value;
|
||||
|
||||
const int64_t num = num1 * den2;
|
||||
const int64_t den = num2 * den1;
|
||||
|
||||
if (num == 1 && den == 1)
|
||||
return ticks();
|
||||
else if (num != 1 && den == 1)
|
||||
return ticks() * num;
|
||||
else if (num == 1 && period_type::den != 1)
|
||||
return ticks() / den;
|
||||
else
|
||||
return ticks() * num / den;
|
||||
}
|
||||
|
||||
duration_type d_;
|
||||
};
|
||||
|
||||
// Convert to POSIX duration type.
|
||||
static posix_time_duration to_posix_duration(const duration_type& d)
|
||||
{
|
||||
return posix_time_duration(WaitTraits::to_wait_duration(d));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_CHRONO_TIME_TRAITS_HPP
|
|
@ -1,81 +0,0 @@
|
|||
//
|
||||
// detail/completion_handler.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_COMPLETION_HANDLER_HPP
|
||||
#define ASIO_DETAIL_COMPLETION_HANDLER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/addressof.hpp"
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/detail/fenced_block.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/operation.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename Handler>
|
||||
class completion_handler : public operation
|
||||
{
|
||||
public:
|
||||
ASIO_DEFINE_HANDLER_PTR(completion_handler);
|
||||
|
||||
completion_handler(Handler& h)
|
||||
: operation(&completion_handler::do_complete),
|
||||
handler_(ASIO_MOVE_CAST(Handler)(h))
|
||||
{
|
||||
}
|
||||
|
||||
static void do_complete(io_service_impl* owner, operation* base,
|
||||
const asio::error_code& /*ec*/,
|
||||
std::size_t /*bytes_transferred*/)
|
||||
{
|
||||
// Take ownership of the handler object.
|
||||
completion_handler* h(static_cast<completion_handler*>(base));
|
||||
ptr p = { asio::detail::addressof(h->handler_), h, h };
|
||||
|
||||
ASIO_HANDLER_COMPLETION((h));
|
||||
|
||||
// Make a copy of the handler so that the memory can be deallocated before
|
||||
// the upcall is made. Even if we're not about to make an upcall, a
|
||||
// sub-object of the handler may be the true owner of the memory associated
|
||||
// with the handler. Consequently, a local copy of the handler is required
|
||||
// to ensure that any owning sub-object remains valid until after we have
|
||||
// deallocated the memory here.
|
||||
Handler handler(ASIO_MOVE_CAST(Handler)(h->handler_));
|
||||
p.h = asio::detail::addressof(handler);
|
||||
p.reset();
|
||||
|
||||
// Make the upcall if required.
|
||||
if (owner)
|
||||
{
|
||||
fenced_block b(fenced_block::half);
|
||||
ASIO_HANDLER_INVOCATION_BEGIN(());
|
||||
asio_handler_invoke_helpers::invoke(handler, handler);
|
||||
ASIO_HANDLER_INVOCATION_END;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Handler handler_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_COMPLETION_HANDLER_HPP
|
|
@ -1,895 +0,0 @@
|
|||
//
|
||||
// detail/config.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_CONFIG_HPP
|
||||
#define ASIO_DETAIL_CONFIG_HPP
|
||||
|
||||
#if defined(ASIO_STANDALONE)
|
||||
# define ASIO_DISABLE_BOOST_ARRAY 1
|
||||
# define ASIO_DISABLE_BOOST_ASSERT 1
|
||||
# define ASIO_DISABLE_BOOST_BIND 1
|
||||
# define ASIO_DISABLE_BOOST_CHRONO 1
|
||||
# define ASIO_DISABLE_BOOST_DATE_TIME 1
|
||||
# define ASIO_DISABLE_BOOST_LIMITS 1
|
||||
# define ASIO_DISABLE_BOOST_REGEX 1
|
||||
# define ASIO_DISABLE_BOOST_STATIC_CONSTANT 1
|
||||
# define ASIO_DISABLE_BOOST_THROW_EXCEPTION 1
|
||||
# define ASIO_DISABLE_BOOST_WORKAROUND 1
|
||||
#else // defined(ASIO_STANDALONE)
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/version.hpp>
|
||||
# define ASIO_HAS_BOOST_CONFIG 1
|
||||
#endif // defined(ASIO_STANDALONE)
|
||||
|
||||
// Default to a header-only implementation. The user must specifically request
|
||||
// separate compilation by defining either ASIO_SEPARATE_COMPILATION or
|
||||
// ASIO_DYN_LINK (as a DLL/shared library implies separate compilation).
|
||||
#if !defined(ASIO_HEADER_ONLY)
|
||||
# if !defined(ASIO_SEPARATE_COMPILATION)
|
||||
# if !defined(ASIO_DYN_LINK)
|
||||
# define ASIO_HEADER_ONLY 1
|
||||
# endif // !defined(ASIO_DYN_LINK)
|
||||
# endif // !defined(ASIO_SEPARATE_COMPILATION)
|
||||
#endif // !defined(ASIO_HEADER_ONLY)
|
||||
|
||||
#if defined(ASIO_HEADER_ONLY)
|
||||
# define ASIO_DECL inline
|
||||
#else // defined(ASIO_HEADER_ONLY)
|
||||
# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CODEGEARC__)
|
||||
// We need to import/export our code only if the user has specifically asked
|
||||
// for it by defining ASIO_DYN_LINK.
|
||||
# if defined(ASIO_DYN_LINK)
|
||||
// Export if this is our own source, otherwise import.
|
||||
# if defined(ASIO_SOURCE)
|
||||
# define ASIO_DECL __declspec(dllexport)
|
||||
# else // defined(ASIO_SOURCE)
|
||||
# define ASIO_DECL __declspec(dllimport)
|
||||
# endif // defined(ASIO_SOURCE)
|
||||
# endif // defined(ASIO_DYN_LINK)
|
||||
# endif // defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CODEGEARC__)
|
||||
#endif // defined(ASIO_HEADER_ONLY)
|
||||
|
||||
// If ASIO_DECL isn't defined yet define it now.
|
||||
#if !defined(ASIO_DECL)
|
||||
# define ASIO_DECL
|
||||
#endif // !defined(ASIO_DECL)
|
||||
|
||||
// Microsoft Visual C++ detection.
|
||||
#if !defined(ASIO_MSVC)
|
||||
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_MSVC)
|
||||
# define ASIO_MSVC BOOST_MSVC
|
||||
# elif defined(_MSC_VER) && !defined(__MWERKS__) && !defined(__EDG_VERSION__)
|
||||
# define ASIO_MSVC _MSC_VER
|
||||
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_MSVC)
|
||||
#endif // defined(ASIO_MSVC)
|
||||
|
||||
// Clang / libc++ detection.
|
||||
#if defined(__clang__)
|
||||
# if (__cplusplus >= 201103)
|
||||
# if __has_include(<__config>)
|
||||
# include <__config>
|
||||
# if defined(_LIBCPP_VERSION)
|
||||
# define ASIO_HAS_CLANG_LIBCXX 1
|
||||
# endif // defined(_LIBCPP_VERSION)
|
||||
# endif // __has_include(<__config>)
|
||||
# endif // (__cplusplus >= 201103)
|
||||
#endif // defined(__clang__)
|
||||
|
||||
// Support move construction and assignment on compilers known to allow it.
|
||||
#if !defined(ASIO_HAS_MOVE)
|
||||
# if !defined(ASIO_DISABLE_MOVE)
|
||||
# if defined(__clang__)
|
||||
# if __has_feature(__cxx_rvalue_references__)
|
||||
# define ASIO_HAS_MOVE 1
|
||||
# endif // __has_feature(__cxx_rvalue_references__)
|
||||
# endif // defined(__clang__)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_MOVE 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_MOVE 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_MOVE)
|
||||
#endif // !defined(ASIO_HAS_MOVE)
|
||||
|
||||
// If ASIO_MOVE_CAST isn't defined, and move support is available, define
|
||||
// ASIO_MOVE_ARG and ASIO_MOVE_CAST to take advantage of rvalue
|
||||
// references and perfect forwarding.
|
||||
#if defined(ASIO_HAS_MOVE) && !defined(ASIO_MOVE_CAST)
|
||||
# define ASIO_MOVE_ARG(type) type&&
|
||||
# define ASIO_MOVE_CAST(type) static_cast<type&&>
|
||||
# define ASIO_MOVE_CAST2(type1, type2) static_cast<type1, type2&&>
|
||||
#endif // defined(ASIO_HAS_MOVE) && !defined(ASIO_MOVE_CAST)
|
||||
|
||||
// If ASIO_MOVE_CAST still isn't defined, default to a C++03-compatible
|
||||
// implementation. Note that older g++ and MSVC versions don't like it when you
|
||||
// pass a non-member function through a const reference, so for most compilers
|
||||
// we'll play it safe and stick with the old approach of passing the handler by
|
||||
// value.
|
||||
#if !defined(ASIO_MOVE_CAST)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)) || (__GNUC__ > 4)
|
||||
# define ASIO_MOVE_ARG(type) const type&
|
||||
# else // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)) || (__GNUC__ > 4)
|
||||
# define ASIO_MOVE_ARG(type) type
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)) || (__GNUC__ > 4)
|
||||
# elif defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1400)
|
||||
# define ASIO_MOVE_ARG(type) const type&
|
||||
# else // (_MSC_VER >= 1400)
|
||||
# define ASIO_MOVE_ARG(type) type
|
||||
# endif // (_MSC_VER >= 1400)
|
||||
# else
|
||||
# define ASIO_MOVE_ARG(type) type
|
||||
# endif
|
||||
# define ASIO_MOVE_CAST(type) static_cast<const type&>
|
||||
# define ASIO_MOVE_CAST2(type1, type2) static_cast<const type1, type2&>
|
||||
#endif // !defined(ASIO_MOVE_CAST)
|
||||
|
||||
// Support variadic templates on compilers known to allow it.
|
||||
#if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
# if !defined(ASIO_DISABLE_VARIADIC_TEMPLATES)
|
||||
# if defined(__clang__)
|
||||
# if __has_feature(__cxx_variadic_templates__)
|
||||
# define ASIO_HAS_VARIADIC_TEMPLATES 1
|
||||
# endif // __has_feature(__cxx_variadic_templates__)
|
||||
# endif // defined(__clang__)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_VARIADIC_TEMPLATES 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# endif // !defined(ASIO_DISABLE_VARIADIC_TEMPLATES)
|
||||
#endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
// Support constexpr on compilers known to allow it.
|
||||
#if !defined(ASIO_HAS_CONSTEXPR)
|
||||
# if !defined(ASIO_DISABLE_CONSTEXPR)
|
||||
# if defined(__clang__)
|
||||
# if __has_feature(__cxx_constexpr__)
|
||||
# define ASIO_HAS_CONSTEXPR 1
|
||||
# endif // __has_feature(__cxx_constexr__)
|
||||
# endif // defined(__clang__)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_CONSTEXPR 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# endif // !defined(ASIO_DISABLE_CONSTEXPR)
|
||||
#endif // !defined(ASIO_HAS_CONSTEXPR)
|
||||
#if !defined(ASIO_CONSTEXPR)
|
||||
# if defined(ASIO_HAS_CONSTEXPR)
|
||||
# define ASIO_CONSTEXPR constexpr
|
||||
# else // defined(ASIO_HAS_CONSTEXPR)
|
||||
# define ASIO_CONSTEXPR
|
||||
# endif // defined(ASIO_HAS_CONSTEXPR)
|
||||
#endif // !defined(ASIO_CONSTEXPR)
|
||||
|
||||
// Standard library support for system errors.
|
||||
#if !defined(ASIO_HAS_STD_SYSTEM_ERROR)
|
||||
# if !defined(ASIO_DISABLE_STD_SYSTEM_ERROR)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_STD_SYSTEM_ERROR 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_STD_SYSTEM_ERROR 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_STD_SYSTEM_ERROR 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_SYSTEM_ERROR)
|
||||
#endif // !defined(ASIO_HAS_STD_SYSTEM_ERROR)
|
||||
|
||||
// Compliant C++11 compilers put noexcept specifiers on error_category members.
|
||||
#if !defined(ASIO_ERROR_CATEGORY_NOEXCEPT)
|
||||
# if (BOOST_VERSION >= 105300)
|
||||
# define ASIO_ERROR_CATEGORY_NOEXCEPT BOOST_NOEXCEPT
|
||||
# elif defined(__clang__)
|
||||
# if __has_feature(__cxx_noexcept__)
|
||||
# define ASIO_ERROR_CATEGORY_NOEXCEPT noexcept(true)
|
||||
# endif // __has_feature(__cxx_noexcept__)
|
||||
# elif defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_ERROR_CATEGORY_NOEXCEPT noexcept(true)
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if !defined(ASIO_ERROR_CATEGORY_NOEXCEPT)
|
||||
# define ASIO_ERROR_CATEGORY_NOEXCEPT
|
||||
# endif // !defined(ASIO_ERROR_CATEGORY_NOEXCEPT)
|
||||
#endif // !defined(ASIO_ERROR_CATEGORY_NOEXCEPT)
|
||||
|
||||
// Standard library support for arrays.
|
||||
#if !defined(ASIO_HAS_STD_ARRAY)
|
||||
# if !defined(ASIO_DISABLE_STD_ARRAY)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_STD_ARRAY 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_STD_ARRAY 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1600)
|
||||
# define ASIO_HAS_STD_ARRAY 1
|
||||
# endif // (_MSC_VER >= 1600)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_ARRAY)
|
||||
#endif // !defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
// Standard library support for shared_ptr and weak_ptr.
|
||||
#if !defined(ASIO_HAS_STD_SHARED_PTR)
|
||||
# if !defined(ASIO_DISABLE_STD_SHARED_PTR)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_STD_SHARED_PTR 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_STD_SHARED_PTR 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1600)
|
||||
# define ASIO_HAS_STD_SHARED_PTR 1
|
||||
# endif // (_MSC_VER >= 1600)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_SHARED_PTR)
|
||||
#endif // !defined(ASIO_HAS_STD_SHARED_PTR)
|
||||
|
||||
// Standard library support for atomic operations.
|
||||
#if !defined(ASIO_HAS_STD_ATOMIC)
|
||||
# if !defined(ASIO_DISABLE_STD_ATOMIC)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_STD_ATOMIC 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_STD_ATOMIC 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_STD_ATOMIC 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_ATOMIC)
|
||||
#endif // !defined(ASIO_HAS_STD_ATOMIC)
|
||||
|
||||
// Standard library support for chrono. Some standard libraries (such as the
|
||||
// libstdc++ shipped with gcc 4.6) provide monotonic_clock as per early C++0x
|
||||
// drafts, rather than the eventually standardised name of steady_clock.
|
||||
#if !defined(ASIO_HAS_STD_CHRONO)
|
||||
# if !defined(ASIO_DISABLE_STD_CHRONO)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_STD_CHRONO 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_STD_CHRONO 1
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
|
||||
# define ASIO_HAS_STD_CHRONO_MONOTONIC_CLOCK 1
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_STD_CHRONO 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_CHRONO)
|
||||
#endif // !defined(ASIO_HAS_STD_CHRONO)
|
||||
|
||||
// Boost support for chrono.
|
||||
#if !defined(ASIO_HAS_BOOST_CHRONO)
|
||||
# if !defined(ASIO_DISABLE_BOOST_CHRONO)
|
||||
# if (BOOST_VERSION >= 104700)
|
||||
# define ASIO_HAS_BOOST_CHRONO 1
|
||||
# endif // (BOOST_VERSION >= 104700)
|
||||
# endif // !defined(ASIO_DISABLE_BOOST_CHRONO)
|
||||
#endif // !defined(ASIO_HAS_BOOST_CHRONO)
|
||||
|
||||
// Boost support for the DateTime library.
|
||||
#if !defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
# if !defined(ASIO_DISABLE_BOOST_DATE_TIME)
|
||||
# define ASIO_HAS_BOOST_DATE_TIME 1
|
||||
# endif // !defined(ASIO_DISABLE_BOOST_DATE_TIME)
|
||||
#endif // !defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
|
||||
// Standard library support for addressof.
|
||||
#if !defined(ASIO_HAS_STD_ADDRESSOF)
|
||||
# if !defined(ASIO_DISABLE_STD_ADDRESSOF)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_STD_ADDRESSOF 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_STD_ADDRESSOF 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_STD_ADDRESSOF 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_ADDRESSOF)
|
||||
#endif // !defined(ASIO_HAS_STD_ADDRESSOF)
|
||||
|
||||
// Standard library support for the function class.
|
||||
#if !defined(ASIO_HAS_STD_FUNCTION)
|
||||
# if !defined(ASIO_DISABLE_STD_FUNCTION)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_STD_FUNCTION 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_STD_FUNCTION 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_STD_FUNCTION 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_FUNCTION)
|
||||
#endif // !defined(ASIO_HAS_STD_FUNCTION)
|
||||
|
||||
// Standard library support for type traits.
|
||||
#if !defined(ASIO_HAS_STD_TYPE_TRAITS)
|
||||
# if !defined(ASIO_DISABLE_STD_TYPE_TRAITS)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_STD_TYPE_TRAITS 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_STD_TYPE_TRAITS 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_STD_TYPE_TRAITS 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_TYPE_TRAITS)
|
||||
#endif // !defined(ASIO_HAS_STD_TYPE_TRAITS)
|
||||
|
||||
// Standard library support for the cstdint header.
|
||||
#if !defined(ASIO_HAS_CSTDINT)
|
||||
# if !defined(ASIO_DISABLE_CSTDINT)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_CSTDINT 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_CSTDINT 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_CSTDINT 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_CSTDINT)
|
||||
#endif // !defined(ASIO_HAS_CSTDINT)
|
||||
|
||||
// Standard library support for the thread class.
|
||||
#if !defined(ASIO_HAS_STD_THREAD)
|
||||
# if !defined(ASIO_DISABLE_STD_THREAD)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_STD_THREAD 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_STD_THREAD 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_STD_THREAD 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_THREAD)
|
||||
#endif // !defined(ASIO_HAS_STD_THREAD)
|
||||
|
||||
// Standard library support for the mutex and condition variable classes.
|
||||
#if !defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR)
|
||||
# if !defined(ASIO_DISABLE_STD_MUTEX_AND_CONDVAR)
|
||||
# if defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# define ASIO_HAS_STD_MUTEX_AND_CONDVAR 1
|
||||
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
|
||||
# if defined(__GNUC__)
|
||||
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
|
||||
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define ASIO_HAS_STD_MUTEX_AND_CONDVAR 1
|
||||
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
|
||||
# endif // defined(__GNUC__)
|
||||
# if defined(ASIO_MSVC)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_STD_MUTEX_AND_CONDVAR 1
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC)
|
||||
# endif // !defined(ASIO_DISABLE_STD_MUTEX_AND_CONDVAR)
|
||||
#endif // !defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR)
|
||||
|
||||
// WinRT target.
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
# if defined(__cplusplus_winrt)
|
||||
# include <winapifamily.h>
|
||||
# if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP)
|
||||
# define ASIO_WINDOWS_RUNTIME 1
|
||||
# endif // WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP)
|
||||
# endif // defined(__cplusplus_winrt)
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
// Windows target. Excludes WinRT.
|
||||
#if !defined(ASIO_WINDOWS)
|
||||
# if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_WINDOWS)
|
||||
# define ASIO_WINDOWS 1
|
||||
# elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
# define ASIO_WINDOWS 1
|
||||
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_WINDOWS)
|
||||
# endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
#endif // !defined(ASIO_WINDOWS)
|
||||
|
||||
// Windows: target OS version.
|
||||
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
# if !defined(_WIN32_WINNT) && !defined(_WIN32_WINDOWS)
|
||||
# if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
# pragma message( \
|
||||
"Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:\n"\
|
||||
"- add -D_WIN32_WINNT=0x0501 to the compiler command line; or\n"\
|
||||
"- add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.\n"\
|
||||
"Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).")
|
||||
# else // defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
# warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately.
|
||||
# warning For example, add -D_WIN32_WINNT=0x0501 to the compiler command line.
|
||||
# warning Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
|
||||
# endif // defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
# define _WIN32_WINNT 0x0501
|
||||
# endif // !defined(_WIN32_WINNT) && !defined(_WIN32_WINDOWS)
|
||||
# if defined(_MSC_VER)
|
||||
# if defined(_WIN32) && !defined(WIN32)
|
||||
# if !defined(_WINSOCK2API_)
|
||||
# define WIN32 // Needed for correct types in winsock2.h
|
||||
# else // !defined(_WINSOCK2API_)
|
||||
# error Please define the macro WIN32 in your compiler options
|
||||
# endif // !defined(_WINSOCK2API_)
|
||||
# endif // defined(_WIN32) && !defined(WIN32)
|
||||
# endif // defined(_MSC_VER)
|
||||
# if defined(__BORLANDC__)
|
||||
# if defined(__WIN32__) && !defined(WIN32)
|
||||
# if !defined(_WINSOCK2API_)
|
||||
# define WIN32 // Needed for correct types in winsock2.h
|
||||
# else // !defined(_WINSOCK2API_)
|
||||
# error Please define the macro WIN32 in your compiler options
|
||||
# endif // !defined(_WINSOCK2API_)
|
||||
# endif // defined(__WIN32__) && !defined(WIN32)
|
||||
# endif // defined(__BORLANDC__)
|
||||
# if defined(__CYGWIN__)
|
||||
# if !defined(__USE_W32_SOCKETS)
|
||||
# error You must add -D__USE_W32_SOCKETS to your compiler options.
|
||||
# endif // !defined(__USE_W32_SOCKETS)
|
||||
# endif // defined(__CYGWIN__)
|
||||
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
|
||||
// Windows: minimise header inclusion.
|
||||
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
# if !defined(ASIO_NO_WIN32_LEAN_AND_MEAN)
|
||||
# if !defined(WIN32_LEAN_AND_MEAN)
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif // !defined(WIN32_LEAN_AND_MEAN)
|
||||
# endif // !defined(ASIO_NO_WIN32_LEAN_AND_MEAN)
|
||||
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
|
||||
// Windows: suppress definition of "min" and "max" macros.
|
||||
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
# if !defined(ASIO_NO_NOMINMAX)
|
||||
# if !defined(NOMINMAX)
|
||||
# define NOMINMAX 1
|
||||
# endif // !defined(NOMINMAX)
|
||||
# endif // !defined(ASIO_NO_NOMINMAX)
|
||||
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
|
||||
// Windows: IO Completion Ports.
|
||||
#if !defined(ASIO_HAS_IOCP)
|
||||
# if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
# if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400)
|
||||
# if !defined(UNDER_CE)
|
||||
# if !defined(ASIO_DISABLE_IOCP)
|
||||
# define ASIO_HAS_IOCP 1
|
||||
# endif // !defined(ASIO_DISABLE_IOCP)
|
||||
# endif // !defined(UNDER_CE)
|
||||
# endif // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400)
|
||||
# endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
#endif // !defined(ASIO_HAS_IOCP)
|
||||
|
||||
// Linux: epoll, eventfd and timerfd.
|
||||
#if defined(__linux__)
|
||||
# include <linux/version.h>
|
||||
# if !defined(ASIO_HAS_EPOLL)
|
||||
# if !defined(ASIO_DISABLE_EPOLL)
|
||||
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,45)
|
||||
# define ASIO_HAS_EPOLL 1
|
||||
# endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,45)
|
||||
# endif // !defined(ASIO_DISABLE_EPOLL)
|
||||
# endif // !defined(ASIO_HAS_EPOLL)
|
||||
# if !defined(ASIO_HAS_EVENTFD)
|
||||
# if !defined(ASIO_DISABLE_EVENTFD)
|
||||
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||
# define ASIO_HAS_EVENTFD 1
|
||||
# endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||
# endif // !defined(ASIO_DISABLE_EVENTFD)
|
||||
# endif // !defined(ASIO_HAS_EVENTFD)
|
||||
# if !defined(ASIO_HAS_TIMERFD)
|
||||
# if defined(ASIO_HAS_EPOLL)
|
||||
# if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8)
|
||||
# define ASIO_HAS_TIMERFD 1
|
||||
# endif // (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8)
|
||||
# endif // defined(ASIO_HAS_EPOLL)
|
||||
# endif // !defined(ASIO_HAS_TIMERFD)
|
||||
#endif // defined(__linux__)
|
||||
|
||||
// Mac OS X, FreeBSD, NetBSD, OpenBSD: kqueue.
|
||||
#if (defined(__MACH__) && defined(__APPLE__)) \
|
||||
|| defined(__FreeBSD__) \
|
||||
|| defined(__NetBSD__) \
|
||||
|| defined(__OpenBSD__)
|
||||
# if !defined(ASIO_HAS_KQUEUE)
|
||||
# if !defined(ASIO_DISABLE_KQUEUE)
|
||||
# define ASIO_HAS_KQUEUE 1
|
||||
# endif // !defined(ASIO_DISABLE_KQUEUE)
|
||||
# endif // !defined(ASIO_HAS_KQUEUE)
|
||||
#endif // (defined(__MACH__) && defined(__APPLE__))
|
||||
// || defined(__FreeBSD__)
|
||||
// || defined(__NetBSD__)
|
||||
// || defined(__OpenBSD__)
|
||||
|
||||
// Solaris: /dev/poll.
|
||||
#if defined(__sun)
|
||||
# if !defined(ASIO_HAS_DEV_POLL)
|
||||
# if !defined(ASIO_DISABLE_DEV_POLL)
|
||||
# define ASIO_HAS_DEV_POLL 1
|
||||
# endif // !defined(ASIO_DISABLE_DEV_POLL)
|
||||
# endif // !defined(ASIO_HAS_DEV_POLL)
|
||||
#endif // defined(__sun)
|
||||
|
||||
// Serial ports.
|
||||
#if !defined(ASIO_HAS_SERIAL_PORT)
|
||||
# if defined(ASIO_HAS_IOCP) \
|
||||
|| !defined(ASIO_WINDOWS) \
|
||||
&& !defined(ASIO_WINDOWS_RUNTIME) \
|
||||
&& !defined(__CYGWIN__)
|
||||
# if !defined(__SYMBIAN32__)
|
||||
# if !defined(ASIO_DISABLE_SERIAL_PORT)
|
||||
# define ASIO_HAS_SERIAL_PORT 1
|
||||
# endif // !defined(ASIO_DISABLE_SERIAL_PORT)
|
||||
# endif // !defined(__SYMBIAN32__)
|
||||
# endif // defined(ASIO_HAS_IOCP)
|
||||
// || !defined(ASIO_WINDOWS)
|
||||
// && !defined(ASIO_WINDOWS_RUNTIME)
|
||||
// && !defined(__CYGWIN__)
|
||||
#endif // !defined(ASIO_HAS_SERIAL_PORT)
|
||||
|
||||
// Windows: stream handles.
|
||||
#if !defined(ASIO_HAS_WINDOWS_STREAM_HANDLE)
|
||||
# if !defined(ASIO_DISABLE_WINDOWS_STREAM_HANDLE)
|
||||
# if defined(ASIO_HAS_IOCP)
|
||||
# define ASIO_HAS_WINDOWS_STREAM_HANDLE 1
|
||||
# endif // defined(ASIO_HAS_IOCP)
|
||||
# endif // !defined(ASIO_DISABLE_WINDOWS_STREAM_HANDLE)
|
||||
#endif // !defined(ASIO_HAS_WINDOWS_STREAM_HANDLE)
|
||||
|
||||
// Windows: random access handles.
|
||||
#if !defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
|
||||
# if !defined(ASIO_DISABLE_WINDOWS_RANDOM_ACCESS_HANDLE)
|
||||
# if defined(ASIO_HAS_IOCP)
|
||||
# define ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE 1
|
||||
# endif // defined(ASIO_HAS_IOCP)
|
||||
# endif // !defined(ASIO_DISABLE_WINDOWS_RANDOM_ACCESS_HANDLE)
|
||||
#endif // !defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
|
||||
|
||||
// Windows: object handles.
|
||||
#if !defined(ASIO_HAS_WINDOWS_OBJECT_HANDLE)
|
||||
# if !defined(ASIO_DISABLE_WINDOWS_OBJECT_HANDLE)
|
||||
# if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
# if !defined(UNDER_CE)
|
||||
# define ASIO_HAS_WINDOWS_OBJECT_HANDLE 1
|
||||
# endif // !defined(UNDER_CE)
|
||||
# endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
# endif // !defined(ASIO_DISABLE_WINDOWS_OBJECT_HANDLE)
|
||||
#endif // !defined(ASIO_HAS_WINDOWS_OBJECT_HANDLE)
|
||||
|
||||
// Windows: OVERLAPPED wrapper.
|
||||
#if !defined(ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
|
||||
# if !defined(ASIO_DISABLE_WINDOWS_OVERLAPPED_PTR)
|
||||
# if defined(ASIO_HAS_IOCP)
|
||||
# define ASIO_HAS_WINDOWS_OVERLAPPED_PTR 1
|
||||
# endif // defined(ASIO_HAS_IOCP)
|
||||
# endif // !defined(ASIO_DISABLE_WINDOWS_OVERLAPPED_PTR)
|
||||
#endif // !defined(ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
|
||||
|
||||
// POSIX: stream-oriented file descriptors.
|
||||
#if !defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
|
||||
# if !defined(ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR)
|
||||
# if !defined(ASIO_WINDOWS) \
|
||||
&& !defined(ASIO_WINDOWS_RUNTIME) \
|
||||
&& !defined(__CYGWIN__)
|
||||
# define ASIO_HAS_POSIX_STREAM_DESCRIPTOR 1
|
||||
# endif // !defined(ASIO_WINDOWS)
|
||||
// && !defined(ASIO_WINDOWS_RUNTIME)
|
||||
// && !defined(__CYGWIN__)
|
||||
# endif // !defined(ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR)
|
||||
#endif // !defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
|
||||
|
||||
// UNIX domain sockets.
|
||||
#if !defined(ASIO_HAS_LOCAL_SOCKETS)
|
||||
# if !defined(ASIO_DISABLE_LOCAL_SOCKETS)
|
||||
# if !defined(ASIO_WINDOWS) \
|
||||
&& !defined(ASIO_WINDOWS_RUNTIME) \
|
||||
&& !defined(__CYGWIN__)
|
||||
# define ASIO_HAS_LOCAL_SOCKETS 1
|
||||
# endif // !defined(ASIO_WINDOWS)
|
||||
// && !defined(ASIO_WINDOWS_RUNTIME)
|
||||
// && !defined(__CYGWIN__)
|
||||
# endif // !defined(ASIO_DISABLE_LOCAL_SOCKETS)
|
||||
#endif // !defined(ASIO_HAS_LOCAL_SOCKETS)
|
||||
|
||||
// Can use sigaction() instead of signal().
|
||||
#if !defined(ASIO_HAS_SIGACTION)
|
||||
# if !defined(ASIO_DISABLE_SIGACTION)
|
||||
# if !defined(ASIO_WINDOWS) \
|
||||
&& !defined(ASIO_WINDOWS_RUNTIME) \
|
||||
&& !defined(__CYGWIN__)
|
||||
# define ASIO_HAS_SIGACTION 1
|
||||
# endif // !defined(ASIO_WINDOWS)
|
||||
// && !defined(ASIO_WINDOWS_RUNTIME)
|
||||
// && !defined(__CYGWIN__)
|
||||
# endif // !defined(ASIO_DISABLE_SIGACTION)
|
||||
#endif // !defined(ASIO_HAS_SIGACTION)
|
||||
|
||||
// Can use signal().
|
||||
#if !defined(ASIO_HAS_SIGNAL)
|
||||
# if !defined(ASIO_DISABLE_SIGNAL)
|
||||
# if !defined(UNDER_CE)
|
||||
# define ASIO_HAS_SIGNAL 1
|
||||
# endif // !defined(UNDER_CE)
|
||||
# endif // !defined(ASIO_DISABLE_SIGNAL)
|
||||
#endif // !defined(ASIO_HAS_SIGNAL)
|
||||
|
||||
// Whether standard iostreams are disabled.
|
||||
#if !defined(ASIO_NO_IOSTREAM)
|
||||
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_NO_IOSTREAM)
|
||||
# define ASIO_NO_IOSTREAM 1
|
||||
# endif // !defined(BOOST_NO_IOSTREAM)
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
// Whether exception handling is disabled.
|
||||
#if !defined(ASIO_NO_EXCEPTIONS)
|
||||
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_NO_EXCEPTIONS)
|
||||
# define ASIO_NO_EXCEPTIONS 1
|
||||
# endif // !defined(BOOST_NO_EXCEPTIONS)
|
||||
#endif // !defined(ASIO_NO_EXCEPTIONS)
|
||||
|
||||
// Whether the typeid operator is supported.
|
||||
#if !defined(ASIO_NO_TYPEID)
|
||||
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_NO_TYPEID)
|
||||
# define ASIO_NO_TYPEID 1
|
||||
# endif // !defined(BOOST_NO_TYPEID)
|
||||
#endif // !defined(ASIO_NO_TYPEID)
|
||||
|
||||
// On POSIX (and POSIX-like) platforms we need to include unistd.h in order to
|
||||
// get access to the various platform feature macros, e.g. to be able to test
|
||||
// for threads support.
|
||||
#if !defined(ASIO_HAS_UNISTD_H)
|
||||
# if !defined(ASIO_HAS_BOOST_CONFIG)
|
||||
# if defined(unix) \
|
||||
|| defined(__unix) \
|
||||
|| defined(_XOPEN_SOURCE) \
|
||||
|| defined(_POSIX_SOURCE) \
|
||||
|| (defined(__MACH__) && defined(__APPLE__)) \
|
||||
|| defined(__FreeBSD__) \
|
||||
|| defined(__NetBSD__) \
|
||||
|| defined(__OpenBSD__) \
|
||||
|| defined(__linux__)
|
||||
# define ASIO_HAS_UNISTD_H 1
|
||||
# endif
|
||||
# endif // !defined(ASIO_HAS_BOOST_CONFIG)
|
||||
#endif // !defined(ASIO_HAS_UNISTD_H)
|
||||
#if defined(ASIO_HAS_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif // defined(ASIO_HAS_UNISTD_H)
|
||||
|
||||
// Threads.
|
||||
#if !defined(ASIO_HAS_THREADS)
|
||||
# if !defined(ASIO_DISABLE_THREADS)
|
||||
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_THREADS)
|
||||
# define ASIO_HAS_THREADS 1
|
||||
# elif defined(_MSC_VER) && defined(_MT)
|
||||
# define ASIO_HAS_THREADS 1
|
||||
# elif defined(__BORLANDC__) && defined(__MT__)
|
||||
# define ASIO_HAS_THREADS 1
|
||||
# elif defined(_POSIX_THREADS)
|
||||
# define ASIO_HAS_THREADS 1
|
||||
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_THREADS)
|
||||
# endif // !defined(ASIO_DISABLE_THREADS)
|
||||
#endif // !defined(ASIO_HAS_THREADS)
|
||||
|
||||
// POSIX threads.
|
||||
#if !defined(ASIO_HAS_PTHREADS)
|
||||
# if defined(ASIO_HAS_THREADS)
|
||||
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_PTHREADS)
|
||||
# define ASIO_HAS_PTHREADS 1
|
||||
# elif defined(_POSIX_THREADS)
|
||||
# define ASIO_HAS_PTHREADS 1
|
||||
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_PTHREADS)
|
||||
# endif // defined(ASIO_HAS_THREADS)
|
||||
#endif // !defined(ASIO_HAS_PTHREADS)
|
||||
|
||||
// Helper to prevent macro expansion.
|
||||
#define ASIO_PREVENT_MACRO_SUBSTITUTION
|
||||
|
||||
// Helper to define in-class constants.
|
||||
#if !defined(ASIO_STATIC_CONSTANT)
|
||||
# if !defined(ASIO_DISABLE_BOOST_STATIC_CONSTANT)
|
||||
# define ASIO_STATIC_CONSTANT(type, assignment) \
|
||||
BOOST_STATIC_CONSTANT(type, assignment)
|
||||
# else // !defined(ASIO_DISABLE_BOOST_STATIC_CONSTANT)
|
||||
# define ASIO_STATIC_CONSTANT(type, assignment) \
|
||||
static const type assignment
|
||||
# endif // !defined(ASIO_DISABLE_BOOST_STATIC_CONSTANT)
|
||||
#endif // !defined(ASIO_STATIC_CONSTANT)
|
||||
|
||||
// Boost array library.
|
||||
#if !defined(ASIO_HAS_BOOST_ARRAY)
|
||||
# if !defined(ASIO_DISABLE_BOOST_ARRAY)
|
||||
# define ASIO_HAS_BOOST_ARRAY 1
|
||||
# endif // !defined(ASIO_DISABLE_BOOST_ARRAY)
|
||||
#endif // !defined(ASIO_HAS_BOOST_ARRAY)
|
||||
|
||||
// Boost assert macro.
|
||||
#if !defined(ASIO_HAS_BOOST_ASSERT)
|
||||
# if !defined(ASIO_DISABLE_BOOST_ASSERT)
|
||||
# define ASIO_HAS_BOOST_ASSERT 1
|
||||
# endif // !defined(ASIO_DISABLE_BOOST_ASSERT)
|
||||
#endif // !defined(ASIO_HAS_BOOST_ASSERT)
|
||||
|
||||
// Boost limits header.
|
||||
#if !defined(ASIO_HAS_BOOST_LIMITS)
|
||||
# if !defined(ASIO_DISABLE_BOOST_LIMITS)
|
||||
# define ASIO_HAS_BOOST_LIMITS 1
|
||||
# endif // !defined(ASIO_DISABLE_BOOST_LIMITS)
|
||||
#endif // !defined(ASIO_HAS_BOOST_LIMITS)
|
||||
|
||||
// Boost throw_exception function.
|
||||
#if !defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
|
||||
# if !defined(ASIO_DISABLE_BOOST_THROW_EXCEPTION)
|
||||
# define ASIO_HAS_BOOST_THROW_EXCEPTION 1
|
||||
# endif // !defined(ASIO_DISABLE_BOOST_THROW_EXCEPTION)
|
||||
#endif // !defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
|
||||
|
||||
// Boost regex library.
|
||||
#if !defined(ASIO_HAS_BOOST_REGEX)
|
||||
# if !defined(ASIO_DISABLE_BOOST_REGEX)
|
||||
# define ASIO_HAS_BOOST_REGEX 1
|
||||
# endif // !defined(ASIO_DISABLE_BOOST_REGEX)
|
||||
#endif // !defined(ASIO_HAS_BOOST_REGEX)
|
||||
|
||||
// Boost bind function.
|
||||
#if !defined(ASIO_HAS_BOOST_BIND)
|
||||
# if !defined(ASIO_DISABLE_BOOST_BIND)
|
||||
# define ASIO_HAS_BOOST_BIND 1
|
||||
# endif // !defined(ASIO_DISABLE_BOOST_BIND)
|
||||
#endif // !defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
// Boost's BOOST_WORKAROUND macro.
|
||||
#if !defined(ASIO_HAS_BOOST_WORKAROUND)
|
||||
# if !defined(ASIO_DISABLE_BOOST_WORKAROUND)
|
||||
# define ASIO_HAS_BOOST_WORKAROUND 1
|
||||
# endif // !defined(ASIO_DISABLE_BOOST_WORKAROUND)
|
||||
#endif // !defined(ASIO_HAS_BOOST_WORKAROUND)
|
||||
|
||||
// Microsoft Visual C++'s secure C runtime library.
|
||||
#if !defined(ASIO_HAS_SECURE_RTL)
|
||||
# if !defined(ASIO_DISABLE_SECURE_RTL)
|
||||
# if defined(ASIO_MSVC) \
|
||||
&& (ASIO_MSVC >= 1400) \
|
||||
&& !defined(UNDER_CE)
|
||||
# define ASIO_HAS_SECURE_RTL 1
|
||||
# endif // defined(ASIO_MSVC)
|
||||
// && (ASIO_MSVC >= 1400)
|
||||
// && !defined(UNDER_CE)
|
||||
# endif // !defined(ASIO_DISABLE_SECURE_RTL)
|
||||
#endif // !defined(ASIO_HAS_SECURE_RTL)
|
||||
|
||||
// Handler hooking. Disabled for ancient Borland C++ and gcc compilers.
|
||||
#if !defined(ASIO_HAS_HANDLER_HOOKS)
|
||||
# if !defined(ASIO_DISABLE_HANDLER_HOOKS)
|
||||
# if defined(__GNUC__)
|
||||
# if (__GNUC__ >= 3)
|
||||
# define ASIO_HAS_HANDLER_HOOKS 1
|
||||
# endif // (__GNUC__ >= 3)
|
||||
# elif !defined(__BORLANDC__)
|
||||
# define ASIO_HAS_HANDLER_HOOKS 1
|
||||
# endif // !defined(__BORLANDC__)
|
||||
# endif // !defined(ASIO_DISABLE_HANDLER_HOOKS)
|
||||
#endif // !defined(ASIO_HAS_HANDLER_HOOKS)
|
||||
|
||||
// Support for the __thread keyword extension.
|
||||
#if !defined(ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
|
||||
# if defined(__linux__)
|
||||
# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
# if ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)
|
||||
# if !defined(__INTEL_COMPILER) && !defined(__ICL)
|
||||
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
|
||||
# define ASIO_THREAD_KEYWORD __thread
|
||||
# elif defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1100)
|
||||
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
|
||||
# endif // defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1100)
|
||||
# endif // ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)
|
||||
# endif // defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
# endif // defined(__linux__)
|
||||
# if defined(ASIO_MSVC) && defined(ASIO_WINDOWS_RUNTIME)
|
||||
# if (_MSC_VER >= 1700)
|
||||
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
|
||||
# define ASIO_THREAD_KEYWORD __declspec(thread)
|
||||
# endif // (_MSC_VER >= 1700)
|
||||
# endif // defined(ASIO_MSVC) && defined(ASIO_WINDOWS_RUNTIME)
|
||||
#endif // !defined(ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
|
||||
#if !defined(ASIO_THREAD_KEYWORD)
|
||||
# define ASIO_THREAD_KEYWORD __thread
|
||||
#endif // !defined(ASIO_THREAD_KEYWORD)
|
||||
|
||||
// Support for POSIX ssize_t typedef.
|
||||
#if !defined(ASIO_DISABLE_SSIZE_T)
|
||||
# if defined(__linux__) \
|
||||
|| (defined(__MACH__) && defined(__APPLE__))
|
||||
# define ASIO_HAS_SSIZE_T 1
|
||||
# endif // defined(__linux__)
|
||||
// || (defined(__MACH__) && defined(__APPLE__))
|
||||
#endif // !defined(ASIO_DISABLE_SSIZE_T)
|
||||
|
||||
#endif // ASIO_DETAIL_CONFIG_HPP
|
|
@ -1,292 +0,0 @@
|
|||
//
|
||||
// detail/consuming_buffers.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_CONSUMING_BUFFERS_HPP
|
||||
#define ASIO_DETAIL_CONSUMING_BUFFERS_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/detail/limits.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// A proxy iterator for a sub-range in a list of buffers.
|
||||
template <typename Buffer, typename Buffer_Iterator>
|
||||
class consuming_buffers_iterator
|
||||
{
|
||||
public:
|
||||
/// The type used for the distance between two iterators.
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
/// The type of the value pointed to by the iterator.
|
||||
typedef Buffer value_type;
|
||||
|
||||
/// The type of the result of applying operator->() to the iterator.
|
||||
typedef const Buffer* pointer;
|
||||
|
||||
/// The type of the result of applying operator*() to the iterator.
|
||||
typedef const Buffer& reference;
|
||||
|
||||
/// The iterator category.
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
|
||||
// Default constructor creates an end iterator.
|
||||
consuming_buffers_iterator()
|
||||
: at_end_(true)
|
||||
{
|
||||
}
|
||||
|
||||
// Construct with a buffer for the first entry and an iterator
|
||||
// range for the remaining entries.
|
||||
consuming_buffers_iterator(bool at_end, const Buffer& first,
|
||||
Buffer_Iterator begin_remainder, Buffer_Iterator end_remainder,
|
||||
std::size_t max_size)
|
||||
: at_end_(max_size > 0 ? at_end : true),
|
||||
first_(buffer(first, max_size)),
|
||||
begin_remainder_(begin_remainder),
|
||||
end_remainder_(end_remainder),
|
||||
offset_(0),
|
||||
max_size_(max_size)
|
||||
{
|
||||
}
|
||||
|
||||
// Dereference an iterator.
|
||||
const Buffer& operator*() const
|
||||
{
|
||||
return dereference();
|
||||
}
|
||||
|
||||
// Dereference an iterator.
|
||||
const Buffer* operator->() const
|
||||
{
|
||||
return &dereference();
|
||||
}
|
||||
|
||||
// Increment operator (prefix).
|
||||
consuming_buffers_iterator& operator++()
|
||||
{
|
||||
increment();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Increment operator (postfix).
|
||||
consuming_buffers_iterator operator++(int)
|
||||
{
|
||||
consuming_buffers_iterator tmp(*this);
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Test two iterators for equality.
|
||||
friend bool operator==(const consuming_buffers_iterator& a,
|
||||
const consuming_buffers_iterator& b)
|
||||
{
|
||||
return a.equal(b);
|
||||
}
|
||||
|
||||
// Test two iterators for inequality.
|
||||
friend bool operator!=(const consuming_buffers_iterator& a,
|
||||
const consuming_buffers_iterator& b)
|
||||
{
|
||||
return !a.equal(b);
|
||||
}
|
||||
|
||||
private:
|
||||
void increment()
|
||||
{
|
||||
if (!at_end_)
|
||||
{
|
||||
if (begin_remainder_ == end_remainder_
|
||||
|| offset_ + buffer_size(first_) >= max_size_)
|
||||
{
|
||||
at_end_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset_ += buffer_size(first_);
|
||||
first_ = buffer(*begin_remainder_++, max_size_ - offset_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool equal(const consuming_buffers_iterator& other) const
|
||||
{
|
||||
if (at_end_ && other.at_end_)
|
||||
return true;
|
||||
return !at_end_ && !other.at_end_
|
||||
&& buffer_cast<const void*>(first_)
|
||||
== buffer_cast<const void*>(other.first_)
|
||||
&& buffer_size(first_) == buffer_size(other.first_)
|
||||
&& begin_remainder_ == other.begin_remainder_
|
||||
&& end_remainder_ == other.end_remainder_;
|
||||
}
|
||||
|
||||
const Buffer& dereference() const
|
||||
{
|
||||
return first_;
|
||||
}
|
||||
|
||||
bool at_end_;
|
||||
Buffer first_;
|
||||
Buffer_Iterator begin_remainder_;
|
||||
Buffer_Iterator end_remainder_;
|
||||
std::size_t offset_;
|
||||
std::size_t max_size_;
|
||||
};
|
||||
|
||||
// A proxy for a sub-range in a list of buffers.
|
||||
template <typename Buffer, typename Buffers>
|
||||
class consuming_buffers
|
||||
{
|
||||
public:
|
||||
// The type for each element in the list of buffers.
|
||||
typedef Buffer value_type;
|
||||
|
||||
// A forward-only iterator type that may be used to read elements.
|
||||
typedef consuming_buffers_iterator<Buffer, typename Buffers::const_iterator>
|
||||
const_iterator;
|
||||
|
||||
// Construct to represent the entire list of buffers.
|
||||
consuming_buffers(const Buffers& buffers)
|
||||
: buffers_(buffers),
|
||||
at_end_(buffers_.begin() == buffers_.end()),
|
||||
begin_remainder_(buffers_.begin()),
|
||||
max_size_((std::numeric_limits<std::size_t>::max)())
|
||||
{
|
||||
if (!at_end_)
|
||||
{
|
||||
first_ = *buffers_.begin();
|
||||
++begin_remainder_;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy constructor.
|
||||
consuming_buffers(const consuming_buffers& other)
|
||||
: buffers_(other.buffers_),
|
||||
at_end_(other.at_end_),
|
||||
first_(other.first_),
|
||||
begin_remainder_(buffers_.begin()),
|
||||
max_size_(other.max_size_)
|
||||
{
|
||||
typename Buffers::const_iterator first = other.buffers_.begin();
|
||||
typename Buffers::const_iterator second = other.begin_remainder_;
|
||||
std::advance(begin_remainder_, std::distance(first, second));
|
||||
}
|
||||
|
||||
// Assignment operator.
|
||||
consuming_buffers& operator=(const consuming_buffers& other)
|
||||
{
|
||||
buffers_ = other.buffers_;
|
||||
at_end_ = other.at_end_;
|
||||
first_ = other.first_;
|
||||
begin_remainder_ = buffers_.begin();
|
||||
typename Buffers::const_iterator first = other.buffers_.begin();
|
||||
typename Buffers::const_iterator second = other.begin_remainder_;
|
||||
std::advance(begin_remainder_, std::distance(first, second));
|
||||
max_size_ = other.max_size_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Get a forward-only iterator to the first element.
|
||||
const_iterator begin() const
|
||||
{
|
||||
return const_iterator(at_end_, first_,
|
||||
begin_remainder_, buffers_.end(), max_size_);
|
||||
}
|
||||
|
||||
// Get a forward-only iterator for one past the last element.
|
||||
const_iterator end() const
|
||||
{
|
||||
return const_iterator();
|
||||
}
|
||||
|
||||
// Set the maximum size for a single transfer.
|
||||
void prepare(std::size_t max_size)
|
||||
{
|
||||
max_size_ = max_size;
|
||||
}
|
||||
|
||||
// Consume the specified number of bytes from the buffers.
|
||||
void consume(std::size_t size)
|
||||
{
|
||||
// Remove buffers from the start until the specified size is reached.
|
||||
while (size > 0 && !at_end_)
|
||||
{
|
||||
if (buffer_size(first_) <= size)
|
||||
{
|
||||
size -= buffer_size(first_);
|
||||
if (begin_remainder_ == buffers_.end())
|
||||
at_end_ = true;
|
||||
else
|
||||
first_ = *begin_remainder_++;
|
||||
}
|
||||
else
|
||||
{
|
||||
first_ = first_ + size;
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any more empty buffers at the start.
|
||||
while (!at_end_ && buffer_size(first_) == 0)
|
||||
{
|
||||
if (begin_remainder_ == buffers_.end())
|
||||
at_end_ = true;
|
||||
else
|
||||
first_ = *begin_remainder_++;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Buffers buffers_;
|
||||
bool at_end_;
|
||||
Buffer first_;
|
||||
typename Buffers::const_iterator begin_remainder_;
|
||||
std::size_t max_size_;
|
||||
};
|
||||
|
||||
// Specialisation for null_buffers to ensure that the null_buffers type is
|
||||
// always passed through to the underlying read or write operation.
|
||||
template <typename Buffer>
|
||||
class consuming_buffers<Buffer, asio::null_buffers>
|
||||
: public asio::null_buffers
|
||||
{
|
||||
public:
|
||||
consuming_buffers(const asio::null_buffers&)
|
||||
{
|
||||
// No-op.
|
||||
}
|
||||
|
||||
void prepare(std::size_t)
|
||||
{
|
||||
// No-op.
|
||||
}
|
||||
|
||||
void consume(std::size_t)
|
||||
{
|
||||
// No-op.
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_CONSUMING_BUFFERS_HPP
|
|
@ -1,46 +0,0 @@
|
|||
//
|
||||
// detail/cstdint.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_CSTDINT_HPP
|
||||
#define ASIO_DETAIL_CSTDINT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_CSTDINT)
|
||||
# include <cstdint>
|
||||
#else // defined(ASIO_HAS_CSTDINT)
|
||||
# include <boost/cstdint.hpp>
|
||||
#endif // defined(ASIO_HAS_CSTDINT)
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if defined(ASIO_HAS_CSTDINT)
|
||||
using std::int16_t;
|
||||
using std::uint16_t;
|
||||
using std::int32_t;
|
||||
using std::uint32_t;
|
||||
using std::int64_t;
|
||||
using std::uint64_t;
|
||||
#else // defined(ASIO_HAS_CSTDINT)
|
||||
using boost::int16_t;
|
||||
using boost::uint16_t;
|
||||
using boost::int32_t;
|
||||
using boost::uint32_t;
|
||||
using boost::int64_t;
|
||||
using boost::uint64_t;
|
||||
#endif // defined(ASIO_HAS_CSTDINT)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_DETAIL_CSTDINT_HPP
|
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// detail/date_time_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_DATE_TIME_FWD_HPP
|
||||
#define ASIO_DETAIL_DATE_TIME_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace date_time {
|
||||
|
||||
template<class T, class TimeSystem>
|
||||
class base_time;
|
||||
|
||||
} // namespace date_time
|
||||
namespace posix_time {
|
||||
|
||||
class ptime;
|
||||
|
||||
} // namespace posix_time
|
||||
} // namespace boost
|
||||
|
||||
#endif // ASIO_DETAIL_DATE_TIME_FWD_HPP
|
|
@ -1,227 +0,0 @@
|
|||
//
|
||||
// detail/deadline_timer_service.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_DEADLINE_TIMER_SERVICE_HPP
|
||||
#define ASIO_DETAIL_DEADLINE_TIMER_SERVICE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <cstddef>
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
#include "asio/detail/addressof.hpp"
|
||||
#include "asio/detail/bind_handler.hpp"
|
||||
#include "asio/detail/fenced_block.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/socket_ops.hpp"
|
||||
#include "asio/detail/socket_types.hpp"
|
||||
#include "asio/detail/timer_queue.hpp"
|
||||
#include "asio/detail/timer_scheduler.hpp"
|
||||
#include "asio/detail/wait_handler.hpp"
|
||||
#include "asio/detail/wait_op.hpp"
|
||||
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
# include <chrono>
|
||||
# include <thread>
|
||||
#endif // defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename Time_Traits>
|
||||
class deadline_timer_service
|
||||
{
|
||||
public:
|
||||
// The time type.
|
||||
typedef typename Time_Traits::time_type time_type;
|
||||
|
||||
// The duration type.
|
||||
typedef typename Time_Traits::duration_type duration_type;
|
||||
|
||||
// The implementation type of the timer. This type is dependent on the
|
||||
// underlying implementation of the timer service.
|
||||
struct implementation_type
|
||||
: private asio::detail::noncopyable
|
||||
{
|
||||
time_type expiry;
|
||||
bool might_have_pending_waits;
|
||||
typename timer_queue<Time_Traits>::per_timer_data timer_data;
|
||||
};
|
||||
|
||||
// Constructor.
|
||||
deadline_timer_service(asio::io_service& io_service)
|
||||
: scheduler_(asio::use_service<timer_scheduler>(io_service))
|
||||
{
|
||||
scheduler_.init_task();
|
||||
scheduler_.add_timer_queue(timer_queue_);
|
||||
}
|
||||
|
||||
// Destructor.
|
||||
~deadline_timer_service()
|
||||
{
|
||||
scheduler_.remove_timer_queue(timer_queue_);
|
||||
}
|
||||
|
||||
// Destroy all user-defined handler objects owned by the service.
|
||||
void shutdown_service()
|
||||
{
|
||||
}
|
||||
|
||||
// Construct a new timer implementation.
|
||||
void construct(implementation_type& impl)
|
||||
{
|
||||
impl.expiry = time_type();
|
||||
impl.might_have_pending_waits = false;
|
||||
}
|
||||
|
||||
// Destroy a timer implementation.
|
||||
void destroy(implementation_type& impl)
|
||||
{
|
||||
asio::error_code ec;
|
||||
cancel(impl, ec);
|
||||
}
|
||||
|
||||
// Cancel any asynchronous wait operations associated with the timer.
|
||||
std::size_t cancel(implementation_type& impl, asio::error_code& ec)
|
||||
{
|
||||
if (!impl.might_have_pending_waits)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ASIO_HANDLER_OPERATION(("deadline_timer", &impl, "cancel"));
|
||||
|
||||
std::size_t count = scheduler_.cancel_timer(timer_queue_, impl.timer_data);
|
||||
impl.might_have_pending_waits = false;
|
||||
ec = asio::error_code();
|
||||
return count;
|
||||
}
|
||||
|
||||
// Cancels one asynchronous wait operation associated with the timer.
|
||||
std::size_t cancel_one(implementation_type& impl,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
if (!impl.might_have_pending_waits)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ASIO_HANDLER_OPERATION(("deadline_timer", &impl, "cancel_one"));
|
||||
|
||||
std::size_t count = scheduler_.cancel_timer(
|
||||
timer_queue_, impl.timer_data, 1);
|
||||
if (count == 0)
|
||||
impl.might_have_pending_waits = false;
|
||||
ec = asio::error_code();
|
||||
return count;
|
||||
}
|
||||
|
||||
// Get the expiry time for the timer as an absolute time.
|
||||
time_type expires_at(const implementation_type& impl) const
|
||||
{
|
||||
return impl.expiry;
|
||||
}
|
||||
|
||||
// Set the expiry time for the timer as an absolute time.
|
||||
std::size_t expires_at(implementation_type& impl,
|
||||
const time_type& expiry_time, asio::error_code& ec)
|
||||
{
|
||||
std::size_t count = cancel(impl, ec);
|
||||
impl.expiry = expiry_time;
|
||||
ec = asio::error_code();
|
||||
return count;
|
||||
}
|
||||
|
||||
// Get the expiry time for the timer relative to now.
|
||||
duration_type expires_from_now(const implementation_type& impl) const
|
||||
{
|
||||
return Time_Traits::subtract(expires_at(impl), Time_Traits::now());
|
||||
}
|
||||
|
||||
// Set the expiry time for the timer relative to now.
|
||||
std::size_t expires_from_now(implementation_type& impl,
|
||||
const duration_type& expiry_time, asio::error_code& ec)
|
||||
{
|
||||
return expires_at(impl,
|
||||
Time_Traits::add(Time_Traits::now(), expiry_time), ec);
|
||||
}
|
||||
|
||||
// Perform a blocking wait on the timer.
|
||||
void wait(implementation_type& impl, asio::error_code& ec)
|
||||
{
|
||||
time_type now = Time_Traits::now();
|
||||
ec = asio::error_code();
|
||||
while (Time_Traits::less_than(now, impl.expiry) && !ec)
|
||||
{
|
||||
this->do_wait(Time_Traits::to_posix_duration(
|
||||
Time_Traits::subtract(impl.expiry, now)), ec);
|
||||
now = Time_Traits::now();
|
||||
}
|
||||
}
|
||||
|
||||
// Start an asynchronous wait on the timer.
|
||||
template <typename Handler>
|
||||
void async_wait(implementation_type& impl, Handler& handler)
|
||||
{
|
||||
// Allocate and construct an operation to wrap the handler.
|
||||
typedef wait_handler<Handler> op;
|
||||
typename op::ptr p = { asio::detail::addressof(handler),
|
||||
asio_handler_alloc_helpers::allocate(
|
||||
sizeof(op), handler), 0 };
|
||||
p.p = new (p.v) op(handler);
|
||||
|
||||
impl.might_have_pending_waits = true;
|
||||
|
||||
ASIO_HANDLER_CREATION((p.p, "deadline_timer", &impl, "async_wait"));
|
||||
|
||||
scheduler_.schedule_timer(timer_queue_, impl.expiry, impl.timer_data, p.p);
|
||||
p.v = p.p = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
// Helper function to wait given a duration type. The duration type should
|
||||
// either be of type boost::posix_time::time_duration, or implement the
|
||||
// required subset of its interface.
|
||||
template <typename Duration>
|
||||
void do_wait(const Duration& timeout, asio::error_code& ec)
|
||||
{
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono::seconds(timeout.total_seconds())
|
||||
+ std::chrono::microseconds(timeout.total_microseconds()));
|
||||
ec = asio::error_code();
|
||||
#else // defined(ASIO_WINDOWS_RUNTIME)
|
||||
::timeval tv;
|
||||
tv.tv_sec = timeout.total_seconds();
|
||||
tv.tv_usec = timeout.total_microseconds() % 1000000;
|
||||
socket_ops::select(0, 0, 0, 0, &tv, ec);
|
||||
#endif // defined(ASIO_WINDOWS_RUNTIME)
|
||||
}
|
||||
|
||||
// The queue of timers.
|
||||
timer_queue<Time_Traits> timer_queue_;
|
||||
|
||||
// The object that schedules and executes timers. Usually a reactor.
|
||||
timer_scheduler& scheduler_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_DEADLINE_TIMER_SERVICE_HPP
|
|
@ -1,36 +0,0 @@
|
|||
//
|
||||
// detail/dependent_type.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_DEPENDENT_TYPE_HPP
|
||||
#define ASIO_DETAIL_DEPENDENT_TYPE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename DependsOn, typename T>
|
||||
struct dependent_type
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DETAIL_DEPENDENT_TYPE_HPP
|
|
@ -1,117 +0,0 @@
|
|||
//
|
||||
// detail/descriptor_ops.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_DESCRIPTOR_OPS_HPP
|
||||
#define ASIO_DETAIL_DESCRIPTOR_OPS_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_WINDOWS) \
|
||||
&& !defined(ASIO_WINDOWS_RUNTIME) \
|
||||
&& !defined(__CYGWIN__)
|
||||
|
||||
#include <cstddef>
|
||||
#include "asio/error_code.hpp"
|
||||
#include "asio/detail/socket_types.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
namespace descriptor_ops {
|
||||
|
||||
// Descriptor state bits.
|
||||
enum
|
||||
{
|
||||
// The user wants a non-blocking descriptor.
|
||||
user_set_non_blocking = 1,
|
||||
|
||||
// The descriptor has been set non-blocking.
|
||||
internal_non_blocking = 2,
|
||||
|
||||
// Helper "state" used to determine whether the descriptor is non-blocking.
|
||||
non_blocking = user_set_non_blocking | internal_non_blocking,
|
||||
|
||||
// The descriptor may have been dup()-ed.
|
||||
possible_dup = 4
|
||||
};
|
||||
|
||||
typedef unsigned char state_type;
|
||||
|
||||
template <typename ReturnType>
|
||||
inline ReturnType error_wrapper(ReturnType return_value,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code(errno,
|
||||
asio::error::get_system_category());
|
||||
return return_value;
|
||||
}
|
||||
|
||||
ASIO_DECL int open(const char* path, int flags,
|
||||
asio::error_code& ec);
|
||||
|
||||
ASIO_DECL int close(int d, state_type& state,
|
||||
asio::error_code& ec);
|
||||
|
||||
ASIO_DECL bool set_user_non_blocking(int d,
|
||||
state_type& state, bool value, asio::error_code& ec);
|
||||
|
||||
ASIO_DECL bool set_internal_non_blocking(int d,
|
||||
state_type& state, bool value, asio::error_code& ec);
|
||||
|
||||
typedef iovec buf;
|
||||
|
||||
ASIO_DECL std::size_t sync_read(int d, state_type state, buf* bufs,
|
||||
std::size_t count, bool all_empty, asio::error_code& ec);
|
||||
|
||||
ASIO_DECL bool non_blocking_read(int d, buf* bufs, std::size_t count,
|
||||
asio::error_code& ec, std::size_t& bytes_transferred);
|
||||
|
||||
ASIO_DECL std::size_t sync_write(int d, state_type state,
|
||||
const buf* bufs, std::size_t count, bool all_empty,
|
||||
asio::error_code& ec);
|
||||
|
||||
ASIO_DECL bool non_blocking_write(int d,
|
||||
const buf* bufs, std::size_t count,
|
||||
asio::error_code& ec, std::size_t& bytes_transferred);
|
||||
|
||||
ASIO_DECL int ioctl(int d, state_type& state, long cmd,
|
||||
ioctl_arg_type* arg, asio::error_code& ec);
|
||||
|
||||
ASIO_DECL int fcntl(int d, int cmd, asio::error_code& ec);
|
||||
|
||||
ASIO_DECL int fcntl(int d, int cmd,
|
||||
long arg, asio::error_code& ec);
|
||||
|
||||
ASIO_DECL int poll_read(int d,
|
||||
state_type state, asio::error_code& ec);
|
||||
|
||||
ASIO_DECL int poll_write(int d,
|
||||
state_type state, asio::error_code& ec);
|
||||
|
||||
} // namespace descriptor_ops
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if defined(ASIO_HEADER_ONLY)
|
||||
# include "asio/detail/impl/descriptor_ops.ipp"
|
||||
#endif // defined(ASIO_HEADER_ONLY)
|
||||
|
||||
#endif // !defined(ASIO_WINDOWS)
|
||||
// && !defined(ASIO_WINDOWS_RUNTIME)
|
||||
// && !defined(__CYGWIN__)
|
||||
|
||||
#endif // ASIO_DETAIL_DESCRIPTOR_OPS_HPP
|
|
@ -1,119 +0,0 @@
|
|||
//
|
||||
// detail/descriptor_read_op.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_DESCRIPTOR_READ_OP_HPP
|
||||
#define ASIO_DETAIL_DESCRIPTOR_READ_OP_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
|
||||
|
||||
#include "asio/detail/addressof.hpp"
|
||||
#include "asio/detail/bind_handler.hpp"
|
||||
#include "asio/detail/buffer_sequence_adapter.hpp"
|
||||
#include "asio/detail/descriptor_ops.hpp"
|
||||
#include "asio/detail/fenced_block.hpp"
|
||||
#include "asio/detail/reactor_op.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename MutableBufferSequence>
|
||||
class descriptor_read_op_base : public reactor_op
|
||||
{
|
||||
public:
|
||||
descriptor_read_op_base(int descriptor,
|
||||
const MutableBufferSequence& buffers, func_type complete_func)
|
||||
: reactor_op(&descriptor_read_op_base::do_perform, complete_func),
|
||||
descriptor_(descriptor),
|
||||
buffers_(buffers)
|
||||
{
|
||||
}
|
||||
|
||||
static bool do_perform(reactor_op* base)
|
||||
{
|
||||
descriptor_read_op_base* o(static_cast<descriptor_read_op_base*>(base));
|
||||
|
||||
buffer_sequence_adapter<asio::mutable_buffer,
|
||||
MutableBufferSequence> bufs(o->buffers_);
|
||||
|
||||
return descriptor_ops::non_blocking_read(o->descriptor_,
|
||||
bufs.buffers(), bufs.count(), o->ec_, o->bytes_transferred_);
|
||||
}
|
||||
|
||||
private:
|
||||
int descriptor_;
|
||||
MutableBufferSequence buffers_;
|
||||
};
|
||||
|
||||
template <typename MutableBufferSequence, typename Handler>
|
||||
class descriptor_read_op
|
||||
: public descriptor_read_op_base<MutableBufferSequence>
|
||||
{
|
||||
public:
|
||||
ASIO_DEFINE_HANDLER_PTR(descriptor_read_op);
|
||||
|
||||
descriptor_read_op(int descriptor,
|
||||
const MutableBufferSequence& buffers, Handler& handler)
|
||||
: descriptor_read_op_base<MutableBufferSequence>(
|
||||
descriptor, buffers, &descriptor_read_op::do_complete),
|
||||
handler_(ASIO_MOVE_CAST(Handler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
static void do_complete(io_service_impl* owner, operation* base,
|
||||
const asio::error_code& /*ec*/,
|
||||
std::size_t /*bytes_transferred*/)
|
||||
{
|
||||
// Take ownership of the handler object.
|
||||
descriptor_read_op* o(static_cast<descriptor_read_op*>(base));
|
||||
ptr p = { asio::detail::addressof(o->handler_), o, o };
|
||||
|
||||
ASIO_HANDLER_COMPLETION((o));
|
||||
|
||||
// Make a copy of the handler so that the memory can be deallocated before
|
||||
// the upcall is made. Even if we're not about to make an upcall, a
|
||||
// sub-object of the handler may be the true owner of the memory associated
|
||||
// with the handler. Consequently, a local copy of the handler is required
|
||||
// to ensure that any owning sub-object remains valid until after we have
|
||||
// deallocated the memory here.
|
||||
detail::binder2<Handler, asio::error_code, std::size_t>
|
||||
handler(o->handler_, o->ec_, o->bytes_transferred_);
|
||||
p.h = asio::detail::addressof(handler.handler_);
|
||||
p.reset();
|
||||
|
||||
// Make the upcall if required.
|
||||
if (owner)
|
||||
{
|
||||
fenced_block b(fenced_block::half);
|
||||
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
|
||||
asio_handler_invoke_helpers::invoke(handler, handler.handler_);
|
||||
ASIO_HANDLER_INVOCATION_END;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Handler handler_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
|
||||
|
||||
#endif // ASIO_DETAIL_DESCRIPTOR_READ_OP_HPP
|
|
@ -1,119 +0,0 @@
|
|||
//
|
||||
// detail/descriptor_write_op.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_DESCRIPTOR_WRITE_OP_HPP
|
||||
#define ASIO_DETAIL_DESCRIPTOR_WRITE_OP_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
|
||||
|
||||
#include "asio/detail/addressof.hpp"
|
||||
#include "asio/detail/bind_handler.hpp"
|
||||
#include "asio/detail/buffer_sequence_adapter.hpp"
|
||||
#include "asio/detail/descriptor_ops.hpp"
|
||||
#include "asio/detail/fenced_block.hpp"
|
||||
#include "asio/detail/reactor_op.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
template <typename ConstBufferSequence>
|
||||
class descriptor_write_op_base : public reactor_op
|
||||
{
|
||||
public:
|
||||
descriptor_write_op_base(int descriptor,
|
||||
const ConstBufferSequence& buffers, func_type complete_func)
|
||||
: reactor_op(&descriptor_write_op_base::do_perform, complete_func),
|
||||
descriptor_(descriptor),
|
||||
buffers_(buffers)
|
||||
{
|
||||
}
|
||||
|
||||
static bool do_perform(reactor_op* base)
|
||||
{
|
||||
descriptor_write_op_base* o(static_cast<descriptor_write_op_base*>(base));
|
||||
|
||||
buffer_sequence_adapter<asio::const_buffer,
|
||||
ConstBufferSequence> bufs(o->buffers_);
|
||||
|
||||
return descriptor_ops::non_blocking_write(o->descriptor_,
|
||||
bufs.buffers(), bufs.count(), o->ec_, o->bytes_transferred_);
|
||||
}
|
||||
|
||||
private:
|
||||
int descriptor_;
|
||||
ConstBufferSequence buffers_;
|
||||
};
|
||||
|
||||
template <typename ConstBufferSequence, typename Handler>
|
||||
class descriptor_write_op
|
||||
: public descriptor_write_op_base<ConstBufferSequence>
|
||||
{
|
||||
public:
|
||||
ASIO_DEFINE_HANDLER_PTR(descriptor_write_op);
|
||||
|
||||
descriptor_write_op(int descriptor,
|
||||
const ConstBufferSequence& buffers, Handler& handler)
|
||||
: descriptor_write_op_base<ConstBufferSequence>(
|
||||
descriptor, buffers, &descriptor_write_op::do_complete),
|
||||
handler_(ASIO_MOVE_CAST(Handler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
static void do_complete(io_service_impl* owner, operation* base,
|
||||
const asio::error_code& /*ec*/,
|
||||
std::size_t /*bytes_transferred*/)
|
||||
{
|
||||
// Take ownership of the handler object.
|
||||
descriptor_write_op* o(static_cast<descriptor_write_op*>(base));
|
||||
ptr p = { asio::detail::addressof(o->handler_), o, o };
|
||||
|
||||
ASIO_HANDLER_COMPLETION((o));
|
||||
|
||||
// Make a copy of the handler so that the memory can be deallocated before
|
||||
// the upcall is made. Even if we're not about to make an upcall, a
|
||||
// sub-object of the handler may be the true owner of the memory associated
|
||||
// with the handler. Consequently, a local copy of the handler is required
|
||||
// to ensure that any owning sub-object remains valid until after we have
|
||||
// deallocated the memory here.
|
||||
detail::binder2<Handler, asio::error_code, std::size_t>
|
||||
handler(o->handler_, o->ec_, o->bytes_transferred_);
|
||||
p.h = asio::detail::addressof(handler.handler_);
|
||||
p.reset();
|
||||
|
||||
// Make the upcall if required.
|
||||
if (owner)
|
||||
{
|
||||
fenced_block b(fenced_block::half);
|
||||
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
|
||||
asio_handler_invoke_helpers::invoke(handler, handler.handler_);
|
||||
ASIO_HANDLER_INVOCATION_END;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Handler handler_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
|
||||
|
||||
#endif // ASIO_DETAIL_DESCRIPTOR_WRITE_OP_HPP
|
|
@ -1,210 +0,0 @@
|
|||
//
|
||||
// detail/dev_poll_reactor.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_DEV_POLL_REACTOR_HPP
|
||||
#define ASIO_DETAIL_DEV_POLL_REACTOR_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_DEV_POLL)
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <sys/devpoll.h>
|
||||
#include "asio/detail/hash_map.hpp"
|
||||
#include "asio/detail/limits.hpp"
|
||||
#include "asio/detail/mutex.hpp"
|
||||
#include "asio/detail/op_queue.hpp"
|
||||
#include "asio/detail/reactor_op.hpp"
|
||||
#include "asio/detail/reactor_op_queue.hpp"
|
||||
#include "asio/detail/select_interrupter.hpp"
|
||||
#include "asio/detail/socket_types.hpp"
|
||||
#include "asio/detail/timer_queue_base.hpp"
|
||||
#include "asio/detail/timer_queue_set.hpp"
|
||||
#include "asio/detail/wait_op.hpp"
|
||||
#include "asio/io_service.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class dev_poll_reactor
|
||||
: public asio::detail::service_base<dev_poll_reactor>
|
||||
{
|
||||
public:
|
||||
enum op_types { read_op = 0, write_op = 1,
|
||||
connect_op = 1, except_op = 2, max_ops = 3 };
|
||||
|
||||
// Per-descriptor data.
|
||||
struct per_descriptor_data
|
||||
{
|
||||
};
|
||||
|
||||
// Constructor.
|
||||
ASIO_DECL dev_poll_reactor(asio::io_service& io_service);
|
||||
|
||||
// Destructor.
|
||||
ASIO_DECL ~dev_poll_reactor();
|
||||
|
||||
// Destroy all user-defined handler objects owned by the service.
|
||||
ASIO_DECL void shutdown_service();
|
||||
|
||||
// Recreate internal descriptors following a fork.
|
||||
ASIO_DECL void fork_service(
|
||||
asio::io_service::fork_event fork_ev);
|
||||
|
||||
// Initialise the task.
|
||||
ASIO_DECL void init_task();
|
||||
|
||||
// Register a socket with the reactor. Returns 0 on success, system error
|
||||
// code on failure.
|
||||
ASIO_DECL int register_descriptor(socket_type, per_descriptor_data&);
|
||||
|
||||
// Register a descriptor with an associated single operation. Returns 0 on
|
||||
// success, system error code on failure.
|
||||
ASIO_DECL int register_internal_descriptor(
|
||||
int op_type, socket_type descriptor,
|
||||
per_descriptor_data& descriptor_data, reactor_op* op);
|
||||
|
||||
// Move descriptor registration from one descriptor_data object to another.
|
||||
ASIO_DECL void move_descriptor(socket_type descriptor,
|
||||
per_descriptor_data& target_descriptor_data,
|
||||
per_descriptor_data& source_descriptor_data);
|
||||
|
||||
// Post a reactor operation for immediate completion.
|
||||
void post_immediate_completion(reactor_op* op, bool is_continuation)
|
||||
{
|
||||
io_service_.post_immediate_completion(op, is_continuation);
|
||||
}
|
||||
|
||||
// Start a new operation. The reactor operation will be performed when the
|
||||
// given descriptor is flagged as ready, or an error has occurred.
|
||||
ASIO_DECL void start_op(int op_type, socket_type descriptor,
|
||||
per_descriptor_data&, reactor_op* op,
|
||||
bool is_continuation, bool allow_speculative);
|
||||
|
||||
// Cancel all operations associated with the given descriptor. The
|
||||
// handlers associated with the descriptor will be invoked with the
|
||||
// operation_aborted error.
|
||||
ASIO_DECL void cancel_ops(socket_type descriptor, per_descriptor_data&);
|
||||
|
||||
// Cancel any operations that are running against the descriptor and remove
|
||||
// its registration from the reactor.
|
||||
ASIO_DECL void deregister_descriptor(socket_type descriptor,
|
||||
per_descriptor_data&, bool closing);
|
||||
|
||||
// Cancel any operations that are running against the descriptor and remove
|
||||
// its registration from the reactor.
|
||||
ASIO_DECL void deregister_internal_descriptor(
|
||||
socket_type descriptor, per_descriptor_data&);
|
||||
|
||||
// Add a new timer queue to the reactor.
|
||||
template <typename Time_Traits>
|
||||
void add_timer_queue(timer_queue<Time_Traits>& queue);
|
||||
|
||||
// Remove a timer queue from the reactor.
|
||||
template <typename Time_Traits>
|
||||
void remove_timer_queue(timer_queue<Time_Traits>& queue);
|
||||
|
||||
// Schedule a new operation in the given timer queue to expire at the
|
||||
// specified absolute time.
|
||||
template <typename Time_Traits>
|
||||
void schedule_timer(timer_queue<Time_Traits>& queue,
|
||||
const typename Time_Traits::time_type& time,
|
||||
typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op);
|
||||
|
||||
// Cancel the timer operations associated with the given token. Returns the
|
||||
// number of operations that have been posted or dispatched.
|
||||
template <typename Time_Traits>
|
||||
std::size_t cancel_timer(timer_queue<Time_Traits>& queue,
|
||||
typename timer_queue<Time_Traits>::per_timer_data& timer,
|
||||
std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
|
||||
|
||||
// Run /dev/poll once until interrupted or events are ready to be dispatched.
|
||||
ASIO_DECL void run(bool block, op_queue<operation>& ops);
|
||||
|
||||
// Interrupt the select loop.
|
||||
ASIO_DECL void interrupt();
|
||||
|
||||
private:
|
||||
// Create the /dev/poll file descriptor. Throws an exception if the descriptor
|
||||
// cannot be created.
|
||||
ASIO_DECL static int do_dev_poll_create();
|
||||
|
||||
// Helper function to add a new timer queue.
|
||||
ASIO_DECL void do_add_timer_queue(timer_queue_base& queue);
|
||||
|
||||
// Helper function to remove a timer queue.
|
||||
ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue);
|
||||
|
||||
// Get the timeout value for the /dev/poll DP_POLL operation. The timeout
|
||||
// value is returned as a number of milliseconds. A return value of -1
|
||||
// indicates that the poll should block indefinitely.
|
||||
ASIO_DECL int get_timeout();
|
||||
|
||||
// Cancel all operations associated with the given descriptor. The do_cancel
|
||||
// function of the handler objects will be invoked. This function does not
|
||||
// acquire the dev_poll_reactor's mutex.
|
||||
ASIO_DECL void cancel_ops_unlocked(socket_type descriptor,
|
||||
const asio::error_code& ec);
|
||||
|
||||
// Helper class used to reregister descriptors after a fork.
|
||||
class fork_helper;
|
||||
friend class fork_helper;
|
||||
|
||||
// Add a pending event entry for the given descriptor.
|
||||
ASIO_DECL ::pollfd& add_pending_event_change(int descriptor);
|
||||
|
||||
// The io_service implementation used to post completions.
|
||||
io_service_impl& io_service_;
|
||||
|
||||
// Mutex to protect access to internal data.
|
||||
asio::detail::mutex mutex_;
|
||||
|
||||
// The /dev/poll file descriptor.
|
||||
int dev_poll_fd_;
|
||||
|
||||
// Vector of /dev/poll events waiting to be written to the descriptor.
|
||||
std::vector< ::pollfd> pending_event_changes_;
|
||||
|
||||
// Hash map to associate a descriptor with a pending event change index.
|
||||
hash_map<int, std::size_t> pending_event_change_index_;
|
||||
|
||||
// The interrupter is used to break a blocking DP_POLL operation.
|
||||
select_interrupter interrupter_;
|
||||
|
||||
// The queues of read, write and except operations.
|
||||
reactor_op_queue<socket_type> op_queue_[max_ops];
|
||||
|
||||
// The timer queues.
|
||||
timer_queue_set timer_queues_;
|
||||
|
||||
// Whether the service has been shut down.
|
||||
bool shutdown_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/detail/impl/dev_poll_reactor.hpp"
|
||||
#if defined(ASIO_HEADER_ONLY)
|
||||
# include "asio/detail/impl/dev_poll_reactor.ipp"
|
||||
#endif // defined(ASIO_HEADER_ONLY)
|
||||
|
||||
#endif // defined(ASIO_HAS_DEV_POLL)
|
||||
|
||||
#endif // ASIO_DETAIL_DEV_POLL_REACTOR_HPP
|
|
@ -1,242 +0,0 @@
|
|||
//
|
||||
// detail/epoll_reactor.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_EPOLL_REACTOR_HPP
|
||||
#define ASIO_DETAIL_EPOLL_REACTOR_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_EPOLL)
|
||||
|
||||
#include "asio/io_service.hpp"
|
||||
#include "asio/detail/atomic_count.hpp"
|
||||
#include "asio/detail/limits.hpp"
|
||||
#include "asio/detail/mutex.hpp"
|
||||
#include "asio/detail/object_pool.hpp"
|
||||
#include "asio/detail/op_queue.hpp"
|
||||
#include "asio/detail/reactor_op.hpp"
|
||||
#include "asio/detail/select_interrupter.hpp"
|
||||
#include "asio/detail/socket_types.hpp"
|
||||
#include "asio/detail/timer_queue_base.hpp"
|
||||
#include "asio/detail/timer_queue_set.hpp"
|
||||
#include "asio/detail/wait_op.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class epoll_reactor
|
||||
: public asio::detail::service_base<epoll_reactor>
|
||||
{
|
||||
public:
|
||||
enum op_types { read_op = 0, write_op = 1,
|
||||
connect_op = 1, except_op = 2, max_ops = 3 };
|
||||
|
||||
// Per-descriptor queues.
|
||||
class descriptor_state : operation
|
||||
{
|
||||
friend class epoll_reactor;
|
||||
friend class object_pool_access;
|
||||
|
||||
descriptor_state* next_;
|
||||
descriptor_state* prev_;
|
||||
|
||||
mutex mutex_;
|
||||
epoll_reactor* reactor_;
|
||||
int descriptor_;
|
||||
uint32_t registered_events_;
|
||||
op_queue<reactor_op> op_queue_[max_ops];
|
||||
bool shutdown_;
|
||||
|
||||
ASIO_DECL descriptor_state();
|
||||
void set_ready_events(uint32_t events) { task_result_ = events; }
|
||||
ASIO_DECL operation* perform_io(uint32_t events);
|
||||
ASIO_DECL static void do_complete(
|
||||
io_service_impl* owner, operation* base,
|
||||
const asio::error_code& ec, std::size_t bytes_transferred);
|
||||
};
|
||||
|
||||
// Per-descriptor data.
|
||||
typedef descriptor_state* per_descriptor_data;
|
||||
|
||||
// Constructor.
|
||||
ASIO_DECL epoll_reactor(asio::io_service& io_service);
|
||||
|
||||
// Destructor.
|
||||
ASIO_DECL ~epoll_reactor();
|
||||
|
||||
// Destroy all user-defined handler objects owned by the service.
|
||||
ASIO_DECL void shutdown_service();
|
||||
|
||||
// Recreate internal descriptors following a fork.
|
||||
ASIO_DECL void fork_service(
|
||||
asio::io_service::fork_event fork_ev);
|
||||
|
||||
// Initialise the task.
|
||||
ASIO_DECL void init_task();
|
||||
|
||||
// Register a socket with the reactor. Returns 0 on success, system error
|
||||
// code on failure.
|
||||
ASIO_DECL int register_descriptor(socket_type descriptor,
|
||||
per_descriptor_data& descriptor_data);
|
||||
|
||||
// Register a descriptor with an associated single operation. Returns 0 on
|
||||
// success, system error code on failure.
|
||||
ASIO_DECL int register_internal_descriptor(
|
||||
int op_type, socket_type descriptor,
|
||||
per_descriptor_data& descriptor_data, reactor_op* op);
|
||||
|
||||
// Move descriptor registration from one descriptor_data object to another.
|
||||
ASIO_DECL void move_descriptor(socket_type descriptor,
|
||||
per_descriptor_data& target_descriptor_data,
|
||||
per_descriptor_data& source_descriptor_data);
|
||||
|
||||
// Post a reactor operation for immediate completion.
|
||||
void post_immediate_completion(reactor_op* op, bool is_continuation)
|
||||
{
|
||||
io_service_.post_immediate_completion(op, is_continuation);
|
||||
}
|
||||
|
||||
// Start a new operation. The reactor operation will be performed when the
|
||||
// given descriptor is flagged as ready, or an error has occurred.
|
||||
ASIO_DECL void start_op(int op_type, socket_type descriptor,
|
||||
per_descriptor_data& descriptor_data, reactor_op* op,
|
||||
bool is_continuation, bool allow_speculative);
|
||||
|
||||
// Cancel all operations associated with the given descriptor. The
|
||||
// handlers associated with the descriptor will be invoked with the
|
||||
// operation_aborted error.
|
||||
ASIO_DECL void cancel_ops(socket_type descriptor,
|
||||
per_descriptor_data& descriptor_data);
|
||||
|
||||
// Cancel any operations that are running against the descriptor and remove
|
||||
// its registration from the reactor.
|
||||
ASIO_DECL void deregister_descriptor(socket_type descriptor,
|
||||
per_descriptor_data& descriptor_data, bool closing);
|
||||
|
||||
// Remote the descriptor's registration from the reactor.
|
||||
ASIO_DECL void deregister_internal_descriptor(
|
||||
socket_type descriptor, per_descriptor_data& descriptor_data);
|
||||
|
||||
// Add a new timer queue to the reactor.
|
||||
template <typename Time_Traits>
|
||||
void add_timer_queue(timer_queue<Time_Traits>& timer_queue);
|
||||
|
||||
// Remove a timer queue from the reactor.
|
||||
template <typename Time_Traits>
|
||||
void remove_timer_queue(timer_queue<Time_Traits>& timer_queue);
|
||||
|
||||
// Schedule a new operation in the given timer queue to expire at the
|
||||
// specified absolute time.
|
||||
template <typename Time_Traits>
|
||||
void schedule_timer(timer_queue<Time_Traits>& queue,
|
||||
const typename Time_Traits::time_type& time,
|
||||
typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op);
|
||||
|
||||
// Cancel the timer operations associated with the given token. Returns the
|
||||
// number of operations that have been posted or dispatched.
|
||||
template <typename Time_Traits>
|
||||
std::size_t cancel_timer(timer_queue<Time_Traits>& queue,
|
||||
typename timer_queue<Time_Traits>::per_timer_data& timer,
|
||||
std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
|
||||
|
||||
// Run epoll once until interrupted or events are ready to be dispatched.
|
||||
ASIO_DECL void run(bool block, op_queue<operation>& ops);
|
||||
|
||||
// Interrupt the select loop.
|
||||
ASIO_DECL void interrupt();
|
||||
|
||||
private:
|
||||
// The hint to pass to epoll_create to size its data structures.
|
||||
enum { epoll_size = 20000 };
|
||||
|
||||
// Create the epoll file descriptor. Throws an exception if the descriptor
|
||||
// cannot be created.
|
||||
ASIO_DECL static int do_epoll_create();
|
||||
|
||||
// Create the timerfd file descriptor. Does not throw.
|
||||
ASIO_DECL static int do_timerfd_create();
|
||||
|
||||
// Allocate a new descriptor state object.
|
||||
ASIO_DECL descriptor_state* allocate_descriptor_state();
|
||||
|
||||
// Free an existing descriptor state object.
|
||||
ASIO_DECL void free_descriptor_state(descriptor_state* s);
|
||||
|
||||
// Helper function to add a new timer queue.
|
||||
ASIO_DECL void do_add_timer_queue(timer_queue_base& queue);
|
||||
|
||||
// Helper function to remove a timer queue.
|
||||
ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue);
|
||||
|
||||
// Called to recalculate and update the timeout.
|
||||
ASIO_DECL void update_timeout();
|
||||
|
||||
// Get the timeout value for the epoll_wait call. The timeout value is
|
||||
// returned as a number of milliseconds. A return value of -1 indicates
|
||||
// that epoll_wait should block indefinitely.
|
||||
ASIO_DECL int get_timeout();
|
||||
|
||||
#if defined(ASIO_HAS_TIMERFD)
|
||||
// Get the timeout value for the timer descriptor. The return value is the
|
||||
// flag argument to be used when calling timerfd_settime.
|
||||
ASIO_DECL int get_timeout(itimerspec& ts);
|
||||
#endif // defined(ASIO_HAS_TIMERFD)
|
||||
|
||||
// The io_service implementation used to post completions.
|
||||
io_service_impl& io_service_;
|
||||
|
||||
// Mutex to protect access to internal data.
|
||||
mutex mutex_;
|
||||
|
||||
// The interrupter is used to break a blocking epoll_wait call.
|
||||
select_interrupter interrupter_;
|
||||
|
||||
// The epoll file descriptor.
|
||||
int epoll_fd_;
|
||||
|
||||
// The timer file descriptor.
|
||||
int timer_fd_;
|
||||
|
||||
// The timer queues.
|
||||
timer_queue_set timer_queues_;
|
||||
|
||||
// Whether the service has been shut down.
|
||||
bool shutdown_;
|
||||
|
||||
// Mutex to protect access to the registered descriptors.
|
||||
mutex registered_descriptors_mutex_;
|
||||
|
||||
// Keep track of all registered descriptors.
|
||||
object_pool<descriptor_state> registered_descriptors_;
|
||||
|
||||
// Helper class to do post-perform_io cleanup.
|
||||
struct perform_io_cleanup_on_block_exit;
|
||||
friend struct perform_io_cleanup_on_block_exit;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/detail/impl/epoll_reactor.hpp"
|
||||
#if defined(ASIO_HEADER_ONLY)
|
||||
# include "asio/detail/impl/epoll_reactor.ipp"
|
||||
#endif // defined(ASIO_HEADER_ONLY)
|
||||
|
||||
#endif // defined(ASIO_HAS_EPOLL)
|
||||
|
||||
#endif // ASIO_DETAIL_EPOLL_REACTOR_HPP
|
|
@ -1,48 +0,0 @@
|
|||
//
|
||||
// detail/event.hpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_EVENT_HPP
|
||||
#define ASIO_DETAIL_EVENT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_HAS_THREADS)
|
||||
# include "asio/detail/null_event.hpp"
|
||||
#elif defined(ASIO_WINDOWS)
|
||||
# include "asio/detail/win_event.hpp"
|
||||
#elif defined(ASIO_HAS_PTHREADS)
|
||||
# include "asio/detail/posix_event.hpp"
|
||||
#elif defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR)
|
||||
# include "asio/detail/std_event.hpp"
|
||||
#else
|
||||
# error Only Windows, POSIX and std::condition_variable are supported!
|
||||
#endif
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
#if !defined(ASIO_HAS_THREADS)
|
||||
typedef null_event event;
|
||||
#elif defined(ASIO_WINDOWS)
|
||||
typedef win_event event;
|
||||
#elif defined(ASIO_HAS_PTHREADS)
|
||||
typedef posix_event event;
|
||||
#elif defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR)
|
||||
typedef std_event event;
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#endif // ASIO_DETAIL_EVENT_HPP
|
|
@ -1,83 +0,0 @@
|
|||
//
|
||||
// detail/eventfd_select_interrupter.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2008 Roelof Naude (roelof.naude at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP
|
||||
#define ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_EVENTFD)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class eventfd_select_interrupter
|
||||
{
|
||||
public:
|
||||
// Constructor.
|
||||
ASIO_DECL eventfd_select_interrupter();
|
||||
|
||||
// Destructor.
|
||||
ASIO_DECL ~eventfd_select_interrupter();
|
||||
|
||||
// Recreate the interrupter's descriptors. Used after a fork.
|
||||
ASIO_DECL void recreate();
|
||||
|
||||
// Interrupt the select call.
|
||||
ASIO_DECL void interrupt();
|
||||
|
||||
// Reset the select interrupt. Returns true if the call was interrupted.
|
||||
ASIO_DECL bool reset();
|
||||
|
||||
// Get the read descriptor to be passed to select.
|
||||
int read_descriptor() const
|
||||
{
|
||||
return read_descriptor_;
|
||||
}
|
||||
|
||||
private:
|
||||
// Open the descriptors. Throws on error.
|
||||
ASIO_DECL void open_descriptors();
|
||||
|
||||
// Close the descriptors.
|
||||
ASIO_DECL void close_descriptors();
|
||||
|
||||
// The read end of a connection used to interrupt the select call. This file
|
||||
// descriptor is passed to select such that when it is time to stop, a single
|
||||
// 64bit value will be written on the other end of the connection and this
|
||||
// descriptor will become readable.
|
||||
int read_descriptor_;
|
||||
|
||||
// The write end of a connection used to interrupt the select call. A single
|
||||
// 64bit non-zero value may be written to this to wake up the select which is
|
||||
// waiting for the other end to become readable. This descriptor will only
|
||||
// differ from the read descriptor when a pipe is used.
|
||||
int write_descriptor_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#if defined(ASIO_HEADER_ONLY)
|
||||
# include "asio/detail/impl/eventfd_select_interrupter.ipp"
|
||||
#endif // defined(ASIO_HEADER_ONLY)
|
||||
|
||||
#endif // defined(ASIO_HAS_EVENTFD)
|
||||
|
||||
#endif // ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue