...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Networking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Classes
|
Free Functions
Class Templates
Services
|
Socket Options
|
I/O Control Commands
Type Requirements
|
Timers |
SSL |
Serial Ports |
Signal Handling |
|||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Classes
Class Templates
Services
Type Requirements
|
Classes
Class Templates
Type Requirements
|
Classes
Class Templates
Services
Serial Port Options
Type Requirements
|
Classes
Class Templates
Services
Type Requirements
|
POSIX-specific |
Windows-specific |
||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Classes
Free Functions
|
Class Templates
Services
Type Requirements
|
Classes
Class Templates
Services
Type Requirements
|
In Boost.Asio, an asynchronous operation is initiated by a function that
is named with the prefix async_
.
These functions will be referred to as initiating functions.
All initiating functions in Boost.Asio take a function object meeting handler requirements as the
final parameter. These handlers accept as their first parameter an lvalue
of type const error_code
.
Implementations of asynchronous operations in Boost.Asio may call the application
programming interface (API) provided by the operating system. If such an
operating system API call results in an error, the handler will be invoked
with a const error_code
lvalue that evaluates to true. Otherwise the handler will be invoked with
a const error_code
lvalue that evaluates to false.
Unless otherwise noted, when the behaviour of an asynchronous operation is
defined "as if" implemented by a POSIX function,
the handler will be invoked with a value of type error_code
that corresponds to the failure condition described by POSIX
for that function, if any. Otherwise the handler will be invoked with an
implementation-defined error_code
value that reflects the operating system error.
Asynchronous operations will not fail with an error condition that indicates
interruption by a signal (POSIX EINTR
).
Asynchronous operations will not fail with any error condition associated
with non-blocking operations (POSIX EWOULDBLOCK
,
EAGAIN
or EINPROGRESS
;
Windows WSAEWOULDBLOCK
or WSAEINPROGRESS
).
All asynchronous operations have an associated io_service
object. Where the initiating function is a member function, the associated
io_service
is that returned
by the get_io_service()
member function on the same object. Where the initiating function is not
a member function, the associated io_service
is that returned by the get_io_service()
member function of the first argument to
the initiating function.
Arguments to initiating functions will be treated as follows:
— If the parameter is declared as a const reference or by-value, the program is not required to guarantee the validity of the argument after the initiating function completes. The implementation may make copies of the argument, and all copies will be destroyed no later than immediately after invocation of the handler.
— If the parameter is declared as a non-const reference, const pointer or non-const pointer, the program must guarantee the validity of the argument until the handler is invoked.
The library implementation is only permitted to make calls to an initiating function's arguments' copy constructors or destructors from a thread that satisfies one of the following conditions:
— The thread is executing any member function of the associated io_service
object.
— The thread is executing the destructor of the associated io_service
object.
— The thread is executing one of the io_service
service access functions use_service
,
add_service
or has_service
, where the first argument is
the associated io_service
object.
— The thread is executing any member function, constructor or destructor of
an object of a class defined in this clause, where the object's get_io_service()
member function returns the associated io_service
object.
— The thread is executing any function defined in this clause, where any argument
to the function has an get_io_service()
member function that returns the associated
io_service
object.
The io_service
object associated
with an asynchronous operation will have unfinished work, as if by maintaining
the existence of one or more objects of class io_service::work
constructed using the io_service
,
until immediately after the handler for the asynchronous operation has been
invoked.
When an asynchronous operation is complete, the handler for the operation will be invoked as if by:
bch
for the handler, as described below.
ios.post(bch)
to schedule the handler for deferred invocation, where ios
is the associated io_service
.
This implies that the handler must not be called directly from within the initiating function, even if the asynchronous operation completes immediately.
A bound completion handler is a handler object that contains a copy of a
user-supplied handler, where the user-supplied handler accepts one or more
arguments. The bound completion handler does not accept any arguments, and
contains values to be passed as arguments to the user-supplied handler. The
bound completion handler forwards the asio_handler_allocate()
, asio_handler_deallocate()
, and asio_handler_invoke()
calls to the corresponding functions for
the user-supplied handler. A bound completion handler meets the requirements
for a completion handler.
For example, a bound completion handler for a ReadHandler
may be implemented as follows:
template<class ReadHandler> struct bound_read_handler { bound_read_handler(ReadHandler handler, const error_code& ec, size_t s) : handler_(handler), ec_(ec), s_(s) { } void operator()() { handler_(ec_, s_); } ReadHandler handler_; const error_code ec_; const size_t s_; }; template<class ReadHandler> void* asio_handler_allocate(size_t size, bound_read_handler<ReadHandler>* this_handler) { using boost::asio::asio_handler_allocate; return asio_handler_allocate(size, &this_handler->handler_); } template<class ReadHandler> void asio_handler_deallocate(void* pointer, std::size_t size, bound_read_handler<ReadHandler>* this_handler) { using boost::asio::asio_handler_deallocate; asio_handler_deallocate(pointer, size, &this_handler->handler_); } template<class F, class ReadHandler> void asio_handler_invoke(const F& f, bound_read_handler<ReadHandler>* this_handler) { using boost::asio::asio_handler_invoke; asio_handler_invoke(f, &this_handler->handler_); }
If the thread that initiates an asynchronous operation terminates before the associated handler is invoked, the behaviour is implementation-defined. Specifically, on Windows versions prior to Vista, unfinished operations are cancelled when the initiating thread exits.
The handler argument to an initiating function defines a handler identity.
That is, the original handler argument and any copies of the handler argument
will be considered equivalent. If the implementation needs to allocate storage
for an asynchronous operation, the implementation will perform asio_handler_allocate(size, &h)
, where size
is the required size in bytes, and h
is the handler. The implementation will perform asio_handler_deallocate(p,
size,
&h)
, where p
is a pointer to the storage, to deallocate the storage prior to the invocation
of the handler via asio_handler_invoke
.
Multiple storage blocks may be allocated for a single asynchronous operation.
By default, initiating functions return void
.
This is always the case when the handler is a function pointer, C++11 lambda,
or a function object produced by boost::bind
or std::bind
.
For other types, the return type may be customised via a two-step process:
handler_type
template, which
is used to determine the true handler type based on the asynchronous
operation's handler's signature.
async_result
template, which
is used both to determine the return type and to extract the return value
from the handler.
These two templates have been specialised to provide support for stackful
coroutines and the C++11 std::future
class.
As an example, consider what happens when enabling std::future
support by using the boost::asio::use_future
special value, as in:
std::future<std::size_t> length = my_socket.async_read_some(my_buffer, boost::asio::use_future);
When a handler signature has the form:
void handler(error_code ec, result_type result);
the initiating function returns a std::future
templated on result_type
.
In the above async_read_some
example, this is std::size_t
. If the asynchronous operation fails,
the error_code
is converted
into a system_error
exception
and passed back to the caller through the future.
Where a handler signature has the form:
void handler(error_code ec);
the initiating function instead returns std::future<void>
.
An accept handler must meet the requirements for a handler.
A value h
of an accept handler
class should work correctly in the expression h(ec)
,
where ec
is an lvalue of
type const error_code
.
A free function as an accept handler:
void accept_handler( const boost::system::error_code& ec) { ... }
An accept handler function object:
struct accept_handler { ... void operator()( const boost::system::error_code& ec) { ... } ... };
A non-static class member function adapted to an accept handler using bind()
:
void my_class::accept_handler( const boost::system::error_code& ec) { ... } ... acceptor.async_accept(..., boost::bind(&my_class::accept_handler, this, boost::asio::placeholders::error));
In the table below, a
denotes
an asynchronous random access read device object, o
denotes an offset of type boost::uint64_t
,
mb
denotes an object satisfying
mutable buffer
sequence requirements, and h
denotes an object satisfying read
handler requirements.
Table 7.1. Buffer-oriented asynchronous random-access read device requirements
operation |
type |
semantics, pre/post-conditions |
---|---|---|
|
|
Returns the |
|
|
Initiates an asynchronous operation to read one or more bytes of
data from the device |
In the table below, a
denotes
an asynchronous write stream object, o
denotes an offset of type boost::uint64_t
,
cb
denotes an object satisfying
constant buffer
sequence requirements, and h
denotes an object satisfying write
handler requirements.
Table 7.2. Buffer-oriented asynchronous random-access write device requirements
operation |
type |
semantics, pre/post-conditions |
---|---|---|
|
|
Returns the |
|
|
Initiates an asynchronous operation to write one or more bytes
of data to the device |
In the table below, a
denotes
an asynchronous read stream object, mb
denotes an object satisfying mutable
buffer sequence requirements, and h
denotes an object satisfying read
handler requirements.
Table 7.3. Buffer-oriented asynchronous read stream requirements
operation |
type |
semantics, pre/post-conditions |
---|---|---|
|
|
Returns the |
|
|
Initiates an asynchronous operation to read one or more bytes of
data from the stream |
In the table below, a
denotes
an asynchronous write stream object, cb
denotes an object satisfying constant
buffer sequence requirements, and h
denotes an object satisfying write
handler requirements.
Table 7.4. Buffer-oriented asynchronous write stream requirements
operation |
type |
semantics, pre/post-conditions |
---|---|---|
|
|
Returns the |
|
|
Initiates an asynchronous operation to write one or more bytes
of data to the stream |
A buffered handshake handler must meet the requirements for a handler.
A value h
of a buffered handshake
handler class should work correctly in the expression h(ec,
s)
,
where ec
is an lvalue of
type const error_code
and s
is an lvalue of type
const size_t
.
A free function as a buffered handshake handler:
void handshake_handler( const boost::system::error_code& ec, std::size_t bytes_transferred) { ... }
A buffered handshake handler function object:
struct handshake_handler { ... void operator()( const boost::system::error_code& ec, std::size_t bytes_transferred) { ... } ... };
A non-static class member function adapted to a buffered handshake handler
using bind()
:
void my_class::handshake_handler( const boost::system::error_code& ec, std::size_t bytes_transferred) { ... } ... socket.async_handshake(..., boost::bind(&my_class::handshake_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
A completion handler must meet the requirements for a handler.
A value h
of a completion
handler class should work correctly in the expression h()
.
A free function as a completion handler:
void completion_handler() { ... }
A completion handler function object:
struct completion_handler { ... void operator()() { ... } ... };
A non-static class member function adapted to a completion handler using
bind()
:
void my_class::completion_handler() { ... } ... my_io_service.post(boost::bind(&my_class::completion_handler, this));
A composed connect handler must meet the requirements for a handler.
A value h
of a composed connect
handler class should work correctly in the expression h(ec,
i)
,
where ec
is an lvalue of
type const error_code
and i
is an lvalue of the
type Iterator
used in the
corresponding connect()
or async_connect()` function.
A free function as a composed connect handler:
void connect_handler( const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator iterator) { ... }
A composed connect handler function object:
struct connect_handler { ... template <typename Iterator> void operator()( const boost::system::error_code& ec, Iterator iterator) { ... } ... };
A non-static class member function adapted to a composed connect handler
using bind()
:
void my_class::connect_handler( const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator iterator) { ... } ... boost::asio::async_connect(..., boost::bind(&my_class::connect_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator));
A connect handler must meet the requirements for a handler.
A value h
of a connect handler
class should work correctly in the expression h(ec)
,
where ec
is an lvalue of
type const error_code
.
A free function as a connect handler:
void connect_handler( const boost::system::error_code& ec) { ... }
A connect handler function object:
struct connect_handler { ... void operator()( const boost::system::error_code& ec) { ... } ... };
A non-static class member function adapted to a connect handler using bind()
:
void my_class::connect_handler( const boost::system::error_code& ec) { ... } ... socket.async_connect(..., boost::bind(&my_class::connect_handler, this, boost::asio::placeholders::error));
In the table below, X
denotes
a class containing objects of type T
,
a
denotes a value of type
X
and u
denotes an identifier.
Table 7.5. ConstBufferSequence requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
|
|
iterator type pointing to |
|
|
post: bool equal_const_buffer_seq( const X& x1, const X& x2) { return distance(x1.begin(), x1.end()) == distance(x2.begin(), x2.end()) && equal(x1.begin(), x1.end(), x2.begin(), equal_buffer); }
and the binary predicate bool equal_buffer( const X::value_type& v1, const X::value_type& v2) { const_buffer b1(v1); const_buffer b2(v2); return buffer_cast<const void*>(b1) == buffer_cast<const void*>(b2) && buffer_size(b1) == buffer_size(b2); }
|
|
|
post: distance(a.begin(), a.end()) == distance(u.begin(), u.end()) && equal(a.begin(), a.end(), u.begin(), equal_buffer)
where the binary predicate bool equal_buffer( const X::value_type& v1, const X::value_type& v2) { const_buffer b1(v1); const_buffer b2(v2); return buffer_cast<const void*>(b1) == buffer_cast<const void*>(b2) && buffer_size(b1) == buffer_size(b2); }
|
|
|
|
note: the destructor is applied to every element of |
|
|
|
|
|
A type that meets the requirements for convertibility to a const buffer must
meet the requirements of CopyConstructible
types (C++ Std, 20.1.3), and the requirements of Assignable
types (C++ Std, 23.1).
In the table below, X
denotes
a class meeting the requirements for convertibility to a const buffer, a
and b
denote values of type X
,
and u
, v
and w
denote identifiers.
Table 7.6. ConvertibleToConstBuffer requirements
expression |
postcondition |
---|---|
const_buffer u(a); const_buffer v(a);
|
buffer_cast<const void*>(u) == buffer_cast<const void*>(v) && buffer_size(u) == buffer_size(v)
|
const_buffer u(a); const_buffer v = a;
|
buffer_cast<const void*>(u) == buffer_cast<const void*>(v) && buffer_size(u) == buffer_size(v)
|
const_buffer u(a); const_buffer v; v = a;
|
buffer_cast<const void*>(u) == buffer_cast<const void*>(v) && buffer_size(u) == buffer_size(v)
|
const_buffer u(a); const X& v = a; const_buffer w(v);
|
buffer_cast<const void*>(u) == buffer_cast<const void*>(w) && buffer_size(u) == buffer_size(w)
|
const_buffer u(a); X v(a); const_buffer w(v);
|
buffer_cast<const void*>(u) == buffer_cast<const void*>(w) && buffer_size(u) == buffer_size(w)
|
const_buffer u(a); X v = a; const_buffer w(v);
|
buffer_cast<const void*>(u) == buffer_cast<const void*>(w) && buffer_size(u) == buffer_size(w)
|
const_buffer u(a); X v(b); v = a; const_buffer w(v);
|
buffer_cast<const void*>(u) == buffer_cast<const void*>(w) && buffer_size(u) == buffer_size(w)
|
A type that meets the requirements for convertibility to a mutable buffer
must meet the requirements of CopyConstructible
types (C++ Std, 20.1.3), and the requirements of Assignable
types (C++ Std, 23.1).
In the table below, X
denotes
a class meeting the requirements for convertibility to a mutable buffer,
a
and b
denote values of type X
,
and u
, v
and w
denote identifiers.
Table 7.7. ConvertibleToMutableBuffer requirements
expression |
postcondition |
---|---|
mutable_buffer u(a); mutable_buffer v(a);
|
buffer_cast<void*>(u) == buffer_cast<void*>(v) && buffer_size(u) == buffer_size(v)
|
mutable_buffer u(a); mutable_buffer v = a;
|
buffer_cast<void*>(u) == buffer_cast<void*>(v) && buffer_size(u) == buffer_size(v)
|
mutable_buffer u(a); mutable_buffer v; v = a;
|
buffer_cast<void*>(u) == buffer_cast<void*>(v) && buffer_size(u) == buffer_size(v)
|
mutable_buffer u(a); const X& v = a; mutable_buffer w(v);
|
buffer_cast<void*>(u) == buffer_cast<void*>(w) && buffer_size(u) == buffer_size(w)
|
mutable_buffer u(a); X v(a); mutable_buffer w(v);
|
buffer_cast<void*>(u) == buffer_cast<void*>(w) && buffer_size(u) == buffer_size(w)
|
mutable_buffer u(a); X v = a; mutable_buffer w(v);
|
buffer_cast<void*>(u) == buffer_cast<void*>(w) && buffer_size(u) == buffer_size(w)
|
mutable_buffer u(a); X v(b); v = a; mutable_buffer w(v);
|
buffer_cast<void*>(u) == buffer_cast<void*>(w) && buffer_size(u) == buffer_size(w)
|
A datagram socket service must meet the requirements for a socket service, as well as the additional requirements listed below.
In the table below, X
denotes
a datagram socket service class for protocol Protocol
, a
denotes a value of type X
,
b
denotes a value of type
X::implementation_type
, e
denotes a value of type Protocol::endpoint
,
ec
denotes a value of type
error_code
, f
denotes a value of type socket_base::message_flags
, mb
denotes a value satisfying mutable
buffer sequence requirements, rh
denotes a value meeting ReadHandler
requirements, cb
denotes a value satisfying constant
buffer sequence requirements, and wh
denotes a value meeting WriteHandler
requirements.
Table 7.8. DatagramSocketService requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
const typename Protocol::endpoint& u = e; a.send_to(b, cb, u, f, ec);
|
|
pre: |
const typename Protocol::endpoint& u = e; a.async_send(b, cb, u, f, wh);
|
|
pre: |
A descriptor service must meet the requirements for an I/O object service with support for movability, as well as the additional requirements listed below.
In the table below, X
denotes
a descriptor service class, a
and ao
denote values of type
X
, b
and c
denote values of type
X::implementation_type
, n
denotes a value of type X::native_handle_type
,
ec
denotes a value of type
error_code
, i
denotes a value meeting IoControlCommand
requirements, and
u
and v
denote identifiers.
Table 7.9. DescriptorService requirements
expression |
return type |
assertion/note |
---|---|---|
|
The implementation-defined native representation of a descriptor.
Must satisfy the requirements of |
|
|
From IoObjectService
requirements. |
|
|
From IoObjectService
requirements. Implicitly cancels asynchronous operations, as if
by calling |
|
a.move_construct(b, c);
|
From IoObjectService
requirements. The underlying native representation is moved from
|
|
a.move_assign(b, ao, c);
|
From IoObjectService
requirements. Implicitly cancels asynchronous operations associated
with |
|
a.assign(b, n, ec);
|
|
pre: |
a.is_open(b);
|
|
|
const X& u = a; const X::implementation_type& v = b; u.is_open(v);
|
|
|
a.close(b, ec);
|
|
If |
a.native_handle(b);
|
|
|
a.cancel(b, ec);
|
|
pre: |
a.io_control(b, i, ec);
|
|
pre: |
An endpoint must meet the requirements of CopyConstructible
types (C++ Std, 20.1.3), and the requirements of Assignable
types (C++ Std, 23.1).
In the table below, X
denotes
an endpoint class, a
denotes
a value of type X
, s
denotes a size in bytes, and u
denotes an identifier.
Table 7.10. Endpoint requirements
expression |
type |
assertion/note |
---|---|---|
|
type meeting protocol requirements |
|
|
||
|
||
|
|
|
|
a pointer |
Returns a pointer suitable for passing as the address
argument to POSIX functions such as |
|
a pointer |
Returns a pointer suitable for passing as the address
argument to POSIX functions such as |
|
|
Returns a value suitable for passing as the address_len
argument to POSIX functions such as |
|
post: |
|
|
|
Returns a value suitable for passing as the address_len
argument to POSIX functions such as |
In the table below, X
denotes
a serial port option class, a
denotes a value of X
, ec
denotes a value of type error_code
, and s
denotes a value of implementation-defined type storage
(where storage
is the type DCB
on Windows and termios
on POSIX platforms), and u
denotes an identifier.
Table 7.11. GettableSerialPortOption requirements
expression |
type |
assertion/note |
---|---|---|
|
|
Retrieves the value of the serial port option from the storage. |
In the table below, X
denotes
a socket option class, a
denotes a value of X
, p
denotes a value that meets the protocol requirements, and
u
denotes an identifier.
Table 7.12. GettableSocketOption requirements
expression |
type |
assertion/note |
---|---|---|
|
|
Returns a value suitable for passing as the level
argument to POSIX |
|
|
Returns a value suitable for passing as the option_name
argument to POSIX |
|
a pointer, convertible to |
Returns a pointer suitable for passing as the option_value
argument to POSIX |
|
|
Returns a value suitable for passing as the option_len
argument to POSIX |
|
post: |
A handler must meet the requirements of CopyConstructible
types (C++ Std, 20.1.3).
In the table below, X
denotes
a handler class, h
denotes
a value of X
, p
denotes a pointer to a block of allocated
memory of type void*
,
s
denotes the size for a
block of allocated memory, and f
denotes a function object taking no arguments.
Table 7.13. Handler requirements
expression |
return type |
assertion/note |
---|---|---|
using boost::asio::asio_handler_allocate; asio_handler_allocate(s, &h);
|
|
Returns a pointer to a block of memory of size |
using boost::asio::asio_handler_deallocate; asio_handler_deallocate(p, s, &h);
|
Frees a block of memory associated with a pointer |
|
using boost::asio::asio_handler_invoke; asio_handler_invoke(f, &h);
|
Causes the function object |
A handle service must meet the requirements for an I/O object service with support for movability, as well as the additional requirements listed below.
In the table below, X
denotes
a handle service class, a
and ao
denote values of type
X
, b
and c
denote values of type
X::implementation_type
, n
denotes a value of type X::native_handle_type
,
ec
denotes a value of type
error_code
, and u
and v
denote identifiers.
Table 7.14. HandleService requirements
expression |
return type |
assertion/note |
---|---|---|
|
The implementation-defined native representation of a handle. Must
satisfy the requirements of |
|
|
From IoObjectService
requirements. |
|
|
From IoObjectService
requirements. Implicitly cancels asynchronous operations, as if
by calling |
|
a.move_construct(b, c);
|
From IoObjectService
requirements. The underlying native representation is moved from
|
|
a.move_assign(b, ao, c);
|
From IoObjectService
requirements. Implicitly cancels asynchronous operations associated
with |
|
a.assign(b, n, ec);
|
|
pre: |
a.is_open(b);
|
|
|
const X& u = a; const X::implementation_type& v = b; u.is_open(v);
|
|
|
a.close(b, ec);
|
|
If |
a.native_handle(b);
|
|
|
a.cancel(b, ec);
|
|
pre: |
A handshake handler must meet the requirements for a handler.
A value h
of a handshake
handler class should work correctly in the expression h(ec)
,
where ec
is an lvalue of
type const error_code
.
A free function as a handshake handler:
void handshake_handler( const boost::system::error_code& ec) { ... }
A handshake handler function object:
struct handshake_handler { ... void operator()( const boost::system::error_code& ec) { ... } ... };
A non-static class member function adapted to a handshake handler using
bind()
:
void my_class::handshake_handler( const boost::system::error_code& ec) { ... } ... ssl_stream.async_handshake(..., boost::bind(&my_class::handshake_handler, this, boost::asio::placeholders::error));
An internet protocol must meet the requirements for a protocol as well as the additional requirements listed below.
In the table below, X
denotes
an internet protocol class, a
denotes a value of type X
,
and b
denotes a value of
type X
.
Table 7.15. InternetProtocol requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
The type of a resolver for the protocol. |
|
|
Returns an object representing the IP version 4 protocol. |
|
|
Returns an object representing the IP version 6 protocol. |
|
convertible to |
Returns whether two protocol objects are equal. |
|
convertible to |
Returns |
In the table below, X
denotes
an I/O control command class, a
denotes a value of X
, and
u
denotes an identifier.
Table 7.16. IoControlCommand requirements
expression |
type |
assertion/note |
---|---|---|
|
|
Returns a value suitable for passing as the request
argument to POSIX |
|
a pointer, convertible to |
An I/O object service must meet the requirements for a service, as well as the requirements listed below.
In the table below, X
denotes
an I/O object service class, a
and ao
denote values of type
X
, b
and c
denote values of type
X::implementation_type
, and u
denotes an identifier.
Table 7.17. IoObjectService requirements
expression |
return type |
assertion/note |
---|---|---|
|
||
|
note: |
|
a.construct(b);
|
||
a.destroy(b);
|
note: |
|
a.move_construct(b, c);
|
note: only required for I/O objects that support movability. |
|
a.move_assign(b, ao, c);
|
note: only required for I/O objects that support movability. |
In the table below, X
denotes
a class containing objects of type T
,
a
denotes a value of type
X
and u
denotes an identifier.
Table 7.18. MutableBufferSequence requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
|
|
iterator type pointing to |
|
|
post: bool equal_mutable_buffer_seq( const X& x1, const X& x2) { return distance(x1.begin(), x1.end()) == distance(x2.begin(), x2.end()) && equal(x1.begin(), x1.end(), x2.begin(), equal_buffer); }
and the binary predicate bool equal_buffer( const X::value_type& v1, const X::value_type& v2) { mutable_buffer b1(v1); mutable_buffer b2(v2); return buffer_cast<const void*>(b1) == buffer_cast<const void*>(b2) && buffer_size(b1) == buffer_size(b2); }
|
|
|
post: distance(a.begin(), a.end()) == distance(u.begin(), u.end()) && equal(a.begin(), a.end(), u.begin(), equal_buffer)
where the binary predicate bool equal_buffer( const X::value_type& v1, const X::value_type& v2) { mutable_buffer b1(v1); mutable_buffer b2(v2); return buffer_cast<const void*>(b1) == buffer_cast<const void*>(b2) && buffer_size(b1) == buffer_size(b2); }
|
|
|
|
note: the destructor is applied to every element of |
|
|
|
|
|
An object handle service must meet the requirements for a handle service, as well as the additional requirements listed below.
In the table below, X
denotes
an object handle service class, a
denotes a value of type X
,
b
denotes a value of type
X::implementation_type
, ec
denotes a value of type error_code
,
and wh
denotes a value meeting
WaitHandler
requirements.
Table 7.19. ObjectHandleService requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
pre: |
|
|
pre: |
A protocol must meet the requirements of CopyConstructible
types (C++ Std, 20.1.3), and the requirements of Assignable
types (C++ Std, 23.1).
In the table below, X
denotes
a protocol class, and a
denotes
a value of X
.
Table 7.20. Protocol requirements
expression |
return type |
assertion/note |
---|---|---|
|
type meeting endpoint requirements |
|
|
|
Returns a value suitable for passing as the domain
argument to POSIX |
|
|
Returns a value suitable for passing as the type
argument to POSIX |
|
|
Returns a value suitable for passing as the protocol
argument to POSIX |
A random access handle service must meet the requirements for a handle service, as well as the additional requirements listed below.
In the table below, X
denotes
a random access handle service class, a
denotes a value of type X
,
b
denotes a value of type
X::implementation_type
, ec
denotes a value of type error_code
,
o
denotes an offset of type
boost::uint64_t, mb
denotes
a value satisfying mutable
buffer sequence requirements, rh
denotes a value meeting ReadHandler
requirements, cb
denotes a value satisfying constant
buffer sequence requirements, and wh
denotes a value meeting WriteHandler
requirements.
Table 7.21. RandomAccessHandleService requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
A raw socket service must meet the requirements for a socket service, as well as the additional requirements listed below.
In the table below, X
denotes
a raw socket service class for protocol Protocol
, a
denotes a value of type X
,
b
denotes a value of type
X::implementation_type
, e
denotes a value of type Protocol::endpoint
,
ec
denotes a value of type
error_code
, f
denotes a value of type socket_base::message_flags
, mb
denotes a value satisfying mutable
buffer sequence requirements, rh
denotes a value meeting ReadHandler
requirements, cb
denotes a value satisfying constant
buffer sequence requirements, and wh
denotes a value meeting WriteHandler
requirements.
Table 7.22. RawSocketService requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
const typename Protocol::endpoint& u = e; a.send_to(b, cb, u, f, ec);
|
|
pre: |
const typename Protocol::endpoint& u = e; a.async_send(b, cb, u, f, wh);
|
|
pre: |
A read handler must meet the requirements for a handler.
A value h
of a read handler
class should work correctly in the expression h(ec,
s)
,
where ec
is an lvalue of
type const error_code
and s
is an lvalue of type
const size_t
.
A free function as a read handler:
void read_handler( const boost::system::error_code& ec, std::size_t bytes_transferred) { ... }
A read handler function object:
struct read_handler { ... void operator()( const boost::system::error_code& ec, std::size_t bytes_transferred) { ... } ... };
A non-static class member function adapted to a read handler using bind()
:
void my_class::read_handler( const boost::system::error_code& ec, std::size_t bytes_transferred) { ... } ... socket.async_read(..., boost::bind(&my_class::read_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
A resolve handler must meet the requirements for a handler.
A value h
of a resolve handler
class should work correctly in the expression h(ec,
i)
,
where ec
is an lvalue of
type const error_code
and i
is an lvalue of type
const ip::basic_resolver_iterator<InternetProtocol>
. InternetProtocol
is the template parameter of the resolver_service
which is used to
initiate the asynchronous operation.
A free function as a resolve handler:
void resolve_handler( const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator iterator) { ... }
A resolve handler function object:
struct resolve_handler { ... void operator()( const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator iterator) { ... } ... };
A non-static class member function adapted to a resolve handler using bind()
:
void my_class::resolve_handler( const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator iterator) { ... } ... resolver.async_resolve(..., boost::bind(&my_class::resolve_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator));
A resolver service must meet the requirements for an I/O object service, as well as the additional requirements listed below.
In the table below, X
denotes
a resolver service class for protocol InternetProtocol
,
a
denotes a value of type
X
, b
denotes a value of type X::implementation_type
,
q
denotes a value of type
ip::basic_resolver_query<InternetProtocol>
,
e
denotes a value of type
ip::basic_endpoint<InternetProtocol>
,
ec
denotes a value of type
error_code
, and h
denotes a value meeting ResolveHandler
requirements.
Table 7.23. ResolverService requirements
expression |
return type |
assertion/note |
---|---|---|
|
From IoObjectService
requirements. Implicitly cancels asynchronous resolve operations,
as if by calling |
|
a.cancel(b, ec);
|
|
Causes any outstanding asynchronous resolve operations to complete
as soon as possible. Handlers for cancelled operations shall be
passed the error code |
a.resolve(b, q, ec);
|
ip::basic_resolver_iterator< InternetProtocol>
|
On success, returns an iterator |
a.async_resolve(b, q, h);
|
Initiates an asynchronous resolve operation that is performed via
the |
|
a.resolve(b, e, ec);
|
ip::basic_resolver_iterator< InternetProtocol>
|
On success, returns an iterator |
a.async_resolve(b, e, h);
|
Initiates an asynchronous resolve operation that is performed via
the |
A sequenced packet socket service must meet the requirements for a socket service, as well as the additional requirements listed below.
In the table below, X
denotes
a stream socket service class, a
denotes a value of type X
,
b
denotes a value of type
X::implementation_type
, ec
denotes a value of type error_code
,
f
denotes a value of type
socket_base::message_flags
, g
denotes an lvalue of type socket_base::message_flags
,
mb
denotes a value satisfying
mutable buffer
sequence requirements, rh
denotes a value meeting ReadHandler
requirements, cb
denotes a value satisfying constant
buffer sequence requirements, and wh
denotes a value meeting WriteHandler
requirements.
Table 7.24. StreamSocketService requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
A serial port service must meet the requirements for an I/O object service with support for movability, as well as the additional requirements listed below.
In the table below, X
denotes
a serial port service class, a
and ao
denote values of type
X
, d
denotes a serial port device name of type std::string
,
b
and c
denote values of type X::implementation_type
, n
denotes a value of type X::native_handle_type
,
ec
denotes a value of type
error_code
, s
denotes a value meeting SettableSerialPortOption
requirements,
g
denotes a value meeting
GettableSerialPortOption
requirements,
mb
denotes a value satisfying
mutable buffer
sequence requirements, rh
denotes a value meeting ReadHandler
requirements, cb
denotes a value satisfying constant
buffer sequence requirements, and wh
denotes a value meeting WriteHandler
requirements. and
u
and v
denote identifiers.
Table 7.25. SerialPortService requirements
expression |
return type |
assertion/note |
---|---|---|
|
The implementation-defined native representation of a serial port.
Must satisfy the requirements of |
|
|
From IoObjectService
requirements. |
|
|
From IoObjectService
requirements. Implicitly cancels asynchronous operations, as if
by calling |
|
a.move_construct(b, c);
|
From IoObjectService
requirements. The underlying native representation is moved from
|
|
a.move_assign(b, ao, c);
|
From IoObjectService
requirements. Implicitly cancels asynchronous operations associated
with |
|
const std::string& u = d; a.open(b, u, ec);
|
|
pre: |
a.assign(b, n, ec);
|
|
pre: |
a.is_open(b);
|
|
|
const X& u = a; const X::implementation_type& v = b; u.is_open(v);
|
|
|
a.close(b, ec);
|
|
If |
a.native_handle(b);
|
|
|
a.cancel(b, ec);
|
|
pre: |
a.set_option(b, s, ec);
|
|
pre: |
a.get_option(b, g, ec);
|
|
pre: |
const X& u = a; const X::implementation_type& v = b; u.get_option(v, g, ec);
|
|
pre: |
a.send_break(b, ec);
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
A class is a service if it is publicly derived from another service, or if
it is a class derived from io_service::service
and contains a publicly-accessible declaration as follows:
static io_service::id id;
All services define a one-argument constructor that takes a reference to
the io_service
object that
owns the service. This constructor is explicit, preventing
its participation in automatic conversions. For example:
class my_service : public io_service::service { public: static io_service::id id; explicit my_service(io_service& ios); private: virtual void shutdown_service(); ... };
A service's shutdown_service
member function must cause all copies of user-defined handler objects that
are held by the service to be destroyed.
In the table below, X
denotes
a serial port option class, a
denotes a value of X
, ec
denotes a value of type error_code
, and s
denotes a value of implementation-defined type storage
(where storage
is the type DCB
on Windows and termios
on POSIX platforms), and u
denotes an identifier.
Table 7.26. SettableSerialPortOption requirements
expression |
type |
assertion/note |
---|---|---|
|
|
Saves the value of the serial port option to the storage. |
In the table below, X
denotes
a socket option class, a
denotes a value of X
, p
denotes a value that meets the protocol requirements, and
u
denotes an identifier.
Table 7.27. SettableSocketOption requirements
expression |
type |
assertion/note |
---|---|---|
|
|
Returns a value suitable for passing as the level
argument to POSIX |
|
|
Returns a value suitable for passing as the option_name
argument to POSIX |
|
a pointer, convertible to |
Returns a pointer suitable for passing as the option_value
argument to POSIX |
|
|
Returns a value suitable for passing as the option_len
argument to POSIX |
A shutdown handler must meet the requirements for a handler.
A value h
of a shutdown handler
class should work correctly in the expression h(ec)
,
where ec
is an lvalue of
type const error_code
.
A free function as a shutdown handler:
void shutdown_handler( const boost::system::error_code& ec) { ... }
A shutdown handler function object:
struct shutdown_handler { ... void operator()( const boost::system::error_code& ec) { ... } ... };
A non-static class member function adapted to a shutdown handler using bind()
:
void my_class::shutdown_handler( const boost::system::error_code& ec) { ... } ... ssl_stream.async_shutdown( boost::bind(&my_class::shutdown_handler, this, boost::asio::placeholders::error));
A signal handler must meet the requirements for a handler.
A value h
of a signal handler
class should work correctly in the expression h(ec,
n)
,
where ec
is an lvalue of
type const error_code
and n
is an lvalue of type
const int
.
A free function as a signal handler:
void signal_handler( const boost::system::error_code& ec, int signal_number) { ... }
A signal handler function object:
struct signal_handler { ... void operator()( const boost::system::error_code& ec, int signal_number) { ... } ... };
A non-static class member function adapted to a signal handler using bind()
:
void my_class::signal_handler( const boost::system::error_code& ec, int signal_number) { ... } ... my_signal_set.async_wait( boost::bind(&my_class::signal_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::signal_number));
A signal set service must meet the requirements for an I/O object service, as well as the additional requirements listed below.
In the table below, X
denotes
a signal set service class, a
denotes a value of type X
,
b
denotes a value of type
X::implementation_type
, ec
denotes a value of type error_code
,
n
denotes a value of type
int
, and sh
denotes a value meeting SignalHandler
requirements.
Table 7.28. SignalSetService requirements
expression |
return type |
assertion/note |
---|---|---|
|
From IoObjectService
requirements. |
|
|
From IoObjectService
requirements. Implicitly clears the registered signals as if by
calling |
|
a.add(b, n, ec);
|
|
|
a.remove(b, n, ec);
|
|
|
a.clear(b, ec);
|
|
|
a.cancel(b, ec);
|
|
|
|
|
pre: |
A socket acceptor service must meet the requirements for an I/O object service, as well as the additional requirements listed below.
In the table below, X
denotes
a socket acceptor service class for protocol Protocol
, a
and ao
denote values of type
X
, b
and c
denote values of type
X::implementation_type
, p
denotes a value of type Protocol
,
n
denotes a value of type
X::native_handle_type
, e
denotes a value of type Protocol::endpoint
,
ec
denotes a value of type
error_code
, s
denotes a value meeting SettableSocketOption
requirements,
g
denotes a value meeting
GettableSocketOption
requirements, i
denotes a
value meeting IoControlCommand
requirements,
k
denotes a value of type
basic_socket<Protocol, SocketService>
where SocketService
is a
type meeting socket service
requirements, ah
denotes
a value meeting AcceptHandler
requirements, and
u
and v
denote identifiers.
Table 7.29. SocketAcceptorService requirements
expression |
return type |
assertion/note |
---|---|---|
|
The implementation-defined native representation of a socket acceptor.
Must satisfy the requirements of |
|
|
From IoObjectService
requirements. |
|
|
From IoObjectService
requirements. Implicitly cancels asynchronous operations, as if
by calling |
|
a.move_construct(b, c);
|
From IoObjectService
requirements. The underlying native representation is moved from
|
|
a.move_assign(b, ao, c);
|
From IoObjectService
requirements. Implicitly cancels asynchronous operations associated
with |
|
a.open(b, p, ec);
|
|
pre: |
a.assign(b, p, n, ec);
|
|
pre: |
a.is_open(b);
|
|
|
const X& u = a; const X::implementation_type& v = b; u.is_open(v);
|
|
|
a.close(b, ec);
|
|
If |
a.native_handle(b);
|
|
|
a.cancel(b, ec);
|
|
pre: |
a.set_option(b, s, ec);
|
|
pre: |
a.get_option(b, g, ec);
|
|
pre: |
const X& u = a; const X::implementation_type& v = b; u.get_option(v, g, ec);
|
|
pre: |
a.io_control(b, i, ec);
|
|
pre: |
const typename Protocol::endpoint& u = e; a.bind(b, u, ec);
|
|
pre: |
a.local_endpoint(b, ec);
|
|
pre: |
const X& u = a; const X::implementation_type& v = b; u.local_endpoint(v, ec);
|
|
pre: |
a.accept(b, k, &e, ec);
|
|
pre: |
a.accept(b, k, 0, ec);
|
|
pre: |
a.async_accept(b, k, &e, ah);
|
pre: |
|
a.async_accept(b, k, 0, ah);
|
pre: |
A socket service must meet the requirements for an I/O object service with support for movability, as well as the additional requirements listed below.
In the table below, X
denotes
a socket service class for protocol Protocol
, a
and ao
denote values of type
X
, b
and c
denote values of type
X::implementation_type
, p
denotes a value of type Protocol
,
n
denotes a value of type
X::native_handle_type
, e
denotes a value of type Protocol::endpoint
,
ec
denotes a value of type
error_code
, s
denotes a value meeting SettableSocketOption
requirements,
g
denotes a value meeting
GettableSocketOption
requirements, i
denotes a
value meeting IoControlCommand
requirements,
h
denotes a value of type
socket_base::shutdown_type
, ch
denotes a value meeting ConnectHandler
requirements, and
u
and v
denote identifiers.
Table 7.30. SocketService requirements
expression |
return type |
assertion/note |
---|---|---|
|
The implementation-defined native representation of a socket. Must
satisfy the requirements of |
|
|
From IoObjectService
requirements. |
|
|
From IoObjectService
requirements. Implicitly cancels asynchronous operations, as if
by calling |
|
a.move_construct(b, c);
|
From IoObjectService
requirements. The underlying native representation is moved from
|
|
a.move_assign(b, ao, c);
|
From IoObjectService
requirements. Implicitly cancels asynchronous operations associated
with |
|
a.open(b, p, ec);
|
|
pre: |
a.assign(b, p, n, ec);
|
|
pre: |
a.is_open(b);
|
|
|
const X& u = a; const X::implementation_type& v = b; u.is_open(v);
|
|
|
a.close(b, ec);
|
|
If |
a.native_handle(b);
|
|
|
a.cancel(b, ec);
|
|
pre: |
a.set_option(b, s, ec);
|
|
pre: |
a.get_option(b, g, ec);
|
|
pre: |
const X& u = a; const X::implementation_type& v = b; u.get_option(v, g, ec);
|
|
pre: |
a.io_control(b, i, ec);
|
|
pre: |
a.at_mark(b, ec);
|
|
pre: |
const X& u = a; const X::implementation_type& v = b; u.at_mark(v, ec);
|
|
pre: |
a.available(b, ec);
|
|
pre: |
const X& u = a; const X::implementation_type& v = b; u.available(v, ec);
|
|
pre: |
const typename Protocol::endpoint& u = e; a.bind(b, u, ec);
|
|
pre: |
a.shutdown(b, h, ec);
|
|
pre: |
a.local_endpoint(b, ec);
|
|
pre: |
const X& u = a; const X::implementation_type& v = b; u.local_endpoint(v, ec);
|
|
pre: |
a.remote_endpoint(b, ec);
|
|
pre: |
const X& u = a; const X::implementation_type& v = b; u.remote_endpoint(v, ec);
|
|
pre: |
const typename Protocol::endpoint& u = e; a.connect(b, u, ec);
|
|
pre: |
const typename Protocol::endpoint& u = e; a.async_connect(b, u, ch);
|
pre: |
A stream descriptor service must meet the requirements for a descriptor service, as well as the additional requirements listed below.
In the table below, X
denotes
a stream descriptor service class, a
denotes a value of type X
,
b
denotes a value of type
X::implementation_type
, ec
denotes a value of type error_code
,
mb
denotes a value satisfying
mutable buffer
sequence requirements, rh
denotes a value meeting ReadHandler
requirements, cb
denotes a value satisfying constant
buffer sequence requirements, and wh
denotes a value meeting WriteHandler
requirements.
Table 7.31. StreamDescriptorService requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
A stream handle service must meet the requirements for a handle service, as well as the additional requirements listed below.
In the table below, X
denotes
a stream handle service class, a
denotes a value of type X
,
b
denotes a value of type
X::implementation_type
, ec
denotes a value of type error_code
,
mb
denotes a value satisfying
mutable buffer
sequence requirements, rh
denotes a value meeting ReadHandler
requirements, cb
denotes a value satisfying constant
buffer sequence requirements, and wh
denotes a value meeting WriteHandler
requirements.
Table 7.32. StreamHandleService requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
A stream socket service must meet the requirements for a socket service, as well as the additional requirements listed below.
In the table below, X
denotes
a stream socket service class, a
denotes a value of type X
,
b
denotes a value of type
X::implementation_type
, ec
denotes a value of type error_code
,
f
denotes a value of type
socket_base::message_flags
, mb
denotes a value satisfying mutable
buffer sequence requirements, rh
denotes a value meeting ReadHandler
requirements, cb
denotes a value satisfying constant
buffer sequence requirements, and wh
denotes a value meeting WriteHandler
requirements.
Table 7.33. StreamSocketService requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
pre: |
|
|
pre: |
|
|
pre: |
|
|
pre: |
In the table below, a
denotes
a synchronous random-access read device object, o
denotes an offset of type boost::uint64_t
,
mb
denotes an object satisfying
mutable buffer
sequence requirements, and ec
denotes an object of type error_code
.
Table 7.34. Buffer-oriented synchronous random-access read device requirements
operation |
type |
semantics, pre/post-conditions |
---|---|---|
|
|
Equivalent to: error_code ec; size_t s = a.read_some_at(o, mb, ec); if (ec) throw system_error(ec); return s;
|
|
|
Reads one or more bytes of data from the device |
In the table below, a
denotes
a synchronous random-access write device object, o
denotes an offset of type boost::uint64_t
,
cb
denotes an object satisfying
constant buffer
sequence requirements, and ec
denotes an object of type error_code
.
Table 7.35. Buffer-oriented synchronous random-access write device requirements
operation |
type |
semantics, pre/post-conditions |
---|---|---|
|
|
Equivalent to: error_code ec; size_t s = a.write_some(o, cb, ec); if (ec) throw system_error(ec); return s;
|
|
|
Writes one or more bytes of data to the device |
In the table below, a
denotes
a synchronous read stream object, mb
denotes an object satisfying mutable
buffer sequence requirements, and ec
denotes an object of type error_code
.
Table 7.36. Buffer-oriented synchronous read stream requirements
operation |
type |
semantics, pre/post-conditions |
---|---|---|
|
|
Equivalent to: error_code ec; size_t s = a.read_some(mb, ec); if (ec) throw system_error(ec); return s;
|
|
|
Reads one or more bytes of data from the stream |
In the table below, a
denotes
a synchronous write stream object, cb
denotes an object satisfying constant
buffer sequence requirements, and ec
denotes an object of type error_code
.
Table 7.37. Buffer-oriented synchronous write stream requirements
operation |
type |
semantics, pre/post-conditions |
---|---|---|
|
|
Equivalent to: error_code ec; size_t s = a.write_some(cb, ec); if (ec) throw system_error(ec); return s;
|
|
|
Writes one or more bytes of data to the stream |
In the table below, X
denotes
a time traits class for time type Time
,
t
, t1
,
and t2
denote values of type
Time
, and d
denotes a value of type X::duration_type
.
Table 7.38. TimeTraits requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
Represents an absolute time. Must support default construction,
and meet the requirements for |
|
Represents the difference between two absolute times. Must support
default construction, and meet the requirements for |
|
|
|
Returns the current time. |
|
|
Returns a new absolute time resulting from adding the duration
|
|
|
Returns the duration resulting from subtracting |
|
|
Returns whether |
|
|
Returns the |
A timer service must meet the requirements for an I/O object service, as well as the additional requirements listed below.
In the table below, X
denotes
a timer service class for time type Time
and traits type TimeTraits
,
a
denotes a value of type
X
, b
denotes a value of type X::implementation_type
,
t
denotes a value of type
Time
, d
denotes a value of type TimeTraits::duration_type
,
e
denotes a value of type
error_code
, and h
denotes a value meeting WaitHandler
requirements.
Table 7.39. TimerService requirements
expression |
return type |
assertion/note |
---|---|---|
|
From IoObjectService
requirements. Implicitly cancels asynchronous wait operations,
as if by calling |
|
a.cancel(b, e);
|
|
Causes any outstanding asynchronous wait operations to complete
as soon as possible. Handlers for cancelled operations shall be
passed the error code |
|
|
|
a.expires_at(b, t, e);
|
|
Implicitly cancels asynchronous wait operations, as if by calling
|
|
|
Returns a value equivalent to |
a.expires_from_now(b, d, e);
|
|
Equivalent to |
a.wait(b, e);
|
|
Sets |
a.async_wait(b, h);
|
Initiates an asynchronous wait operation that is performed via
the |
A waitable timer service must meet the requirements for an I/O object service, as well as the additional requirements listed below.
In the table below, X
denotes
a waitable timer service class for clock type Clock
,
where Clock
meets the C++11
clock type requirements, a
denotes a value of type X
,
b
denotes a value of type
X::implementation_type
, t
denotes a value of type Clock::time_point
,
d
denotes a value of type
Clock::duration
, e
denotes a value of type error_code
,
and h
denotes a value meeting
WaitHandler
requirements.
Table 7.40. WaitableTimerService requirements
expression |
return type |
assertion/note |
---|---|---|
|
From IoObjectService
requirements. Implicitly cancels asynchronous wait operations,
as if by calling |
|
a.cancel(b, e);
|
|
Causes any outstanding asynchronous wait operations to complete
as soon as possible. Handlers for cancelled operations shall be
passed the error code |
|
|
|
a.expires_at(b, t, e);
|
|
Implicitly cancels asynchronous wait operations, as if by calling
|
|
|
Returns a value equivalent to |
a.expires_from_now(b, d, e);
|
|
Equivalent to |
a.wait(b, e);
|
|
Sets |
a.async_wait(b, h);
|
Initiates an asynchronous wait operation that is performed via
the |
A wait handler must meet the requirements for a handler.
A value h
of a wait handler
class should work correctly in the expression h(ec)
,
where ec
is an lvalue of
type const error_code
.
A free function as a wait handler:
void wait_handler( const boost::system::error_code& ec) { ... }
A wait handler function object:
struct wait_handler { ... void operator()( const boost::system::error_code& ec) { ... } ... };
A non-static class member function adapted to a wait handler using bind()
:
void my_class::wait_handler( const boost::system::error_code& ec) { ... } ... socket.async_wait(..., boost::bind(&my_class::wait_handler, this, boost::asio::placeholders::error));
In the table below, X
denotes
a wait traits class for clock type Clock
,
where Clock
meets the C++11
type requirements for a clock, and d
denotes a value of type Clock::duration
.
Table 7.41. WaitTraits requirements
expression |
return type |
assertion/note |
---|---|---|
|
|
Returns the maximum duration to be used for an individual, implementation-defined wait operation. |
A write handler must meet the requirements for a handler.
A value h
of a write handler
class should work correctly in the expression h(ec,
s)
,
where ec
is an lvalue of
type const error_code
and s
is an lvalue of type
const size_t
.
A free function as a write handler:
void write_handler( const boost::system::error_code& ec, std::size_t bytes_transferred) { ... }
A write handler function object:
struct write_handler { ... void operator()( const boost::system::error_code& ec, std::size_t bytes_transferred) { ... } ... };
A non-static class member function adapted to a write handler using bind()
:
void my_class::write_handler( const boost::system::error_code& ec, std::size_t bytes_transferred) { ... } ... socket.async_write(..., boost::bind(&my_class::write_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
template< typename Service> void add_service( io_service & ios, Service * svc);
This function is used to add a service to the io_service
.
The io_service
object that owns the service.
The service object. On success, ownership of the service object is
transferred to the io_service
. When the io_service
object is destroyed, it will destroy the service object by performing:
delete static_cast<io_service::service*>(svc)
Thrown if a service of the given type is already present in the io_service
.
Thrown if the service's owning io_service
is not the io_service
object specified by the ios parameter.
Header: boost/asio/io_service.hpp
Convenience header: boost/asio.hpp
Default allocation function for handlers.
void * asio_handler_allocate( std::size_t size, ... );
Asynchronous operations may need to allocate temporary objects. Since asynchronous operations have a handler function object, these temporary objects can be said to be associated with the handler.
Implement asio_handler_allocate and asio_handler_deallocate for your own handlers to provide custom allocation for these temporary objects.
The default implementation of these allocation hooks uses operator
new
and operator
delete
.
All temporary objects associated with a handler will be deallocated before the upcall to the handler is performed. This allows the same memory to be reused for a subsequent asynchronous operation initiated by the handler.
class my_handler; void* asio_handler_allocate(std::size_t size, my_handler* context) { return ::operator new(size); } void asio_handler_deallocate(void* pointer, std::size_t size, my_handler* context) { ::operator delete(pointer); }
Header: boost/asio/handler_alloc_hook.hpp
Convenience header: boost/asio.hpp
Default deallocation function for handlers.
void asio_handler_deallocate( void * pointer, std::size_t size, ... );
Implement asio_handler_allocate and asio_handler_deallocate for your own handlers to provide custom allocation for the associated temporary objects.
The default implementation of these allocation hooks uses operator
new
and operator
delete
.
Header: boost/asio/handler_alloc_hook.hpp
Convenience header: boost/asio.hpp
Default invoke function for handlers.
template< typename Function> void asio_handler_invoke( Function & function, ... ); » more... template< typename Function> void asio_handler_invoke( const Function & function, ... ); » more...
Completion handlers for asynchronous operations are invoked by the io_service
associated with the corresponding object (e.g. a socket or deadline_timer).
Certain guarantees are made on when the handler may be invoked, in particular
that a handler can only be invoked from a thread that is currently calling
run()
on the corresponding io_service
object. Handlers may
subsequently be invoked through other objects (such as io_service::strand
objects) that provide additional
guarantees.
When asynchronous operations are composed from other asynchronous operations, all intermediate handlers should be invoked using the same method as the final handler. This is required to ensure that user-defined objects are not accessed in a way that may violate the guarantees. This hooking function ensures that the invoked method used for the final handler is accessible at each intermediate step.
Implement asio_handler_invoke for your own handlers to specify a custom invocation strategy.
This default implementation invokes the function object like so:
function();
If necessary, the default implementation makes a copy of the function object so that the non-const operator() can be used.
class my_handler; template <typename Function> void asio_handler_invoke(Function function, my_handler* context) { context->strand_.dispatch(function); }
Header: boost/asio/handler_invoke_hook.hpp
Convenience header: boost/asio.hpp
Default handler invocation hook used for non-const function objects.
template< typename Function> void asio_handler_invoke( Function & function, ... );
Default handler invocation hook used for const function objects.
template< typename Function> void asio_handler_invoke( const Function & function, ... );
Default continuation function for handlers.
bool asio_handler_is_continuation( ... );
Asynchronous operations may represent a continuation of the asynchronous control flow associated with the current handler. The implementation can use this knowledge to optimise scheduling of the handler.
Implement asio_handler_is_continuation for your own handlers to indicate when a handler represents a continuation.
The default implementation of the continuation hook returns false
.
class my_handler; bool asio_handler_is_continuation(my_handler* context) { return true; }
Header: boost/asio/handler_continuation_hook.hpp
Convenience header: boost/asio.hpp
Asynchronously establishes a socket connection by trying each endpoint in a sequence.
template< typename Protocol, typename SocketService, typename Iterator, typename ComposedConnectHandler> void-or-deduced async_connect( basic_socket< Protocol, SocketService > & s, Iterator begin, ComposedConnectHandler handler); » more... template< typename Protocol, typename SocketService, typename Iterator, typename ComposedConnectHandler> void-or-deduced async_connect( basic_socket< Protocol, SocketService > & s, Iterator begin, Iterator end, ComposedConnectHandler handler); » more... template< typename Protocol, typename SocketService, typename Iterator, typename ConnectCondition, typename ComposedConnectHandler> void-or-deduced async_connect( basic_socket< Protocol, SocketService > & s, Iterator begin, ConnectCondition connect_condition, ComposedConnectHandler handler); » more... template< typename Protocol, typename SocketService, typename Iterator, typename ConnectCondition, typename ComposedConnectHandler> void-or-deduced async_connect( basic_socket< Protocol, SocketService > & s, Iterator begin, Iterator end, ConnectCondition connect_condition, ComposedConnectHandler handler); » more...
Header: boost/asio/connect.hpp
Convenience header: boost/asio.hpp
Asynchronously establishes a socket connection by trying each endpoint in a sequence.
template< typename Protocol, typename SocketService, typename Iterator, typename ComposedConnectHandler> void-or-deduced async_connect( basic_socket< Protocol, SocketService > & s, Iterator begin, ComposedConnectHandler handler);
This function attempts to connect a socket to one of a sequence of endpoints.
It does this by repeated calls to the socket's async_connect
member function, once for each endpoint in the sequence, until a connection
is successfully established.
The socket to be connected. If the socket is already open, it will be closed.
An iterator pointing to the start of a sequence of endpoints.
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:
void handler( // Result of operation. if the sequence is empty, set to // boost::asio::error::not_found. Otherwise, contains the // error from the last connection attempt. const boost::system::error_code& error, // On success, an iterator denoting the successfully // connected endpoint. Otherwise, the end iterator. Iterator iterator );
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 boost::asio::io_service::post()
.
This overload assumes that a default constructed object of type Iterator
represents the end of the sequence.
This is a valid assumption for iterator types such as boost::asio::ip::tcp::resolver::iterator
.
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 boost::system::error_code& ec, tcp::resolver::iterator i) { if (!ec) { boost::asio::async_connect(s, i, connect_handler); } } // ... void connect_handler( const boost::system::error_code& ec, tcp::resolver::iterator i) { // ... }
Asynchronously establishes a socket connection by trying each endpoint in a sequence.
template< typename Protocol, typename SocketService, typename Iterator, typename ComposedConnectHandler> void-or-deduced async_connect( basic_socket< Protocol, SocketService > & s, Iterator begin, Iterator end, ComposedConnectHandler handler);
This function attempts to connect a socket to one of a sequence of endpoints.
It does this by repeated calls to the socket's async_connect
member function, once for each endpoint in the sequence, until a connection
is successfully established.
The socket to be connected. If the socket is already open, it will be closed.
An iterator pointing to the start of a sequence of endpoints.
An iterator pointing to the end of a sequence of endpoints.
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:
void handler( // Result of operation. if the sequence is empty, set to // boost::asio::error::not_found. Otherwise, contains the // error from the last connection attempt. const boost::system::error_code& error, // On success, an iterator denoting the successfully // connected endpoint. Otherwise, the end iterator. Iterator iterator );
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 boost::asio::io_service::post()
.
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 boost::system::error_code& ec, tcp::resolver::iterator i) { if (!ec) { tcp::resolver::iterator end; boost::asio::async_connect(s, i, end, connect_handler); } } // ... void connect_handler( const boost::system::error_code& ec, tcp::resolver::iterator i) { // ... }
Asynchronously establishes a socket connection by trying each endpoint in a sequence.
template< typename Protocol, typename SocketService, typename Iterator, typename ConnectCondition, typename ComposedConnectHandler> void-or-deduced async_connect( basic_socket< Protocol, SocketService > & s, Iterator begin, ConnectCondition connect_condition, ComposedConnectHandler handler);
This function attempts to connect a socket to one of a sequence of endpoints.
It does this by repeated calls to the socket's async_connect
member function, once for each endpoint in the sequence, until a connection
is successfully established.
The socket to be connected. If the socket is already open, it will be closed.
An iterator pointing to the start of a sequence of endpoints.
A function object that is called prior to each connection attempt. The signature of the function object must be:
Iterator connect_condition( const boost::system::error_code& ec, Iterator next);
The ec
parameter
contains the result from the most recent connect operation. Before
the first connection attempt, ec
is always set to indicate success. The 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.
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:
void handler( // Result of operation. if the sequence is empty, set to // boost::asio::error::not_found. Otherwise, contains the // error from the last connection attempt. const boost::system::error_code& error, // On success, an iterator denoting the successfully // connected endpoint. Otherwise, the end iterator. Iterator iterator );
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 boost::asio::io_service::post()
.
This overload assumes that a default constructed object of type Iterator
represents the end of the sequence.
This is a valid assumption for iterator types such as boost::asio::ip::tcp::resolver::iterator
.
The following connect condition function object can be used to output information about the individual connection attempts:
struct my_connect_condition { template <typename Iterator> Iterator operator()( const boost::system::error_code& ec, Iterator next) { if (ec) std::cout << "Error: " << ec.message() << std::endl; std::cout << "Trying: " << next->endpoint() << std::endl; return next; } };
It would be used with the boost::asio::connect
function as follows:
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 boost::system::error_code& ec, tcp::resolver::iterator i) { if (!ec) { boost::asio::async_connect(s, i, my_connect_condition(), connect_handler); } } // ... void connect_handler( const boost::system::error_code& ec, tcp::resolver::iterator i) { if (ec) { // An error occurred. } else { std::cout << "Connected to: " << i->endpoint() << std::endl; } }
Asynchronously establishes a socket connection by trying each endpoint in a sequence.
template< typename Protocol, typename SocketService, typename Iterator, typename ConnectCondition, typename ComposedConnectHandler> void-or-deduced async_connect( basic_socket< Protocol, SocketService > & s, Iterator begin, Iterator end, ConnectCondition connect_condition, ComposedConnectHandler handler);
This function attempts to connect a socket to one of a sequence of endpoints.
It does this by repeated calls to the socket's async_connect
member function, once for each endpoint in the sequence, until a connection
is successfully established.
The socket to be connected. If the socket is already open, it will be closed.
An iterator pointing to the start of a sequence of endpoints.
An iterator pointing to the end of a sequence of endpoints.
A function object that is called prior to each connection attempt. The signature of the function object must be:
Iterator connect_condition( const boost::system::error_code& ec, Iterator next);
The ec
parameter
contains the result from the most recent connect operation. Before
the first connection attempt, ec
is always set to indicate success. The 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.
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:
void handler( // Result of operation. if the sequence is empty, set to // boost::asio::error::not_found. Otherwise, contains the // error from the last connection attempt. const boost::system::error_code& error, // On success, an iterator denoting the successfully // connected endpoint. Otherwise, the end iterator. Iterator iterator );
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 boost::asio::io_service::post()
.
The following connect condition function object can be used to output information about the individual connection attempts:
struct my_connect_condition { template <typename Iterator> Iterator operator()( const boost::system::error_code& ec, Iterator next) { if (ec) std::cout << "Error: " << ec.message() << std::endl; std::cout << "Trying: " << next->endpoint() << std::endl; return next; } };
It would be used with the boost::asio::connect
function as follows:
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 boost::system::error_code& ec, tcp::resolver::iterator i) { if (!ec) { tcp::resolver::iterator end; boost::asio::async_connect(s, i, end, my_connect_condition(), connect_handler); } } // ... void connect_handler( const boost::system::error_code& ec, tcp::resolver::iterator i) { if (ec) { // An error occurred. } else { std::cout << "Connected to: " << i->endpoint() << std::endl; } }
Start an asynchronous operation to read a certain amount of data from a stream.
template< typename AsyncReadStream, typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_read( AsyncReadStream & s, const MutableBufferSequence & buffers, ReadHandler handler); » more... template< typename AsyncReadStream, typename MutableBufferSequence, typename CompletionCondition, typename ReadHandler> void-or-deduced async_read( AsyncReadStream & s, const MutableBufferSequence & buffers, CompletionCondition completion_condition, ReadHandler handler); » more... template< typename AsyncReadStream, typename Allocator, typename ReadHandler> void-or-deduced async_read( AsyncReadStream & s, basic_streambuf< Allocator > & b, ReadHandler handler); » more... template< typename AsyncReadStream, typename Allocator, typename CompletionCondition, typename ReadHandler> void-or-deduced async_read( AsyncReadStream & s, basic_streambuf< Allocator > & b, CompletionCondition completion_condition, ReadHandler handler); » more...
Header: boost/asio/read.hpp
Convenience header: boost/asio.hpp
Start an asynchronous operation to read a certain amount of data from a stream.
template< typename AsyncReadStream, typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_read( AsyncReadStream & s, const MutableBufferSequence & buffers, ReadHandler handler);
This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. The program must ensure that the stream performs no other read operations (such as async_read, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.
The stream from which the data is to be read. The type must support the AsyncReadStream concept.
One or more buffers into which the data will be read. The sum of the buffer sizes indicates the maximum number of bytes to read from the stream. 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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes copied into the // buffers. If an error occurred, // this will be the number of // bytes successfully transferred // prior to the error. );
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 boost::asio::io_service::post()
.
To read into a single data buffer use the buffer
function as follows:
boost::asio::async_read(s, boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on reading into multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
This overload is equivalent to calling:
boost::asio::async_read( s, buffers, boost::asio::transfer_all(), handler);
Start an asynchronous operation to read a certain amount of data from a stream.
template< typename AsyncReadStream, typename MutableBufferSequence, typename CompletionCondition, typename ReadHandler> void-or-deduced async_read( AsyncReadStream & s, const MutableBufferSequence & buffers, CompletionCondition completion_condition, ReadHandler handler);
This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
The stream from which the data is to be read. The type must support the AsyncReadStream concept.
One or more buffers into which the data will be read. The sum of the buffer sizes indicates the maximum number of bytes to read from the stream. 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.
The function object to be called to determine whether the read operation is complete. The signature of the function object must be:
std::size_t completion_condition( // Result of latest async_read_some operation. const boost::system::error_code& error, // Number of bytes transferred so far. std::size_t bytes_transferred );
A return value of 0 indicates that the read operation is complete. A non-zero return value indicates the maximum number of bytes to be read on the next call to the stream's async_read_some function.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes copied into the // buffers. If an error occurred, // this will be the number of // bytes successfully transferred // prior to the error. );
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 boost::asio::io_service::post()
.
To read into a single data buffer use the buffer
function as follows:
boost::asio::async_read(s, boost::asio::buffer(data, size), boost::asio::transfer_at_least(32), handler);
See the buffer
documentation for information on reading into multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Start an asynchronous operation to read a certain amount of data from a stream.
template< typename AsyncReadStream, typename Allocator, typename ReadHandler> void-or-deduced async_read( AsyncReadStream & s, basic_streambuf< Allocator > & b, ReadHandler handler);
This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. The program must ensure that the stream performs no other read operations (such as async_read, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.
The stream from which the data is to be read. The type must support the AsyncReadStream concept.
A basic_streambuf
object into
which the data will be read. Ownership of the streambuf is retained
by the caller, which must guarantee that it remains valid until the
handler is called.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes copied into the // buffers. If an error occurred, // this will be the number of // bytes successfully transferred // prior to the error. );
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 boost::asio::io_service::post()
.
This overload is equivalent to calling:
boost::asio::async_read( s, b, boost::asio::transfer_all(), handler);
Start an asynchronous operation to read a certain amount of data from a stream.
template< typename AsyncReadStream, typename Allocator, typename CompletionCondition, typename ReadHandler> void-or-deduced async_read( AsyncReadStream & s, basic_streambuf< Allocator > & b, CompletionCondition completion_condition, ReadHandler handler);
This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. The program must ensure that the stream performs no other read operations (such as async_read, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.
The stream from which the data is to be read. The type must support the AsyncReadStream concept.
A basic_streambuf
object into
which the data will be read. Ownership of the streambuf is retained
by the caller, which must guarantee that it remains valid until the
handler is called.
The function object to be called to determine whether the read operation is complete. The signature of the function object must be:
std::size_t completion_condition( // Result of latest async_read_some operation. const boost::system::error_code& error, // Number of bytes transferred so far. std::size_t bytes_transferred );
A return value of 0 indicates that the read operation is complete. A non-zero return value indicates the maximum number of bytes to be read on the next call to the stream's async_read_some function.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes copied into the // buffers. If an error occurred, // this will be the number of // bytes successfully transferred // prior to the error. );
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 boost::asio::io_service::post()
.
Start an asynchronous operation to read a certain amount of data at the specified offset.
template< typename AsyncRandomAccessReadDevice, typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_read_at( AsyncRandomAccessReadDevice & d, uint64_t offset, const MutableBufferSequence & buffers, ReadHandler handler); » more... template< typename AsyncRandomAccessReadDevice, typename MutableBufferSequence, typename CompletionCondition, typename ReadHandler> void-or-deduced async_read_at( AsyncRandomAccessReadDevice & d, uint64_t offset, const MutableBufferSequence & buffers, CompletionCondition completion_condition, ReadHandler handler); » more... template< typename AsyncRandomAccessReadDevice, typename Allocator, typename ReadHandler> void-or-deduced async_read_at( AsyncRandomAccessReadDevice & d, uint64_t offset, basic_streambuf< Allocator > & b, ReadHandler handler); » more... template< typename AsyncRandomAccessReadDevice, typename Allocator, typename CompletionCondition, typename ReadHandler> void-or-deduced async_read_at( AsyncRandomAccessReadDevice & d, uint64_t offset, basic_streambuf< Allocator > & b, CompletionCondition completion_condition, ReadHandler handler); » more...
Header: boost/asio/read_at.hpp
Convenience header: boost/asio.hpp
Start an asynchronous operation to read a certain amount of data at the specified offset.
template< typename AsyncRandomAccessReadDevice, typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_read_at( AsyncRandomAccessReadDevice & d, uint64_t offset, const MutableBufferSequence & buffers, ReadHandler handler);
This function is used to asynchronously read a certain number of bytes of data from a random access device at the specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the device's async_read_some_at function.
The device from which the data is to be read. The type must support the AsyncRandomAccessReadDevice concept.
The offset at which the data will be read.
One or more buffers into which the data will be read. The sum of the buffer sizes indicates the maximum number of bytes to read from the device. 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.
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:
void handler( // Result of operation. const boost::system::error_code& error, // Number of bytes copied into the buffers. If an error // occurred, this will be the number of bytes successfully // transferred prior to the error. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
To read into a single data buffer use the buffer
function as follows:
boost::asio::async_read_at(d, 42, boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on reading into multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
This overload is equivalent to calling:
boost::asio::async_read_at( d, 42, buffers, boost::asio::transfer_all(), handler);
Start an asynchronous operation to read a certain amount of data at the specified offset.
template< typename AsyncRandomAccessReadDevice, typename MutableBufferSequence, typename CompletionCondition, typename ReadHandler> void-or-deduced async_read_at( AsyncRandomAccessReadDevice & d, uint64_t offset, const MutableBufferSequence & buffers, CompletionCondition completion_condition, ReadHandler handler);
This function is used to asynchronously read a certain number of bytes of data from a random access device at the specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
The device from which the data is to be read. The type must support the AsyncRandomAccessReadDevice concept.
The offset at which the data will be read.
One or more buffers into which the data will be read. The sum of the buffer sizes indicates the maximum number of bytes to read from the device. 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.
The function object to be called to determine whether the read operation is complete. The signature of the function object must be:
std::size_t completion_condition( // Result of latest async_read_some_at operation. const boost::system::error_code& error, // Number of bytes transferred so far. std::size_t bytes_transferred );
A return value of 0 indicates that the read operation is complete. A non-zero return value indicates the maximum number of bytes to be read on the next call to the device's async_read_some_at function.
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:
void handler( // Result of operation. const boost::system::error_code& error, // Number of bytes copied into the buffers. If an error // occurred, this will be the number of bytes successfully // transferred prior to the error. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
To read into a single data buffer use the buffer
function as follows:
boost::asio::async_read_at(d, 42, boost::asio::buffer(data, size), boost::asio::transfer_at_least(32), handler);
See the buffer
documentation for information on reading into multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Start an asynchronous operation to read a certain amount of data at the specified offset.
template< typename AsyncRandomAccessReadDevice, typename Allocator, typename ReadHandler> void-or-deduced async_read_at( AsyncRandomAccessReadDevice & d, uint64_t offset, basic_streambuf< Allocator > & b, ReadHandler handler);
This function is used to asynchronously read a certain number of bytes of data from a random access device at the specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the device's async_read_some_at function.
The device from which the data is to be read. The type must support the AsyncRandomAccessReadDevice concept.
The offset at which the data will be read.
A basic_streambuf
object into
which the data will be read. Ownership of the streambuf is retained
by the caller, which must guarantee that it remains valid until the
handler is called.
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:
void handler( // Result of operation. const boost::system::error_code& error, // Number of bytes copied into the buffers. If an error // occurred, this will be the number of bytes successfully // transferred prior to the error. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
This overload is equivalent to calling:
boost::asio::async_read_at( d, 42, b, boost::asio::transfer_all(), handler);
Start an asynchronous operation to read a certain amount of data at the specified offset.
template< typename AsyncRandomAccessReadDevice, typename Allocator, typename CompletionCondition, typename ReadHandler> void-or-deduced async_read_at( AsyncRandomAccessReadDevice & d, uint64_t offset, basic_streambuf< Allocator > & b, CompletionCondition completion_condition, ReadHandler handler);
This function is used to asynchronously read a certain number of bytes of data from a random access device at the specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the device's async_read_some_at function.
The device from which the data is to be read. The type must support the AsyncRandomAccessReadDevice concept.
The offset at which the data will be read.
A basic_streambuf
object into
which the data will be read. Ownership of the streambuf is retained
by the caller, which must guarantee that it remains valid until the
handler is called.
The function object to be called to determine whether the read operation is complete. The signature of the function object must be:
std::size_t completion_condition( // Result of latest async_read_some_at operation. const boost::system::error_code& error, // Number of bytes transferred so far. std::size_t bytes_transferred );
A return value of 0 indicates that the read operation is complete. A non-zero return value indicates the maximum number of bytes to be read on the next call to the device's async_read_some_at function.
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:
void handler( // Result of operation. const boost::system::error_code& error, // Number of bytes copied into the buffers. If an error // occurred, this will be the number of bytes successfully // transferred prior to the error. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
Start an asynchronous operation to read data into a streambuf until it contains a delimiter, matches a regular expression, or a function object indicates a match.
template< typename AsyncReadStream, typename Allocator, typename ReadHandler> void-or-deduced async_read_until( AsyncReadStream & s, boost::asio::basic_streambuf< Allocator > & b, char delim, ReadHandler handler); » more... template< typename AsyncReadStream, typename Allocator, typename ReadHandler> void-or-deduced async_read_until( AsyncReadStream & s, boost::asio::basic_streambuf< Allocator > & b, const std::string & delim, ReadHandler handler); » more... template< typename AsyncReadStream, typename Allocator, typename ReadHandler> void-or-deduced async_read_until( AsyncReadStream & s, boost::asio::basic_streambuf< Allocator > & b, const boost::regex & expr, ReadHandler handler); » more... template< typename AsyncReadStream, typename Allocator, typename MatchCondition, typename ReadHandler> void-or-deduced async_read_until( AsyncReadStream & s, boost::asio::basic_streambuf< Allocator > & b, MatchCondition match_condition, ReadHandler handler, typename enable_if< is_match_condition< MatchCondition >::value >::type * = 0); » more...
Header: boost/asio/read_until.hpp
Convenience header: boost/asio.hpp
Start an asynchronous operation to read data into a streambuf until it contains a specified delimiter.
template< typename AsyncReadStream, typename Allocator, typename ReadHandler> void-or-deduced async_read_until( AsyncReadStream & s, boost::asio::basic_streambuf< Allocator > & b, char delim, ReadHandler handler);
This function is used to asynchronously read data into the specified streambuf until the streambuf's get area contains the specified delimiter. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. If the streambuf's get area already contains the delimiter, this asynchronous operation completes immediately. The program must ensure that the stream performs no other read operations (such as async_read, async_read_until, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.
The stream from which the data is to be read. The type must support the AsyncReadStream concept.
A streambuf object into which the data will be read. Ownership of the streambuf is retained by the caller, which must guarantee that it remains valid until the handler is called.
The delimiter character.
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:
void handler( // Result of operation. const boost::system::error_code& error, // The number of bytes in the streambuf's get // area up to and including the delimiter. // 0 if an error occurred. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
After a successful async_read_until operation, the streambuf may contain additional data beyond the delimiter. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.
To asynchronously read data into a streambuf until a newline is encountered:
boost::asio::streambuf b; ... void handler(const boost::system::error_code& e, std::size_t size) { if (!e) { std::istream is(&b); std::string line; std::getline(is, line); ... } } ... boost::asio::async_read_until(s, b, '\n', handler);
After the async_read_until
operation completes successfully, the buffer b
contains the delimiter:
{ 'a', 'b', ..., 'c', '\n', 'd', 'e', ... }
The call to std::getline
then extracts the data up to
and including the delimiter, so that the string line
contains:
{ 'a', 'b', ..., 'c', '\n' }
The remaining data is left in the buffer b
as follows:
{ 'd', 'e', ... }
This data may be the start of a new line, to be extracted by a subsequent
async_read_until
operation.
Start an asynchronous operation to read data into a streambuf until it contains a specified delimiter.
template< typename AsyncReadStream, typename Allocator, typename ReadHandler> void-or-deduced async_read_until( AsyncReadStream & s, boost::asio::basic_streambuf< Allocator > & b, const std::string & delim, ReadHandler handler);
This function is used to asynchronously read data into the specified streambuf until the streambuf's get area contains the specified delimiter. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. If the streambuf's get area already contains the delimiter, this asynchronous operation completes immediately. The program must ensure that the stream performs no other read operations (such as async_read, async_read_until, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.
The stream from which the data is to be read. The type must support the AsyncReadStream concept.
A streambuf object into which the data will be read. Ownership of the streambuf is retained by the caller, which must guarantee that it remains valid until the handler is called.
The delimiter string.
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:
void handler( // Result of operation. const boost::system::error_code& error, // The number of bytes in the streambuf's get // area up to and including the delimiter. // 0 if an error occurred. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
After a successful async_read_until operation, the streambuf may contain additional data beyond the delimiter. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.
To asynchronously read data into a streambuf until a newline is encountered:
boost::asio::streambuf b; ... void handler(const boost::system::error_code& e, std::size_t size) { if (!e) { std::istream is(&b); std::string line; std::getline(is, line); ... } } ... boost::asio::async_read_until(s, b, "\r\n", handler);
After the async_read_until
operation completes successfully, the buffer b
contains the delimiter:
{ 'a', 'b', ..., 'c', '\r', '\n', 'd', 'e', ... }
The call to std::getline
then extracts the data up to
and including the delimiter, so that the string line
contains:
{ 'a', 'b', ..., 'c', '\r', '\n' }
The remaining data is left in the buffer b
as follows:
{ 'd', 'e', ... }
This data may be the start of a new line, to be extracted by a subsequent
async_read_until
operation.
Start an asynchronous operation to read data into a streambuf until some part of its data matches a regular expression.
template< typename AsyncReadStream, typename Allocator, typename ReadHandler> void-or-deduced async_read_until( AsyncReadStream & s, boost::asio::basic_streambuf< Allocator > & b, const boost::regex & expr, ReadHandler handler);
This function is used to asynchronously read data into the specified streambuf until the streambuf's get area contains some data that matches a regular expression. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. If the streambuf's get area already contains data that matches the regular expression, this asynchronous operation completes immediately. The program must ensure that the stream performs no other read operations (such as async_read, async_read_until, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.
The stream from which the data is to be read. The type must support the AsyncReadStream concept.
A streambuf object into which the data will be read. Ownership of the streambuf is retained by the caller, which must guarantee that it remains valid until the handler is called.
The regular expression.
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:
void handler( // Result of operation. const boost::system::error_code& error, // The number of bytes in the streambuf's get // area up to and including the substring // that matches the regular. expression. // 0 if an error occurred. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
After a successful async_read_until operation, the streambuf may contain additional data beyond that which matched the regular expression. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.
To asynchronously read data into a streambuf until a CR-LF sequence is encountered:
boost::asio::streambuf b; ... void handler(const boost::system::error_code& e, std::size_t size) { if (!e) { std::istream is(&b); std::string line; std::getline(is, line); ... } } ... boost::asio::async_read_until(s, b, boost::regex("\r\n"), handler);
After the async_read_until
operation completes successfully, the buffer b
contains the data which matched the regular expression:
{ 'a', 'b', ..., 'c', '\r', '\n', 'd', 'e', ... }
The call to std::getline
then extracts the data up to
and including the match, so that the string line
contains:
{ 'a', 'b', ..., 'c', '\r', '\n' }
The remaining data is left in the buffer b
as follows:
{ 'd', 'e', ... }
This data may be the start of a new line, to be extracted by a subsequent
async_read_until
operation.
Start an asynchronous operation to read data into a streambuf until a function object indicates a match.
template< typename AsyncReadStream, typename Allocator, typename MatchCondition, typename ReadHandler> void-or-deduced async_read_until( AsyncReadStream & s, boost::asio::basic_streambuf< Allocator > & b, MatchCondition match_condition, ReadHandler handler, typename enable_if< is_match_condition< MatchCondition >::value >::type * = 0);
This function is used to asynchronously read data into the specified streambuf until a user-defined match condition function object, when applied to the data contained in the streambuf, indicates a successful match. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. If the match condition function object already indicates a match, this asynchronous operation completes immediately. The program must ensure that the stream performs no other read operations (such as async_read, async_read_until, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.
The stream from which the data is to be read. The type must support the AsyncReadStream concept.
A streambuf object into which the data will be read.
The function object to be called to determine whether a match exists. The signature of the function object must be:
pair<iterator, bool> match_condition(iterator begin, iterator end);
where iterator
represents
the type:
buffers_iterator<basic_streambuf<Allocator>::const_buffers_type>
The iterator parameters begin
and end
define the
range of bytes to be scanned to determine whether there is a match.
The first
member
of the return value is an iterator marking one-past-the-end of the
bytes that have been consumed by the match function. This iterator
is used to calculate the begin
parameter for any subsequent invocation of the match condition. The
second
member of
the return value is true if a match has been found, false otherwise.
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:
void handler( // Result of operation. const boost::system::error_code& error, // The number of bytes in the streambuf's get // area that have been fully consumed by the // match function. O if an error occurred. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
After a successful async_read_until operation, the streambuf may contain additional data beyond that which matched the function object. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.
The default implementation of the is_match_condition
type trait evaluates to true for function pointers and function objects
with a result_type
typedef.
It must be specialised for other user-defined function objects.
To asynchronously read data into a streambuf until whitespace is encountered:
typedef boost::asio::buffers_iterator< boost::asio::streambuf::const_buffers_type> iterator; std::pair<iterator, bool> match_whitespace(iterator begin, iterator end) { iterator i = begin; while (i != end) if (std::isspace(*i++)) return std::make_pair(i, true); return std::make_pair(i, false); } ... void handler(const boost::system::error_code& e, std::size_t size); ... boost::asio::streambuf b; boost::asio::async_read_until(s, b, match_whitespace, handler);
To asynchronously read data into a streambuf until a matching character is found:
class match_char { public: explicit match_char(char c) : c_(c) {} template <typename Iterator> std::pair<Iterator, bool> operator()( Iterator begin, Iterator end) const { Iterator i = begin; while (i != end) if (c_ == *i++) return std::make_pair(i, true); return std::make_pair(i, false); } private: char c_; }; namespace asio { template <> struct is_match_condition<match_char> : public boost::true_type {}; } // namespace asio ... void handler(const boost::system::error_code& e, std::size_t size); ... boost::asio::streambuf b; boost::asio::async_read_until(s, b, match_char('a'), handler);
An interface for customising the behaviour of an initiating function.
template< typename Handler> class async_result
Name |
Description |
---|---|
The return type of the initiating function. |
Name |
Description |
---|---|
Construct an async result from a given handler. |
|
Obtain the value to be returned from the initiating function. |
This template may be specialised for user-defined handler types.
Header: boost/asio/async_result.hpp
Convenience header: boost/asio.hpp
Construct an async result from a given handler.
async_result( 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.
The return type of the initiating function.
typedef void type;
Header: boost/asio/async_result.hpp
Convenience header: boost/asio.hpp
Start an asynchronous operation to write a certain amount of data to a stream.
template< typename AsyncWriteStream, typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_write( AsyncWriteStream & s, const ConstBufferSequence & buffers, WriteHandler handler); » more... template< typename AsyncWriteStream, typename ConstBufferSequence, typename CompletionCondition, typename WriteHandler> void-or-deduced async_write( AsyncWriteStream & s, const ConstBufferSequence & buffers, CompletionCondition completion_condition, WriteHandler handler); » more... template< typename AsyncWriteStream, typename Allocator, typename WriteHandler> void-or-deduced async_write( AsyncWriteStream & s, basic_streambuf< Allocator > & b, WriteHandler handler); » more... template< typename AsyncWriteStream, typename Allocator, typename CompletionCondition, typename WriteHandler> void-or-deduced async_write( AsyncWriteStream & s, basic_streambuf< Allocator > & b, CompletionCondition completion_condition, WriteHandler handler); » more...
Header: boost/asio/write.hpp
Convenience header: boost/asio.hpp
Start an asynchronous operation to write all of the supplied data to a stream.
template< typename AsyncWriteStream, typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_write( AsyncWriteStream & s, const ConstBufferSequence & buffers, WriteHandler handler);
This function is used to asynchronously write a certain number of bytes of data to a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the stream's async_write_some function, and is known as a composed operation. The program must ensure that the stream performs no other write operations (such as async_write, the stream's async_write_some function, or any other composed operations that perform writes) until this operation completes.
The stream to which the data is to be written. The type must support the AsyncWriteStream concept.
One or more buffers containing the data to be written. 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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes written from the // buffers. If an error occurred, // this will be less than the sum // of the buffer sizes. );
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 boost::asio::io_service::post()
.
To write a single data buffer use the buffer
function as follows:
boost::asio::async_write(s, boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on writing multiple buffers in one go, and
how to use it with arrays, boost::array or std::vector.
Start an asynchronous operation to write a certain amount of data to a stream.
template< typename AsyncWriteStream, typename ConstBufferSequence, typename CompletionCondition, typename WriteHandler> void-or-deduced async_write( AsyncWriteStream & s, const ConstBufferSequence & buffers, CompletionCondition completion_condition, WriteHandler handler);
This function is used to asynchronously write a certain number of bytes of data to a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the stream's async_write_some function, and is known as a composed operation. The program must ensure that the stream performs no other write operations (such as async_write, the stream's async_write_some function, or any other composed operations that perform writes) until this operation completes.
The stream to which the data is to be written. The type must support the AsyncWriteStream concept.
One or more buffers containing the data to be written. 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.
The function object to be called to determine whether the write operation is complete. The signature of the function object must be:
std::size_t completion_condition( // Result of latest async_write_some operation. const boost::system::error_code& error, // Number of bytes transferred so far. std::size_t bytes_transferred );
A return value of 0 indicates that the write operation is complete. A non-zero return value indicates the maximum number of bytes to be written on the next call to the stream's async_write_some function.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes written from the // buffers. If an error occurred, // this will be less than the sum // of the buffer sizes. );
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 boost::asio::io_service::post()
.
To write a single data buffer use the buffer
function as follows:
boost::asio::async_write(s, boost::asio::buffer(data, size), boost::asio::transfer_at_least(32), handler);
See the buffer
documentation for information on writing multiple buffers in one go, and
how to use it with arrays, boost::array or std::vector.
Start an asynchronous operation to write all of the supplied data to a stream.
template< typename AsyncWriteStream, typename Allocator, typename WriteHandler> void-or-deduced async_write( AsyncWriteStream & s, basic_streambuf< Allocator > & b, WriteHandler handler);
This function is used to asynchronously write a certain number of bytes of data to a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
basic_streambuf
has been written.
This operation is implemented in terms of zero or more calls to the stream's async_write_some function, and is known as a composed operation. The program must ensure that the stream performs no other write operations (such as async_write, the stream's async_write_some function, or any other composed operations that perform writes) until this operation completes.
The stream to which the data is to be written. The type must support the AsyncWriteStream concept.
A basic_streambuf
object from
which data will be written. Ownership of the streambuf is retained
by the caller, which must guarantee that it remains valid until the
handler is called.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes written from the // buffers. If an error occurred, // this will be less than the sum // of the buffer sizes. );
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 boost::asio::io_service::post()
.
Start an asynchronous operation to write a certain amount of data to a stream.
template< typename AsyncWriteStream, typename Allocator, typename CompletionCondition, typename WriteHandler> void-or-deduced async_write( AsyncWriteStream & s, basic_streambuf< Allocator > & b, CompletionCondition completion_condition, WriteHandler handler);
This function is used to asynchronously write a certain number of bytes of data to a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
basic_streambuf
has been written.
This operation is implemented in terms of zero or more calls to the stream's async_write_some function, and is known as a composed operation. The program must ensure that the stream performs no other write operations (such as async_write, the stream's async_write_some function, or any other composed operations that perform writes) until this operation completes.
The stream to which the data is to be written. The type must support the AsyncWriteStream concept.
A basic_streambuf
object from
which data will be written. Ownership of the streambuf is retained
by the caller, which must guarantee that it remains valid until the
handler is called.
The function object to be called to determine whether the write operation is complete. The signature of the function object must be:
std::size_t completion_condition( // Result of latest async_write_some operation. const boost::system::error_code& error, // Number of bytes transferred so far. std::size_t bytes_transferred );
A return value of 0 indicates that the write operation is complete. A non-zero return value indicates the maximum number of bytes to be written on the next call to the stream's async_write_some function.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes written from the // buffers. If an error occurred, // this will be less than the sum // of the buffer sizes. );
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 boost::asio::io_service::post()
.
Start an asynchronous operation to write a certain amount of data at the specified offset.
template< typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_write_at( AsyncRandomAccessWriteDevice & d, uint64_t offset, const ConstBufferSequence & buffers, WriteHandler handler); » more... template< typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence, typename CompletionCondition, typename WriteHandler> void-or-deduced async_write_at( AsyncRandomAccessWriteDevice & d, uint64_t offset, const ConstBufferSequence & buffers, CompletionCondition completion_condition, WriteHandler handler); » more... template< typename AsyncRandomAccessWriteDevice, typename Allocator, typename WriteHandler> void-or-deduced async_write_at( AsyncRandomAccessWriteDevice & d, uint64_t offset, basic_streambuf< Allocator > & b, WriteHandler handler); » more... template< typename AsyncRandomAccessWriteDevice, typename Allocator, typename CompletionCondition, typename WriteHandler> void-or-deduced async_write_at( AsyncRandomAccessWriteDevice & d, uint64_t offset, basic_streambuf< Allocator > & b, CompletionCondition completion_condition, WriteHandler handler); » more...
Header: boost/asio/write_at.hpp
Convenience header: boost/asio.hpp
Start an asynchronous operation to write all of the supplied data at the specified offset.
template< typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_write_at( AsyncRandomAccessWriteDevice & d, uint64_t offset, const ConstBufferSequence & buffers, WriteHandler handler);
This function is used to asynchronously write a certain number of bytes of data to a random access device at a specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the device's async_write_some_at function, and is known as a composed operation. The program must ensure that the device performs no overlapping write operations (such as async_write_at, the device's async_write_some_at function, or any other composed operations that perform writes) until this operation completes. Operations are overlapping if the regions defined by their offsets, and the numbers of bytes to write, intersect.
The device to which the data is to be written. The type must support the AsyncRandomAccessWriteDevice concept.
The offset at which the data will be written.
One or more buffers containing the data to be written. 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.
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:
void handler( // Result of operation. const boost::system::error_code& error, // Number of bytes written from the buffers. If an error // occurred, this will be less than the sum of the buffer sizes. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
To write a single data buffer use the buffer
function as follows:
boost::asio::async_write_at(d, 42, boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on writing multiple buffers in one go, and
how to use it with arrays, boost::array or std::vector.
Start an asynchronous operation to write a certain amount of data at the specified offset.
template< typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence, typename CompletionCondition, typename WriteHandler> void-or-deduced async_write_at( AsyncRandomAccessWriteDevice & d, uint64_t offset, const ConstBufferSequence & buffers, CompletionCondition completion_condition, WriteHandler handler);
This function is used to asynchronously write a certain number of bytes of data to a random access device at a specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
This operation is implemented in terms of zero or more calls to the device's async_write_some_at function, and is known as a composed operation. The program must ensure that the device performs no overlapping write operations (such as async_write_at, the device's async_write_some_at function, or any other composed operations that perform writes) until this operation completes. Operations are overlapping if the regions defined by their offsets, and the numbers of bytes to write, intersect.
The device to which the data is to be written. The type must support the AsyncRandomAccessWriteDevice concept.
The offset at which the data will be written.
One or more buffers containing the data to be written. 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.
The function object to be called to determine whether the write operation is complete. The signature of the function object must be:
std::size_t completion_condition( // Result of latest async_write_some_at operation. const boost::system::error_code& error, // Number of bytes transferred so far. std::size_t bytes_transferred );
A return value of 0 indicates that the write operation is complete. A non-zero return value indicates the maximum number of bytes to be written on the next call to the device's async_write_some_at function.
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:
void handler( // Result of operation. const boost::system::error_code& error, // Number of bytes written from the buffers. If an error // occurred, this will be less than the sum of the buffer sizes. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
To write a single data buffer use the buffer
function as follows:
boost::asio::async_write_at(d, 42, boost::asio::buffer(data, size), boost::asio::transfer_at_least(32), handler);
See the buffer
documentation for information on writing multiple buffers in one go, and
how to use it with arrays, boost::array or std::vector.
Start an asynchronous operation to write all of the supplied data at the specified offset.
template< typename AsyncRandomAccessWriteDevice, typename Allocator, typename WriteHandler> void-or-deduced async_write_at( AsyncRandomAccessWriteDevice & d, uint64_t offset, basic_streambuf< Allocator > & b, WriteHandler handler);
This function is used to asynchronously write a certain number of bytes of data to a random access device at a specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
basic_streambuf
has been written.
This operation is implemented in terms of zero or more calls to the device's async_write_some_at function, and is known as a composed operation. The program must ensure that the device performs no overlapping write operations (such as async_write_at, the device's async_write_some_at function, or any other composed operations that perform writes) until this operation completes. Operations are overlapping if the regions defined by their offsets, and the numbers of bytes to write, intersect.
The device to which the data is to be written. The type must support the AsyncRandomAccessWriteDevice concept.
The offset at which the data will be written.
A basic_streambuf
object from
which data will be written. Ownership of the streambuf is retained
by the caller, which must guarantee that it remains valid until the
handler is called.
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:
void handler( // Result of operation. const boost::system::error_code& error, // Number of bytes written from the buffers. If an error // occurred, this will be less than the sum of the buffer sizes. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
Start an asynchronous operation to write a certain amount of data at the specified offset.
template< typename AsyncRandomAccessWriteDevice, typename Allocator, typename CompletionCondition, typename WriteHandler> void-or-deduced async_write_at( AsyncRandomAccessWriteDevice & d, uint64_t offset, basic_streambuf< Allocator > & b, CompletionCondition completion_condition, WriteHandler handler);
This function is used to asynchronously write a certain number of bytes of data to a random access device at a specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
basic_streambuf
has been written.
This operation is implemented in terms of zero or more calls to the device's async_write_some_at function, and is known as a composed operation. The program must ensure that the device performs no overlapping write operations (such as async_write_at, the device's async_write_some_at function, or any other composed operations that perform writes) until this operation completes. Operations are overlapping if the regions defined by their offsets, and the numbers of bytes to write, intersect.
The device to which the data is to be written. The type must support the AsyncRandomAccessWriteDevice concept.
The offset at which the data will be written.
A basic_streambuf
object from
which data will be written. Ownership of the streambuf is retained
by the caller, which must guarantee that it remains valid until the
handler is called.
The function object to be called to determine whether the write operation is complete. The signature of the function object must be:
std::size_t completion_condition( // Result of latest async_write_some_at operation. const boost::system::error_code& error, // Number of bytes transferred so far. std::size_t bytes_transferred );
A return value of 0 indicates that the write operation is complete. A non-zero return value indicates the maximum number of bytes to be written on the next call to the device's async_write_some_at function.
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:
void handler( // Result of operation. const boost::system::error_code& error, // Number of bytes written from the buffers. If an error // occurred, this will be less than the sum of the buffer sizes. std::size_t bytes_transferred );
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 boost::asio::io_service::post()
.
Provides datagram-oriented socket functionality.
template< typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>> class basic_datagram_socket : public basic_socket< Protocol, DatagramSocketService >
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Start an asynchronous receive on a connected socket. |
|
Start an asynchronous receive. |
|
Start an asynchronous send on a connected socket. |
|
Start an asynchronous send. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_datagram_socket without opening it. Construct and open a basic_datagram_socket. Construct a basic_datagram_socket, opening it and binding it to the given local endpoint. Construct a basic_datagram_socket on an existing native socket. Move-construct a basic_datagram_socket from another. Move-construct a basic_datagram_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_datagram_socket from another. Move-assign a basic_datagram_socket from a socket of another protocol type. |
|
Receive some data on a connected socket. |
|
Receive a datagram with the endpoint of the sender. |
|
Get the remote endpoint of the socket. |
|
Send some data on a connected socket. |
|
Send a datagram to the specified endpoint. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_datagram_socket
class template
provides asynchronous and blocking datagram-oriented socket functionality.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket); » more... boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket);
Inherited from basic_socket.
Assign an existing native socket to the socket.
boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec);
Inherited from basic_socket.
Start an asynchronous connect.
template< typename ConnectHandler> void-or-deduced async_connect( const endpoint_type & peer_endpoint, ConnectHandler handler);
This function is used to asynchronously connect a socket to the specified remote endpoint. The function call always returns immediately.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected. Copies will be made of the endpoint object as required.
The handler to be called when the connection operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error // Result of operation );
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 boost::asio::io_service::post()
.
void connect_handler(const boost::system::error_code& error) { if (!error) { // Connect succeeded. } } ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.async_connect(endpoint, connect_handler);
Start an asynchronous receive on a connected socket.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, ReadHandler handler); » more... template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, ReadHandler handler); » more...
Start an asynchronous receive on a connected socket.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, ReadHandler handler);
This function is used to asynchronously receive data from the datagram socket. The function call always returns immediately.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
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.
To receive into a single data buffer use the buffer
function as follows:
socket.async_receive(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Start an asynchronous receive on a connected socket.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, ReadHandler handler);
This function is used to asynchronously receive data from the datagram socket. The function call always returns immediately.
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.
Flags specifying how the receive call is to be made.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
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.
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, ReadHandler handler); » more... template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags, ReadHandler handler); » more...
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, ReadHandler handler);
This function is used to asynchronously receive a datagram. The function call always returns immediately.
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.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
To receive into a single data buffer use the buffer
function as follows:
socket.async_receive_from( boost::asio::buffer(data, size), sender_endpoint, handler);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags, ReadHandler handler);
This function is used to asynchronously receive a datagram. The function call always returns immediately.
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.
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.
Flags specifying how the receive call is to be made.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
Start an asynchronous send on a connected socket.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, WriteHandler handler); » more... template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, socket_base::message_flags flags, WriteHandler handler); » more...
Start an asynchronous send on a connected socket.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, WriteHandler handler);
This function is used to asynchronously send data on the datagram socket. The function call always returns immediately.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
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.
To send a single data buffer use the buffer
function as follows:
socket.async_send(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Start an asynchronous send on a connected socket.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, socket_base::message_flags flags, WriteHandler handler);
This function is used to asynchronously send data on the datagram socket. The function call always returns immediately.
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.
Flags specifying how the send call is to be made.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
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> void-or-deduced async_send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, WriteHandler handler); » more... template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags, WriteHandler handler); » more...
Start an asynchronous send.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, WriteHandler handler);
This function is used to asynchronously send a datagram to the specified remote endpoint. The function call always returns immediately.
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.
The remote endpoint to which the data will be sent. Copies will be made of the endpoint as required.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
To send a single data buffer use the buffer
function as follows:
boost::asio::ip::udp::endpoint destination( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.async_send_to( boost::asio::buffer(data, size), destination, handler);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Start an asynchronous send.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags, WriteHandler handler);
This function is used to asynchronously send a datagram to the specified remote endpoint. The function call always returns immediately.
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.
Flags specifying how the send call is to be made.
The remote endpoint to which the data will be sent. Copies will be made of the endpoint as required.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const; » more... bool at_mark( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
A bool indicating whether the socket is at the out-of-band data mark.
Thrown on failure.
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark( boost::system::error_code & ec) const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
Set to indicate what error occurred, if any.
A bool indicating whether the socket is at the out-of-band data mark.
Determine the number of bytes available for reading.
std::size_t available() const; » more... std::size_t available( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available() const;
This function is used to determine the number of bytes that may be read without blocking.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Thrown on failure.
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available( boost::system::error_code & ec) const;
This function is used to determine the number of bytes that may be read without blocking.
Set to indicate what error occurred, if any.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Construct a basic_datagram_socket
without
opening it.
explicit basic_datagram_socket( boost::asio::io_service & io_service); » more...
Construct and open a basic_datagram_socket
.
basic_datagram_socket( boost::asio::io_service & io_service, const protocol_type & protocol); » more...
Construct a basic_datagram_socket
, opening
it and binding it to the given local endpoint.
basic_datagram_socket( boost::asio::io_service & io_service, const endpoint_type & endpoint); » more...
Construct a basic_datagram_socket
on an existing
native socket.
basic_datagram_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket); » more...
Move-construct a basic_datagram_socket
from another.
basic_datagram_socket( basic_datagram_socket && other); » more...
Move-construct a basic_datagram_socket
from a socket
of another protocol type.
template< typename Protocol1, typename DatagramSocketService1> basic_datagram_socket( basic_datagram_socket< Protocol1, DatagramSocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0); » more...
Construct a basic_datagram_socket
without
opening it.
basic_datagram_socket( boost::asio::io_service & io_service);
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.
The io_service
object that
the datagram socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
Construct and open a basic_datagram_socket
.
basic_datagram_socket( boost::asio::io_service & io_service, const protocol_type & protocol);
This constructor creates and opens a datagram socket.
The io_service
object that
the datagram socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
An object specifying protocol parameters to be used.
Thrown on failure.
Construct a basic_datagram_socket
, opening
it and binding it to the given local endpoint.
basic_datagram_socket( boost::asio::io_service & io_service, const endpoint_type & 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.
The io_service
object that
the datagram socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
An endpoint on the local machine to which the datagram socket will be bound.
Thrown on failure.
Construct a basic_datagram_socket
on an
existing native socket.
basic_datagram_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket);
This constructor creates a datagram socket object to hold an existing native socket.
The io_service
object that
the datagram socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
An object specifying protocol parameters to be used.
The new underlying socket implementation.
Thrown on failure.
Move-construct a basic_datagram_socket
from another.
basic_datagram_socket( basic_datagram_socket && other);
This constructor moves a datagram socket from one object to another.
The other basic_datagram_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_datagram_socket(io_service&) constructor
.
Move-construct a basic_datagram_socket
from a
socket of another protocol type.
template< typename Protocol1, typename DatagramSocketService1> basic_datagram_socket( basic_datagram_socket< Protocol1, DatagramSocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0);
This constructor moves a datagram socket from one object to another.
The other basic_datagram_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_datagram_socket(io_service&) constructor
.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint); » more... boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345));
Inherited from basic_socket.
Bind the socket to the given local endpoint.
boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); boost::system::error_code ec; socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345), ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to permit sending of broadcast messages.
typedef implementation_defined broadcast;
Implements the SOL_SOCKET/SO_BROADCAST socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
IO control command to get the amount of data that can be read without blocking.
typedef implementation_defined bytes_readable;
Implements the FIONREAD IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::bytes_readable command(true); socket.io_control(command); std::size_t bytes_readable = command.get();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Cancel all asynchronous operations associated with the socket.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
void cancel();
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Close the socket.
void close();
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Thrown on failure. Note that, even if the function indicates an error, the underlying descriptor is closed.
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Inherited from basic_socket.
Close the socket.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any. Note that, even if the function indicates an error, the underlying descriptor is closed.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.close(ec); if (ec) { // An error occurred. }
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint); » more... boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.connect(endpoint);
Inherited from basic_socket.
Connect the socket to the specified endpoint.
boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); boost::system::error_code ec; socket.connect(endpoint, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to enable socket-level debugging.
typedef implementation_defined debug;
Implements the SOL_SOCKET/SO_DEBUG socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to prevent routing, use local interfaces only.
typedef implementation_defined do_not_route;
Implements the SOL_SOCKET/SO_DONTROUTE socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to report aborted connections on accept.
typedef implementation_defined enable_connection_aborted;
Implements a custom socket option that determines whether or not an accept
operation is permitted to fail with boost::asio::error::connection_aborted
.
By default the option is false.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get an option from the socket.
void get_option( GettableSocketOption & option) const; » more... boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Thrown on failure.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; socket.get_option(option); bool is_set = option.value();
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Set to indicate what error occurred, if any.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; boost::system::error_code ec; socket.get_option(option, ec); if (ec) { // An error occurred. } bool is_set = option.value();
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the socket.
void io_control( IoControlCommand & command); » more... boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> void io_control( IoControlCommand & command);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Thrown on failure.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; socket.io_control(command); std::size_t bytes_readable = command.get();
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Set to indicate what error occurred, if any.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; boost::system::error_code ec; socket.io_control(command, ec); if (ec) { // An error occurred. } std::size_t bytes_readable = command.get();
Inherited from socket_base.
Socket option to send keep-alives.
typedef implementation_defined keep_alive;
Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to specify whether the socket lingers on close if unsent data is present.
typedef implementation_defined linger;
Implements the SOL_SOCKET/SO_LINGER socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option(true, 30); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option; socket.get_option(option); bool is_set = option.enabled(); unsigned short timeout = option.timeout();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Get the local endpoint of the socket.
endpoint_type local_endpoint() const; » more... endpoint_type local_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint() const;
This function is used to obtain the locally bound endpoint of the socket.
An object that represents the local endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint();
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the locally bound endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the local endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint(ec); if (ec) { // An error occurred. }
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Inherited from basic_socket.
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer();
This function returns a reference to the lowest layer in a stack of layers.
Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
This function returns a const reference to the lowest layer in a stack
of layers. Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A const reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
A basic_socket
is always the lowest
layer.
typedef basic_socket< Protocol, DatagramSocketService > lowest_layer_type;
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_socket without opening it. Construct and open a basic_socket. Construct a basic_socket, opening it and binding it to the given local endpoint. Construct a basic_socket on an existing native socket. Move-construct a basic_socket from another. Move-construct a basic_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_socket from another. Move-assign a basic_socket from a socket of another protocol type. |
|
Get the remote endpoint of the socket. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
|
Protected destructor to prevent deletion through this type. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_socket
class template provides functionality that is common to both stream-oriented
and datagram-oriented sockets.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
The maximum length of the queue of pending incoming connections.
static const int max_connections = implementation_defined;
Inherited from socket_base.
Specify that the data should not be subject to routing.
static const int message_do_not_route = implementation_defined;
Inherited from socket_base.
Specifies that the data marks the end of a record.
static const int message_end_of_record = implementation_defined;
Inherited from socket_base.
Bitmask type for flags that can be passed to send and receive operations.
typedef int message_flags;
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
static const int message_out_of_band = implementation_defined;
Inherited from socket_base.
Peek at incoming data without removing it from the input queue.
static const int message_peek = implementation_defined;
Inherited from basic_socket.
(Deprecated: Use native_handle()
.) Get the native socket representation.
native_type native();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
Inherited from basic_socket.
Get the native socket representation.
native_handle_type native_handle();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
The native representation of a socket.
typedef DatagramSocketService::native_handle_type native_handle_type;
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const; » more...
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode); » more... boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const;
This function is used to retrieve the non-blocking mode of the underlying native socket. This mode has no effect on the behaviour of the socket object's synchronous operations.
true
if the underlying socket
is in non-blocking mode and direct system calls may fail with boost::asio::error::would_block
(or the equivalent system
error).
The current non-blocking mode is cached by the socket object. Consequently, the return value may be incorrect if the non-blocking mode was set directly on the native socket.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Thrown on failure. If the mode
is false
, but the
current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Set to indicate what error occurred, if any. If the mode
is false
,
but the current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
(Deprecated: Use native_handle_type.) The native representation of a socket.
typedef DatagramSocketService::native_handle_type native_type;
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the socket.
bool non_blocking() const; » more...
Sets the non-blocking mode of the socket.
void non_blocking( bool mode); » more... boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the socket.
bool non_blocking() const;
true
if the socket's synchronous
operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately. If
false
, synchronous operations
will block until complete.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
void non_blocking( bool mode);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Thrown on failure.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Set to indicate what error occurred, if any.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from socket_base.
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket.
typedef implementation_defined non_blocking_io;
Implements the FIONBIO IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::non_blocking_io command(true); socket.io_control(command);
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type()); » more... boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type());
This function opens the socket so that it will use the specified protocol.
An object specifying protocol parameters to be used.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4());
Inherited from basic_socket.
Open the socket using the specified protocol.
boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec);
This function opens the socket so that it will use the specified protocol.
An object specifying which protocol is to be used.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::system::error_code ec; socket.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
Move-assign a basic_datagram_socket
from another.
basic_datagram_socket & operator=( basic_datagram_socket && other); » more...
Move-assign a basic_datagram_socket
from a socket
of another protocol type.
template< typename Protocol1, typename DatagramSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_datagram_socket >::type & operator=( basic_datagram_socket< Protocol1, DatagramSocketService1 > && other); » more...
Move-assign a basic_datagram_socket
from another.
basic_datagram_socket & operator=( basic_datagram_socket && other);
This assignment operator moves a datagram socket from one object to another.
The other basic_datagram_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_datagram_socket(io_service&) constructor
.
Move-assign a basic_datagram_socket
from a
socket of another protocol type.
template< typename Protocol1, typename DatagramSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_datagram_socket >::type & operator=( basic_datagram_socket< Protocol1, DatagramSocketService1 > && other);
This assignment operator moves a datagram socket from one object to another.
The other basic_datagram_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_datagram_socket(io_service&) constructor
.
typedef Protocol protocol_type;
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers); » more... template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags); » more... template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers);
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.
One or more buffers into which the data will be received.
The number of bytes received.
Thrown on failure.
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected datagram socket.
To receive into a single data buffer use the buffer
function as follows:
socket.receive(boost::asio::buffer(data, size));
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags);
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.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
The number of bytes received.
Thrown on failure.
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected datagram socket.
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec);
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.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
Set to indicate what error occurred, if any.
The number of bytes received.
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected datagram socket.
Inherited from socket_base.
Socket option for the receive buffer size of a socket.
typedef implementation_defined receive_buffer_size;
Implements the SOL_SOCKET/SO_RCVBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Receive a datagram with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint); » more... template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags); » more... template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Receive a datagram with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint);
This function is used to receive a datagram. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
An endpoint object that receives the endpoint of the remote sender of the datagram.
The number of bytes received.
Thrown on failure.
To receive into a single data buffer use the buffer
function as follows:
boost::asio::ip::udp::endpoint sender_endpoint; socket.receive_from( boost::asio::buffer(data, size), sender_endpoint);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Receive a datagram with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags);
This function is used to receive a datagram. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
An endpoint object that receives the endpoint of the remote sender of the datagram.
Flags specifying how the receive call is to be made.
The number of bytes received.
Thrown on failure.
Receive a datagram with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags, boost::system::error_code & ec);
This function is used to receive a datagram. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
An endpoint object that receives the endpoint of the remote sender of the datagram.
Flags specifying how the receive call is to be made.
Set to indicate what error occurred, if any.
The number of bytes received.
Inherited from socket_base.
Socket option for the receive low watermark.
typedef implementation_defined receive_low_watermark;
Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const; » more... endpoint_type remote_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const;
This function is used to obtain the remote endpoint of the socket.
An object that represents the remote endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the remote endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the remote endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to allow the socket to be bound to an address that is already in use.
typedef implementation_defined reuse_address;
Implements the SOL_SOCKET/SO_REUSEADDR socket option.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers); » more... template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags); » more... template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers);
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.
One ore more data buffers to be sent on the socket.
The number of bytes sent.
Thrown on failure.
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected datagram socket.
To send a single data buffer use the buffer
function as follows:
socket.send(boost::asio::buffer(data, size));
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags);
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.
One ore more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
The number of bytes sent.
Thrown on failure.
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected datagram socket.
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec);
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.
One or more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
Set to indicate what error occurred, if any.
The number of bytes sent.
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected datagram socket.
Inherited from socket_base.
Socket option for the send buffer size of a socket.
typedef implementation_defined send_buffer_size;
Implements the SOL_SOCKET/SO_SNDBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send low watermark.
typedef implementation_defined send_low_watermark;
Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
Send a datagram to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination); » more... template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags); » more... template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Send a datagram to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination);
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.
One or more data buffers to be sent to the remote endpoint.
The remote endpoint to which the data will be sent.
The number of bytes sent.
Thrown on failure.
To send a single data buffer use the buffer
function as follows:
boost::asio::ip::udp::endpoint destination( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.send_to(boost::asio::buffer(data, size), destination);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Send a datagram to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags);
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.
One or more data buffers to be sent to the remote endpoint.
The remote endpoint to which the data will be sent.
Flags specifying how the send call is to be made.
The number of bytes sent.
Thrown on failure.
Send a datagram to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags, boost::system::error_code & ec);
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.
One or more data buffers to be sent to the remote endpoint.
The remote endpoint to which the data will be sent.
Flags specifying how the send call is to be made.
Set to indicate what error occurred, if any.
The number of bytes sent.
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef DatagramSocketService service_type;
Header: boost/asio/basic_datagram_socket.hpp
Convenience header: boost/asio.hpp
void set_option( const SettableSocketOption & option); » more... boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Thrown on failure.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); socket.set_option(option);
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Set to indicate what error occurred, if any.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); boost::system::error_code ec; socket.set_option(option, ec); if (ec) { // An error occurred. }
Disable sends or receives on the socket.
void shutdown( shutdown_type what); » more... boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Disable sends or receives on the socket.
void shutdown( shutdown_type what);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Thrown on failure.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send);
Inherited from basic_socket.
Disable sends or receives on the socket.
boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Set to indicate what error occurred, if any.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Different ways a socket may be shutdown.
enum shutdown_type
Shutdown the receive side of the socket.
Shutdown the send side of the socket.
Shutdown both send and receive on the socket.
Provides waitable timer functionality.
template< typename Time, typename TimeTraits = boost::asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>> class basic_deadline_timer : public basic_io_object< TimerService >
Name |
Description |
---|---|
The duration type. |
|
The underlying implementation type of I/O object. |
|
The type of the service that will be used to provide I/O operations. |
|
The time type. |
|
The time traits type. |
Name |
Description |
---|---|
Start an asynchronous wait on the timer. |
|
Constructor. Constructor to set a particular expiry time as an absolute time. Constructor to set a particular expiry time relative to now. |
|
Cancel any asynchronous operations that are waiting on the timer. |
|
Cancels one asynchronous operation that is waiting on the timer. |
|
Get the timer's expiry time as an absolute time. Set the timer's expiry time as an absolute time. |
|
Get the timer's expiry time relative to now. Set the timer's expiry time relative to now. |
|
Get the io_service associated with the object. |
|
Perform a blocking wait on the timer. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
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 deadline_timer
typedef.
Distinct objects: Safe.
Shared objects: Unsafe.
Performing a blocking wait:
// Construct a timer without setting an expiry time. boost::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();
Performing an asynchronous wait:
void handler(const boost::system::error_code& error) { if (!error) { // Timer expired. } } ... // Construct a timer with an absolute expiry time. boost::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);
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:
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 boost::system::error_code& e) { if (e != boost::asio::error::operation_aborted) { // Timer was not cancelled, take necessary action. } }
boost::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.
boost::asio::error::operation_aborted
.
Header: boost/asio/basic_deadline_timer.hpp
Convenience header: boost/asio.hpp
Start an asynchronous wait on the timer.
template< typename WaitHandler> void-or-deduced async_wait( WaitHandler handler);
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:
boost::asio::error::operation_aborted
.
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:
void handler( const boost::system::error_code& error // Result of operation. );
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 boost::asio::io_service::post()
.
explicit basic_deadline_timer( boost::asio::io_service & io_service); » more...
Constructor to set a particular expiry time as an absolute time.
basic_deadline_timer( boost::asio::io_service & io_service, const time_type & expiry_time); » more...
Constructor to set a particular expiry time relative to now.
basic_deadline_timer( boost::asio::io_service & io_service, const duration_type & expiry_time); » more...
Constructor.
basic_deadline_timer( boost::asio::io_service & io_service);
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.
The io_service
object that
the timer will use to dispatch handlers for any asynchronous operations
performed on the timer.
Constructor to set a particular expiry time as an absolute time.
basic_deadline_timer( boost::asio::io_service & io_service, const time_type & expiry_time);
This constructor creates a timer and sets the expiry time.
The io_service
object that
the timer will use to dispatch handlers for any asynchronous operations
performed on the timer.
The expiry time to be used for the timer, expressed as an absolute time.
Constructor to set a particular expiry time relative to now.
basic_deadline_timer( boost::asio::io_service & io_service, const duration_type & expiry_time);
This constructor creates a timer and sets the expiry time.
The io_service
object that
the timer will use to dispatch handlers for any asynchronous operations
performed on the timer.
The expiry time to be used for the timer, relative to now.
Cancel any asynchronous operations that are waiting on the timer.
std::size_t cancel(); » more... std::size_t cancel( boost::system::error_code & ec); » more...
Cancel any asynchronous operations that are waiting on the timer.
std::size_t cancel();
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 boost::asio::error::operation_aborted
error code.
Cancelling the timer does not change the expiry time.
The number of asynchronous operations that were cancelled.
Thrown on failure.
If the timer has already expired when cancel()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Cancel any asynchronous operations that are waiting on the timer.
std::size_t cancel( boost::system::error_code & ec);
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 boost::asio::error::operation_aborted
error code.
Cancelling the timer does not change the expiry time.
Set to indicate what error occurred, if any.
The number of asynchronous operations that were cancelled.
If the timer has already expired when cancel()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Cancels one asynchronous operation that is waiting on the timer.
std::size_t cancel_one(); » more... std::size_t cancel_one( boost::system::error_code & ec); » more...
Cancels one asynchronous operation that is waiting on the timer.
std::size_t cancel_one();
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 boost::asio::error::operation_aborted
error code.
Cancelling the timer does not change the expiry time.
The number of asynchronous operations that were cancelled. That is, either 0 or 1.
Thrown on failure.
If the timer has already expired when cancel_one()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Cancels one asynchronous operation that is waiting on the timer.
std::size_t cancel_one( boost::system::error_code & ec);
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 boost::asio::error::operation_aborted
error code.
Cancelling the timer does not change the expiry time.
Set to indicate what error occurred, if any.
The number of asynchronous operations that were cancelled. That is, either 0 or 1.
If the timer has already expired when cancel_one()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
typedef traits_type::duration_type duration_type;
Header: boost/asio/basic_deadline_timer.hpp
Convenience header: boost/asio.hpp
Get the timer's expiry time as an absolute time.
time_type expires_at() const; » more...
Set the timer's expiry time as an absolute time.
std::size_t expires_at( const time_type & expiry_time); » more... std::size_t expires_at( const time_type & expiry_time, boost::system::error_code & ec); » more...
Get the timer's expiry time as an absolute time.
time_type expires_at() const;
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.
Set the timer's expiry time as an absolute time.
std::size_t expires_at( const time_type & expiry_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 boost::asio::error::operation_aborted
error code.
The expiry time to be used for the timer.
The number of asynchronous operations that were cancelled.
Thrown on failure.
If the timer has already expired when expires_at()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Set the timer's expiry time as an absolute time.
std::size_t expires_at( const time_type & expiry_time, boost::system::error_code & ec);
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 boost::asio::error::operation_aborted
error code.
The expiry time to be used for the timer.
Set to indicate what error occurred, if any.
The number of asynchronous operations that were cancelled.
If the timer has already expired when expires_at()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Get the timer's expiry time relative to now.
duration_type expires_from_now() const; » more...
Set the timer's expiry time relative to now.
std::size_t expires_from_now( const duration_type & expiry_time); » more... std::size_t expires_from_now( const duration_type & expiry_time, boost::system::error_code & ec); » more...
Get the timer's expiry time relative to now.
duration_type expires_from_now() const;
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.
Set the timer's expiry time relative to now.
std::size_t expires_from_now( const duration_type & expiry_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 boost::asio::error::operation_aborted
error code.
The expiry time to be used for the timer.
The number of asynchronous operations that were cancelled.
Thrown on failure.
If the timer has already expired when expires_from_now()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Set the timer's expiry time relative to now.
std::size_t expires_from_now( const duration_type & expiry_time, boost::system::error_code & ec);
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 boost::asio::error::operation_aborted
error code.
The expiry time to be used for the timer.
Set to indicate what error occurred, if any.
The number of asynchronous operations that were cancelled.
If the timer has already expired when expires_from_now()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_deadline_timer.hpp
Convenience header: boost/asio.hpp
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef TimerService service_type;
Header: boost/asio/basic_deadline_timer.hpp
Convenience header: boost/asio.hpp
typedef traits_type::time_type time_type;
Header: boost/asio/basic_deadline_timer.hpp
Convenience header: boost/asio.hpp
typedef TimeTraits traits_type;
Header: boost/asio/basic_deadline_timer.hpp
Convenience header: boost/asio.hpp
Perform a blocking wait on the timer.
void wait(); » more... void wait( boost::system::error_code & ec); » more...
Perform a blocking wait on the timer.
void wait();
This function is used to wait for the timer to expire. This function blocks and does not return until the timer has expired.
Thrown on failure.
Perform a blocking wait on the timer.
void wait( boost::system::error_code & ec);
This function is used to wait for the timer to expire. This function blocks and does not return until the timer has expired.
Set to indicate what error occurred, if any.
Base class for all I/O objects.
template< typename IoObjectService> class basic_io_object
Name |
Description |
---|---|
The underlying implementation type of I/O object. |
|
The type of the service that will be used to provide I/O operations. |
Name |
Description |
---|---|
Get the io_service associated with the object. |
Name |
Description |
---|---|
Construct a basic_io_object. Move-construct a basic_io_object. |
|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
|
Move-assign a basic_io_object. |
|
Protected destructor to prevent deletion through this type. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
All I/O objects are non-copyable. However, when using C++0x, certain I/O objects do support move construction and move assignment.
Header: boost/asio/basic_io_object.hpp
Convenience header: boost/asio.hpp
Construct a basic_io_object
.
explicit basic_io_object( boost::asio::io_service & io_service); » more...
Move-construct a basic_io_object
.
basic_io_object( basic_io_object && other); » more...
Construct a basic_io_object
.
basic_io_object( boost::asio::io_service & io_service);
Performs:
get_service().construct(get_implementation());
Move-construct a basic_io_object
.
basic_io_object( basic_io_object && other);
Performs:
get_service().move_construct( get_implementation(), other.get_implementation());
Available only for services that support movability,
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Get the service associated with the I/O object.
service_type & get_service();
Get the service associated with the I/O object.
const service_type & get_service() const;
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_io_object.hpp
Convenience header: boost/asio.hpp
Move-assign a basic_io_object
.
basic_io_object & operator=( basic_io_object && other);
Performs:
get_service().move_assign(get_implementation(), other.get_service(), other.get_implementation());
Available only for services that support movability,
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
The type of the service that will be used to provide I/O operations.
typedef IoObjectService service_type;
Header: boost/asio/basic_io_object.hpp
Convenience header: boost/asio.hpp
Provides raw-oriented socket functionality.
template< typename Protocol, typename RawSocketService = raw_socket_service<Protocol>> class basic_raw_socket : public basic_socket< Protocol, RawSocketService >
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Start an asynchronous receive on a connected socket. |
|
Start an asynchronous receive. |
|
Start an asynchronous send on a connected socket. |
|
Start an asynchronous send. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_raw_socket without opening it. Construct and open a basic_raw_socket. Construct a basic_raw_socket, opening it and binding it to the given local endpoint. Construct a basic_raw_socket on an existing native socket. Move-construct a basic_raw_socket from another. Move-construct a basic_raw_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_raw_socket from another. Move-assign a basic_raw_socket from a socket of another protocol type. |
|
Receive some data on a connected socket. |
|
Receive raw data with the endpoint of the sender. |
|
Get the remote endpoint of the socket. |
|
Send some data on a connected socket. |
|
Send raw data to the specified endpoint. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_raw_socket
class template provides asynchronous and blocking raw-oriented socket functionality.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket); » more... boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket);
Inherited from basic_socket.
Assign an existing native socket to the socket.
boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec);
Inherited from basic_socket.
Start an asynchronous connect.
template< typename ConnectHandler> void-or-deduced async_connect( const endpoint_type & peer_endpoint, ConnectHandler handler);
This function is used to asynchronously connect a socket to the specified remote endpoint. The function call always returns immediately.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected. Copies will be made of the endpoint object as required.
The handler to be called when the connection operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error // Result of operation );
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 boost::asio::io_service::post()
.
void connect_handler(const boost::system::error_code& error) { if (!error) { // Connect succeeded. } } ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.async_connect(endpoint, connect_handler);
Start an asynchronous receive on a connected socket.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, ReadHandler handler); » more... template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, ReadHandler handler); » more...
Start an asynchronous receive on a connected socket.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, ReadHandler handler);
This function is used to asynchronously receive data from the raw socket. The function call always returns immediately.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
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.
To receive into a single data buffer use the buffer
function as follows:
socket.async_receive(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Start an asynchronous receive on a connected socket.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, ReadHandler handler);
This function is used to asynchronously receive data from the raw socket. The function call always returns immediately.
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.
Flags specifying how the receive call is to be made.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
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.
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, ReadHandler handler); » more... template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags, ReadHandler handler); » more...
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, ReadHandler handler);
This function is used to asynchronously receive raw data. The function call always returns immediately.
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.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
To receive into a single data buffer use the buffer
function as follows:
socket.async_receive_from( boost::asio::buffer(data, size), 0, sender_endpoint, handler);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags, ReadHandler handler);
This function is used to asynchronously receive raw data. The function call always returns immediately.
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.
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.
Flags specifying how the receive call is to be made.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
Start an asynchronous send on a connected socket.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, WriteHandler handler); » more... template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, socket_base::message_flags flags, WriteHandler handler); » more...
Start an asynchronous send on a connected socket.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, WriteHandler handler);
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.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
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.
To send a single data buffer use the buffer
function as follows:
socket.async_send(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Start an asynchronous send on a connected socket.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, socket_base::message_flags flags, WriteHandler handler);
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.
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.
Flags specifying how the send call is to be made.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
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> void-or-deduced async_send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, WriteHandler handler); » more... template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags, WriteHandler handler); » more...
Start an asynchronous send.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, WriteHandler handler);
This function is used to asynchronously send raw data to the specified remote endpoint. The function call always returns immediately.
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.
The remote endpoint to which the data will be sent. Copies will be made of the endpoint as required.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
To send a single data buffer use the buffer
function as follows:
boost::asio::ip::udp::endpoint destination( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.async_send_to( boost::asio::buffer(data, size), destination, handler);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Start an asynchronous send.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags, WriteHandler handler);
This function is used to asynchronously send raw data to the specified remote endpoint. The function call always returns immediately.
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.
Flags specifying how the send call is to be made.
The remote endpoint to which the data will be sent. Copies will be made of the endpoint as required.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const; » more... bool at_mark( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
A bool indicating whether the socket is at the out-of-band data mark.
Thrown on failure.
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark( boost::system::error_code & ec) const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
Set to indicate what error occurred, if any.
A bool indicating whether the socket is at the out-of-band data mark.
Determine the number of bytes available for reading.
std::size_t available() const; » more... std::size_t available( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available() const;
This function is used to determine the number of bytes that may be read without blocking.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Thrown on failure.
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available( boost::system::error_code & ec) const;
This function is used to determine the number of bytes that may be read without blocking.
Set to indicate what error occurred, if any.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Construct a basic_raw_socket
without opening
it.
explicit basic_raw_socket( boost::asio::io_service & io_service); » more...
Construct and open a basic_raw_socket
.
basic_raw_socket( boost::asio::io_service & io_service, const protocol_type & protocol); » more...
Construct a basic_raw_socket
, opening it and
binding it to the given local endpoint.
basic_raw_socket( boost::asio::io_service & io_service, const endpoint_type & endpoint); » more...
Construct a basic_raw_socket
on an existing
native socket.
basic_raw_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket); » more...
Move-construct a basic_raw_socket
from another.
basic_raw_socket( basic_raw_socket && other); » more...
Move-construct a basic_raw_socket
from a socket
of another protocol type.
template< typename Protocol1, typename RawSocketService1> basic_raw_socket( basic_raw_socket< Protocol1, RawSocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0); » more...
Construct a basic_raw_socket
without opening
it.
basic_raw_socket( boost::asio::io_service & io_service);
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.
The io_service
object that
the raw socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
Construct and open a basic_raw_socket
.
basic_raw_socket( boost::asio::io_service & io_service, const protocol_type & protocol);
This constructor creates and opens a raw socket.
The io_service
object that
the raw socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
An object specifying protocol parameters to be used.
Thrown on failure.
Construct a basic_raw_socket
, opening it
and binding it to the given local endpoint.
basic_raw_socket( boost::asio::io_service & io_service, const endpoint_type & 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.
The io_service
object that
the raw socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
An endpoint on the local machine to which the raw socket will be bound.
Thrown on failure.
Construct a basic_raw_socket
on an existing
native socket.
basic_raw_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket);
This constructor creates a raw socket object to hold an existing native socket.
The io_service
object that
the raw socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
An object specifying protocol parameters to be used.
The new underlying socket implementation.
Thrown on failure.
Move-construct a basic_raw_socket
from another.
basic_raw_socket( basic_raw_socket && other);
This constructor moves a raw socket from one object to another.
The other basic_raw_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_raw_socket(io_service&) constructor
.
Move-construct a basic_raw_socket
from a socket
of another protocol type.
template< typename Protocol1, typename RawSocketService1> basic_raw_socket( basic_raw_socket< Protocol1, RawSocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0);
This constructor moves a raw socket from one object to another.
The other basic_raw_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_raw_socket(io_service&) constructor
.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint); » more... boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345));
Inherited from basic_socket.
Bind the socket to the given local endpoint.
boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); boost::system::error_code ec; socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345), ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to permit sending of broadcast messages.
typedef implementation_defined broadcast;
Implements the SOL_SOCKET/SO_BROADCAST socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
IO control command to get the amount of data that can be read without blocking.
typedef implementation_defined bytes_readable;
Implements the FIONREAD IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::bytes_readable command(true); socket.io_control(command); std::size_t bytes_readable = command.get();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Cancel all asynchronous operations associated with the socket.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
void cancel();
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Close the socket.
void close();
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Thrown on failure. Note that, even if the function indicates an error, the underlying descriptor is closed.
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Inherited from basic_socket.
Close the socket.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any. Note that, even if the function indicates an error, the underlying descriptor is closed.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.close(ec); if (ec) { // An error occurred. }
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint); » more... boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.connect(endpoint);
Inherited from basic_socket.
Connect the socket to the specified endpoint.
boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); boost::system::error_code ec; socket.connect(endpoint, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to enable socket-level debugging.
typedef implementation_defined debug;
Implements the SOL_SOCKET/SO_DEBUG socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to prevent routing, use local interfaces only.
typedef implementation_defined do_not_route;
Implements the SOL_SOCKET/SO_DONTROUTE socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to report aborted connections on accept.
typedef implementation_defined enable_connection_aborted;
Implements a custom socket option that determines whether or not an accept
operation is permitted to fail with boost::asio::error::connection_aborted
.
By default the option is false.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get an option from the socket.
void get_option( GettableSocketOption & option) const; » more... boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Thrown on failure.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; socket.get_option(option); bool is_set = option.value();
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Set to indicate what error occurred, if any.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; boost::system::error_code ec; socket.get_option(option, ec); if (ec) { // An error occurred. } bool is_set = option.value();
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the socket.
void io_control( IoControlCommand & command); » more... boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> void io_control( IoControlCommand & command);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Thrown on failure.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; socket.io_control(command); std::size_t bytes_readable = command.get();
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Set to indicate what error occurred, if any.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; boost::system::error_code ec; socket.io_control(command, ec); if (ec) { // An error occurred. } std::size_t bytes_readable = command.get();
Inherited from socket_base.
Socket option to send keep-alives.
typedef implementation_defined keep_alive;
Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to specify whether the socket lingers on close if unsent data is present.
typedef implementation_defined linger;
Implements the SOL_SOCKET/SO_LINGER socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option(true, 30); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option; socket.get_option(option); bool is_set = option.enabled(); unsigned short timeout = option.timeout();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Get the local endpoint of the socket.
endpoint_type local_endpoint() const; » more... endpoint_type local_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint() const;
This function is used to obtain the locally bound endpoint of the socket.
An object that represents the local endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint();
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the locally bound endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the local endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint(ec); if (ec) { // An error occurred. }
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Inherited from basic_socket.
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer();
This function returns a reference to the lowest layer in a stack of layers.
Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
This function returns a const reference to the lowest layer in a stack
of layers. Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A const reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
A basic_socket
is always the lowest
layer.
typedef basic_socket< Protocol, RawSocketService > lowest_layer_type;
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_socket without opening it. Construct and open a basic_socket. Construct a basic_socket, opening it and binding it to the given local endpoint. Construct a basic_socket on an existing native socket. Move-construct a basic_socket from another. Move-construct a basic_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_socket from another. Move-assign a basic_socket from a socket of another protocol type. |
|
Get the remote endpoint of the socket. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
|
Protected destructor to prevent deletion through this type. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_socket
class template provides functionality that is common to both stream-oriented
and datagram-oriented sockets.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
The maximum length of the queue of pending incoming connections.
static const int max_connections = implementation_defined;
Inherited from socket_base.
Specify that the data should not be subject to routing.
static const int message_do_not_route = implementation_defined;
Inherited from socket_base.
Specifies that the data marks the end of a record.
static const int message_end_of_record = implementation_defined;
Inherited from socket_base.
Bitmask type for flags that can be passed to send and receive operations.
typedef int message_flags;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
static const int message_out_of_band = implementation_defined;
Inherited from socket_base.
Peek at incoming data without removing it from the input queue.
static const int message_peek = implementation_defined;
Inherited from basic_socket.
(Deprecated: Use native_handle()
.) Get the native socket representation.
native_type native();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
Inherited from basic_socket.
Get the native socket representation.
native_handle_type native_handle();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
The native representation of a socket.
typedef RawSocketService::native_handle_type native_handle_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const; » more...
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode); » more... boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const;
This function is used to retrieve the non-blocking mode of the underlying native socket. This mode has no effect on the behaviour of the socket object's synchronous operations.
true
if the underlying socket
is in non-blocking mode and direct system calls may fail with boost::asio::error::would_block
(or the equivalent system
error).
The current non-blocking mode is cached by the socket object. Consequently, the return value may be incorrect if the non-blocking mode was set directly on the native socket.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Thrown on failure. If the mode
is false
, but the
current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Set to indicate what error occurred, if any. If the mode
is false
,
but the current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
(Deprecated: Use native_handle_type.) The native representation of a socket.
typedef RawSocketService::native_handle_type native_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the socket.
bool non_blocking() const; » more...
Sets the non-blocking mode of the socket.
void non_blocking( bool mode); » more... boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the socket.
bool non_blocking() const;
true
if the socket's synchronous
operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately. If
false
, synchronous operations
will block until complete.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
void non_blocking( bool mode);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Thrown on failure.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Set to indicate what error occurred, if any.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from socket_base.
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket.
typedef implementation_defined non_blocking_io;
Implements the FIONBIO IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::non_blocking_io command(true); socket.io_control(command);
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type()); » more... boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type());
This function opens the socket so that it will use the specified protocol.
An object specifying protocol parameters to be used.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4());
Inherited from basic_socket.
Open the socket using the specified protocol.
boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec);
This function opens the socket so that it will use the specified protocol.
An object specifying which protocol is to be used.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::system::error_code ec; socket.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
Move-assign a basic_raw_socket
from another.
basic_raw_socket & operator=( basic_raw_socket && other); » more...
Move-assign a basic_raw_socket
from a socket
of another protocol type.
template< typename Protocol1, typename RawSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_raw_socket >::type & operator=( basic_raw_socket< Protocol1, RawSocketService1 > && other); » more...
Move-assign a basic_raw_socket
from another.
basic_raw_socket & operator=( basic_raw_socket && other);
This assignment operator moves a raw socket from one object to another.
The other basic_raw_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_raw_socket(io_service&) constructor
.
Move-assign a basic_raw_socket
from a socket
of another protocol type.
template< typename Protocol1, typename RawSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_raw_socket >::type & operator=( basic_raw_socket< Protocol1, RawSocketService1 > && other);
This assignment operator moves a raw socket from one object to another.
The other basic_raw_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_raw_socket(io_service&) constructor
.
typedef Protocol protocol_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers); » more... template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags); » more... template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers);
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.
One or more buffers into which the data will be received.
The number of bytes received.
Thrown on failure.
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected raw socket.
To receive into a single data buffer use the buffer
function as follows:
socket.receive(boost::asio::buffer(data, size));
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags);
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.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
The number of bytes received.
Thrown on failure.
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected raw socket.
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec);
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.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
Set to indicate what error occurred, if any.
The number of bytes received.
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected raw socket.
Inherited from socket_base.
Socket option for the receive buffer size of a socket.
typedef implementation_defined receive_buffer_size;
Implements the SOL_SOCKET/SO_RCVBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Receive raw data with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint); » more... template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags); » more... template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Receive raw data with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint);
This function is used to receive raw data. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
An endpoint object that receives the endpoint of the remote sender of the data.
The number of bytes received.
Thrown on failure.
To receive into a single data buffer use the buffer
function as follows:
boost::asio::ip::udp::endpoint sender_endpoint; socket.receive_from( boost::asio::buffer(data, size), sender_endpoint);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Receive raw data with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags);
This function is used to receive raw data. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
An endpoint object that receives the endpoint of the remote sender of the data.
Flags specifying how the receive call is to be made.
The number of bytes received.
Thrown on failure.
Receive raw data with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags, boost::system::error_code & ec);
This function is used to receive raw data. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
An endpoint object that receives the endpoint of the remote sender of the data.
Flags specifying how the receive call is to be made.
Set to indicate what error occurred, if any.
The number of bytes received.
Inherited from socket_base.
Socket option for the receive low watermark.
typedef implementation_defined receive_low_watermark;
Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const; » more... endpoint_type remote_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const;
This function is used to obtain the remote endpoint of the socket.
An object that represents the remote endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the remote endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the remote endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to allow the socket to be bound to an address that is already in use.
typedef implementation_defined reuse_address;
Implements the SOL_SOCKET/SO_REUSEADDR socket option.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers); » more... template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags); » more... template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers);
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.
One ore more data buffers to be sent on the socket.
The number of bytes sent.
Thrown on failure.
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected raw socket.
To send a single data buffer use the buffer
function as follows:
socket.send(boost::asio::buffer(data, size));
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags);
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.
One ore more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
The number of bytes sent.
Thrown on failure.
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected raw socket.
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec);
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.
One or more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
Set to indicate what error occurred, if any.
The number of bytes sent.
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected raw socket.
Inherited from socket_base.
Socket option for the send buffer size of a socket.
typedef implementation_defined send_buffer_size;
Implements the SOL_SOCKET/SO_SNDBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send low watermark.
typedef implementation_defined send_low_watermark;
Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Send raw data to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination); » more... template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags); » more... template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Send raw data to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination);
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.
One or more data buffers to be sent to the remote endpoint.
The remote endpoint to which the data will be sent.
The number of bytes sent.
Thrown on failure.
To send a single data buffer use the buffer
function as follows:
boost::asio::ip::udp::endpoint destination( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.send_to(boost::asio::buffer(data, size), destination);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Send raw data to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags);
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.
One or more data buffers to be sent to the remote endpoint.
The remote endpoint to which the data will be sent.
Flags specifying how the send call is to be made.
The number of bytes sent.
Thrown on failure.
Send raw data to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags, boost::system::error_code & ec);
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.
One or more data buffers to be sent to the remote endpoint.
The remote endpoint to which the data will be sent.
Flags specifying how the send call is to be made.
Set to indicate what error occurred, if any.
The number of bytes sent.
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef RawSocketService service_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
void set_option( const SettableSocketOption & option); » more... boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Thrown on failure.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); socket.set_option(option);
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Set to indicate what error occurred, if any.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); boost::system::error_code ec; socket.set_option(option, ec); if (ec) { // An error occurred. }
Disable sends or receives on the socket.
void shutdown( shutdown_type what); » more... boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Disable sends or receives on the socket.
void shutdown( shutdown_type what);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Thrown on failure.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send);
Inherited from basic_socket.
Disable sends or receives on the socket.
boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Set to indicate what error occurred, if any.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Different ways a socket may be shutdown.
enum shutdown_type
Shutdown the receive side of the socket.
Shutdown the send side of the socket.
Shutdown both send and receive on the socket.
Provides sequenced packet socket functionality.
template< typename Protocol, typename SeqPacketSocketService = seq_packet_socket_service<Protocol>> class basic_seq_packet_socket : public basic_socket< Protocol, SeqPacketSocketService >
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Start an asynchronous receive. |
|
Start an asynchronous send. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_seq_packet_socket without opening it. Construct and open a basic_seq_packet_socket. Construct a basic_seq_packet_socket, opening it and binding it to the given local endpoint. Construct a basic_seq_packet_socket on an existing native socket. Move-construct a basic_seq_packet_socket from another. Move-construct a basic_seq_packet_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_seq_packet_socket from another. Move-assign a basic_seq_packet_socket from a socket of another protocol type. |
|
Receive some data on the socket. Receive some data on a connected socket. |
|
Get the remote endpoint of the socket. |
|
Send some data on the socket. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_seq_packet_socket
class template
provides asynchronous and blocking sequenced packet socket functionality.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket); » more... boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket);
Inherited from basic_socket.
Assign an existing native socket to the socket.
boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec);
Inherited from basic_socket.
Start an asynchronous connect.
template< typename ConnectHandler> void-or-deduced async_connect( const endpoint_type & peer_endpoint, ConnectHandler handler);
This function is used to asynchronously connect a socket to the specified remote endpoint. The function call always returns immediately.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected. Copies will be made of the endpoint object as required.
The handler to be called when the connection operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error // Result of operation );
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 boost::asio::io_service::post()
.
void connect_handler(const boost::system::error_code& error) { if (!error) { // Connect succeeded. } } ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.async_connect(endpoint, connect_handler);
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags & out_flags, ReadHandler handler); » more... template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags, ReadHandler handler); » more...
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags & out_flags, ReadHandler handler);
This function is used to asynchronously receive data from the sequenced packet socket. The function call always returns immediately.
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.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
To receive into a single data buffer use the buffer
function as follows:
socket.async_receive(boost::asio::buffer(data, size), out_flags, handler);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags, ReadHandler handler);
This function is used to asynchronously receive data from the sequenced data socket. The function call always returns immediately.
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.
Flags specifying how the receive call is to be made.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
To receive into a single data buffer use the buffer
function as follows:
socket.async_receive( boost::asio::buffer(data, size), 0, out_flags, handler);
See the 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 ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, socket_base::message_flags flags, WriteHandler handler);
This function is used to asynchronously send data on the sequenced packet socket. The function call always returns immediately.
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.
Flags specifying how the send call is to be made.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
To send a single data buffer use the buffer
function as follows:
socket.async_send(boost::asio::buffer(data, size), 0, handler);
See the buffer
documentation for information on sending multiple buffers in one go, and
how to use it with arrays, boost::array or std::vector.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const; » more... bool at_mark( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
A bool indicating whether the socket is at the out-of-band data mark.
Thrown on failure.
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark( boost::system::error_code & ec) const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
Set to indicate what error occurred, if any.
A bool indicating whether the socket is at the out-of-band data mark.
Determine the number of bytes available for reading.
std::size_t available() const; » more... std::size_t available( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available() const;
This function is used to determine the number of bytes that may be read without blocking.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Thrown on failure.
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available( boost::system::error_code & ec) const;
This function is used to determine the number of bytes that may be read without blocking.
Set to indicate what error occurred, if any.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Construct a basic_seq_packet_socket
without
opening it.
explicit basic_seq_packet_socket( boost::asio::io_service & io_service); » more...
Construct and open a basic_seq_packet_socket
.
basic_seq_packet_socket( boost::asio::io_service & io_service, const protocol_type & protocol); » more...
Construct a basic_seq_packet_socket
, opening
it and binding it to the given local endpoint.
basic_seq_packet_socket( boost::asio::io_service & io_service, const endpoint_type & endpoint); » more...
Construct a basic_seq_packet_socket
on an
existing native socket.
basic_seq_packet_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket); » more...
Move-construct a basic_seq_packet_socket
from another.
basic_seq_packet_socket( basic_seq_packet_socket && other); » more...
Move-construct a basic_seq_packet_socket
from a
socket of another protocol type.
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); » more...
Construct a basic_seq_packet_socket
without
opening it.
basic_seq_packet_socket( boost::asio::io_service & io_service);
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.
The io_service
object that
the sequenced packet socket will use to dispatch handlers for any
asynchronous operations performed on the socket.
Construct and open a basic_seq_packet_socket
.
basic_seq_packet_socket( boost::asio::io_service & io_service, const protocol_type & protocol);
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.
The io_service
object that
the sequenced packet socket will use to dispatch handlers for any
asynchronous operations performed on the socket.
An object specifying protocol parameters to be used.
Thrown on failure.
Construct a basic_seq_packet_socket
, opening
it and binding it to the given local endpoint.
basic_seq_packet_socket( boost::asio::io_service & io_service, const endpoint_type & 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.
The io_service
object that
the sequenced packet socket will use to dispatch handlers for any
asynchronous operations performed on the socket.
An endpoint on the local machine to which the sequenced packet socket will be bound.
Thrown on failure.
Construct a basic_seq_packet_socket
on an
existing native socket.
basic_seq_packet_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket);
This constructor creates a sequenced packet socket object to hold an existing native socket.
The io_service
object that
the sequenced packet socket will use to dispatch handlers for any
asynchronous operations performed on the socket.
An object specifying protocol parameters to be used.
The new underlying socket implementation.
Thrown on failure.
Move-construct a basic_seq_packet_socket
from
another.
basic_seq_packet_socket( basic_seq_packet_socket && other);
This constructor moves a sequenced packet socket from one object to another.
The other basic_seq_packet_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_seq_packet_socket(io_service&) constructor
.
Move-construct a basic_seq_packet_socket
from
a socket of another protocol type.
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);
This constructor moves a sequenced packet socket from one object to another.
The other basic_seq_packet_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_seq_packet_socket(io_service&) constructor
.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint); » more... boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345));
Inherited from basic_socket.
Bind the socket to the given local endpoint.
boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); boost::system::error_code ec; socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345), ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to permit sending of broadcast messages.
typedef implementation_defined broadcast;
Implements the SOL_SOCKET/SO_BROADCAST socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
IO control command to get the amount of data that can be read without blocking.
typedef implementation_defined bytes_readable;
Implements the FIONREAD IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::bytes_readable command(true); socket.io_control(command); std::size_t bytes_readable = command.get();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Cancel all asynchronous operations associated with the socket.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
void cancel();
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Close the socket.
void close();
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Thrown on failure. Note that, even if the function indicates an error, the underlying descriptor is closed.
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Inherited from basic_socket.
Close the socket.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any. Note that, even if the function indicates an error, the underlying descriptor is closed.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.close(ec); if (ec) { // An error occurred. }
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint); » more... boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.connect(endpoint);
Inherited from basic_socket.
Connect the socket to the specified endpoint.
boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); boost::system::error_code ec; socket.connect(endpoint, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to enable socket-level debugging.
typedef implementation_defined debug;
Implements the SOL_SOCKET/SO_DEBUG socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to prevent routing, use local interfaces only.
typedef implementation_defined do_not_route;
Implements the SOL_SOCKET/SO_DONTROUTE socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to report aborted connections on accept.
typedef implementation_defined enable_connection_aborted;
Implements a custom socket option that determines whether or not an accept
operation is permitted to fail with boost::asio::error::connection_aborted
.
By default the option is false.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get an option from the socket.
void get_option( GettableSocketOption & option) const; » more... boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Thrown on failure.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; socket.get_option(option); bool is_set = option.value();
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Set to indicate what error occurred, if any.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; boost::system::error_code ec; socket.get_option(option, ec); if (ec) { // An error occurred. } bool is_set = option.value();
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the socket.
void io_control( IoControlCommand & command); » more... boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> void io_control( IoControlCommand & command);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Thrown on failure.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; socket.io_control(command); std::size_t bytes_readable = command.get();
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Set to indicate what error occurred, if any.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; boost::system::error_code ec; socket.io_control(command, ec); if (ec) { // An error occurred. } std::size_t bytes_readable = command.get();
Inherited from socket_base.
Socket option to send keep-alives.
typedef implementation_defined keep_alive;
Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to specify whether the socket lingers on close if unsent data is present.
typedef implementation_defined linger;
Implements the SOL_SOCKET/SO_LINGER socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option(true, 30); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option; socket.get_option(option); bool is_set = option.enabled(); unsigned short timeout = option.timeout();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Get the local endpoint of the socket.
endpoint_type local_endpoint() const; » more... endpoint_type local_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint() const;
This function is used to obtain the locally bound endpoint of the socket.
An object that represents the local endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint();
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the locally bound endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the local endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint(ec); if (ec) { // An error occurred. }
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Inherited from basic_socket.
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer();
This function returns a reference to the lowest layer in a stack of layers.
Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
This function returns a const reference to the lowest layer in a stack
of layers. Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A const reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
A basic_socket
is always the lowest
layer.
typedef basic_socket< Protocol, SeqPacketSocketService > lowest_layer_type;
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_socket without opening it. Construct and open a basic_socket. Construct a basic_socket, opening it and binding it to the given local endpoint. Construct a basic_socket on an existing native socket. Move-construct a basic_socket from another. Move-construct a basic_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_socket from another. Move-assign a basic_socket from a socket of another protocol type. |
|
Get the remote endpoint of the socket. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
|
Protected destructor to prevent deletion through this type. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_socket
class template provides functionality that is common to both stream-oriented
and datagram-oriented sockets.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
The maximum length of the queue of pending incoming connections.
static const int max_connections = implementation_defined;
Inherited from socket_base.
Specify that the data should not be subject to routing.
static const int message_do_not_route = implementation_defined;
Inherited from socket_base.
Specifies that the data marks the end of a record.
static const int message_end_of_record = implementation_defined;
Inherited from socket_base.
Bitmask type for flags that can be passed to send and receive operations.
typedef int message_flags;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
static const int message_out_of_band = implementation_defined;
Inherited from socket_base.
Peek at incoming data without removing it from the input queue.
static const int message_peek = implementation_defined;
Inherited from basic_socket.
(Deprecated: Use native_handle()
.) Get the native socket representation.
native_type native();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
Inherited from basic_socket.
Get the native socket representation.
native_handle_type native_handle();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
The native representation of a socket.
typedef SeqPacketSocketService::native_handle_type native_handle_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const; » more...
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode); » more... boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const;
This function is used to retrieve the non-blocking mode of the underlying native socket. This mode has no effect on the behaviour of the socket object's synchronous operations.
true
if the underlying socket
is in non-blocking mode and direct system calls may fail with boost::asio::error::would_block
(or the equivalent system
error).
The current non-blocking mode is cached by the socket object. Consequently, the return value may be incorrect if the non-blocking mode was set directly on the native socket.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Thrown on failure. If the mode
is false
, but the
current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Set to indicate what error occurred, if any. If the mode
is false
,
but the current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
(Deprecated: Use native_handle_type.) The native representation of a socket.
typedef SeqPacketSocketService::native_handle_type native_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the socket.
bool non_blocking() const; » more...
Sets the non-blocking mode of the socket.
void non_blocking( bool mode); » more... boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the socket.
bool non_blocking() const;
true
if the socket's synchronous
operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately. If
false
, synchronous operations
will block until complete.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
void non_blocking( bool mode);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Thrown on failure.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Set to indicate what error occurred, if any.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from socket_base.
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket.
typedef implementation_defined non_blocking_io;
Implements the FIONBIO IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::non_blocking_io command(true); socket.io_control(command);
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type()); » more... boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type());
This function opens the socket so that it will use the specified protocol.
An object specifying protocol parameters to be used.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4());
Inherited from basic_socket.
Open the socket using the specified protocol.
boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec);
This function opens the socket so that it will use the specified protocol.
An object specifying which protocol is to be used.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::system::error_code ec; socket.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
Move-assign a basic_seq_packet_socket
from another.
basic_seq_packet_socket & operator=( basic_seq_packet_socket && other); » more...
Move-assign a basic_seq_packet_socket
from a
socket of another protocol type.
template< typename Protocol1, typename SeqPacketSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_seq_packet_socket >::type & operator=( basic_seq_packet_socket< Protocol1, SeqPacketSocketService1 > && other); » more...
Move-assign a basic_seq_packet_socket
from
another.
basic_seq_packet_socket & operator=( basic_seq_packet_socket && other);
This assignment operator moves a sequenced packet socket from one object to another.
The other basic_seq_packet_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_seq_packet_socket(io_service&) constructor
.
Move-assign a basic_seq_packet_socket
from
a socket of another protocol type.
template< typename Protocol1, typename SeqPacketSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_seq_packet_socket >::type & operator=( basic_seq_packet_socket< Protocol1, SeqPacketSocketService1 > && other);
This assignment operator moves a sequenced packet socket from one object to another.
The other basic_seq_packet_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_seq_packet_socket(io_service&) constructor
.
typedef Protocol protocol_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Receive some data on the socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags & out_flags); » more... template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags); » more...
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags, boost::system::error_code & ec); » more...
Receive some data on the socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags & out_flags);
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.
One or more buffers into which the data will be received.
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.
The number of bytes received.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
To receive into a single data buffer use the buffer
function as follows:
socket.receive(boost::asio::buffer(data, size), out_flags);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Receive some data on the socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags);
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.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
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.
The number of bytes received.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
The receive operation may not receive all of the requested number of
bytes. Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
To receive into a single data buffer use the buffer
function as follows:
socket.receive(boost::asio::buffer(data, size), 0, out_flags);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags, boost::system::error_code & ec);
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.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
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.
Set to indicate what error occurred, if any.
The number of bytes received. Returns 0 if an error occurred.
The receive operation may not receive all of the requested number of
bytes. Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
Inherited from socket_base.
Socket option for the receive buffer size of a socket.
typedef implementation_defined receive_buffer_size;
Implements the SOL_SOCKET/SO_RCVBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the receive low watermark.
typedef implementation_defined receive_low_watermark;
Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const; » more... endpoint_type remote_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const;
This function is used to obtain the remote endpoint of the socket.
An object that represents the remote endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the remote endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the remote endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to allow the socket to be bound to an address that is already in use.
typedef implementation_defined reuse_address;
Implements the SOL_SOCKET/SO_REUSEADDR socket option.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags); » more... template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Send some data on the socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags);
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.
One or more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
The number of bytes sent.
Thrown on failure.
To send a single data buffer use the buffer
function as follows:
socket.send(boost::asio::buffer(data, size), 0);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Send some data on the socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec);
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.
One or more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
Set to indicate what error occurred, if any.
The number of bytes sent. Returns 0 if an error occurred.
The send operation may not transmit all of the data to the peer. Consider
using the write
function if you need to ensure that all data is written before the blocking
operation completes.
Inherited from socket_base.
Socket option for the send buffer size of a socket.
typedef implementation_defined send_buffer_size;
Implements the SOL_SOCKET/SO_SNDBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send low watermark.
typedef implementation_defined send_low_watermark;
Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef SeqPacketSocketService service_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
void set_option( const SettableSocketOption & option); » more... boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Thrown on failure.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); socket.set_option(option);
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Set to indicate what error occurred, if any.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); boost::system::error_code ec; socket.set_option(option, ec); if (ec) { // An error occurred. }
Disable sends or receives on the socket.
void shutdown( shutdown_type what); » more... boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Disable sends or receives on the socket.
void shutdown( shutdown_type what);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Thrown on failure.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send);
Inherited from basic_socket.
Disable sends or receives on the socket.
boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Set to indicate what error occurred, if any.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Different ways a socket may be shutdown.
enum shutdown_type
Shutdown the receive side of the socket.
Shutdown the send side of the socket.
Shutdown both send and receive on the socket.
Provides serial port functionality.
template< typename SerialPortService = serial_port_service> class basic_serial_port : public basic_io_object< SerialPortService >, public serial_port_base
Name |
Description |
---|---|
The underlying implementation type of I/O object. |
|
A basic_serial_port is always the lowest layer. |
|
The native representation of a serial port. |
|
(Deprecated: Use native_handle_type.) The native representation of a serial port. |
|
The type of the service that will be used to provide I/O operations. |
Name |
Description |
---|---|
Assign an existing native serial port to the serial port. |
|
Start an asynchronous read. |
|
Start an asynchronous write. |
|
Construct a basic_serial_port without opening it. Construct and open a basic_serial_port. Construct a basic_serial_port on an existing native serial port. Move-construct a basic_serial_port from another. |
|
Cancel all asynchronous operations associated with the serial port. |
|
Close the serial port. |
|
Get the io_service associated with the object. |
|
Get an option from the serial port. |
|
Determine whether the serial port is open. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native serial port representation. |
|
Get the native serial port representation. |
|
Open the serial port using the specified device name. |
|
Move-assign a basic_serial_port from another. |
|
Read some data from the serial port. |
|
Send a break sequence to the serial port. |
|
Set an option on the serial port. |
|
Write some data to the serial port. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_serial_port
class template
provides functionality that is common to all serial ports.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_serial_port.hpp
Convenience header: boost/asio.hpp
Assign an existing native serial port to the serial port.
void assign( const native_handle_type & native_serial_port); » more... boost::system::error_code assign( const native_handle_type & native_serial_port, boost::system::error_code & ec); » more...
Assign an existing native serial port to the serial port.
void assign( const native_handle_type & native_serial_port);
Assign an existing native serial port to the serial port.
boost::system::error_code assign( const native_handle_type & native_serial_port, boost::system::error_code & ec);
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_read_some( const MutableBufferSequence & buffers, ReadHandler handler);
This function is used to asynchronously read data from the serial port. The function call always returns immediately.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes read. );
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 boost::asio::io_service::post()
.
The read operation may not read all of the requested number of bytes. Consider
using the async_read
function if you need
to ensure that the requested amount of data is read before the asynchronous
operation completes.
To read into a single data buffer use the buffer
function as follows:
serial_port.async_read_some(boost::asio::buffer(data, size), handler);
See the 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 ConstBufferSequence, typename WriteHandler> void-or-deduced async_write_some( const ConstBufferSequence & buffers, WriteHandler handler);
This function is used to asynchronously write data to the serial port. The function call always returns immediately.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes written. );
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 boost::asio::io_service::post()
.
The write operation may not transmit all of the data to the peer. Consider
using the async_write
function if you need
to ensure that all data is written before the asynchronous operation completes.
To write a single data buffer use the buffer
function as follows:
serial_port.async_write_some(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on writing multiple buffers in one go, and
how to use it with arrays, boost::array or std::vector.
Construct a basic_serial_port
without opening
it.
explicit basic_serial_port( boost::asio::io_service & io_service); » more...
Construct and open a basic_serial_port
.
explicit basic_serial_port( boost::asio::io_service & io_service, const char * device); » more... explicit basic_serial_port( boost::asio::io_service & io_service, const std::string & device); » more...
Construct a basic_serial_port
on an existing
native serial port.
basic_serial_port( boost::asio::io_service & io_service, const native_handle_type & native_serial_port); » more...
Move-construct a basic_serial_port
from another.
basic_serial_port( basic_serial_port && other); » more...
Construct a basic_serial_port
without opening
it.
basic_serial_port( boost::asio::io_service & io_service);
This constructor creates a serial port without opening it.
The io_service
object that
the serial port will use to dispatch handlers for any asynchronous
operations performed on the port.
Construct and open a basic_serial_port
.
basic_serial_port( boost::asio::io_service & io_service, const char * device);
This constructor creates and opens a serial port for the specified device name.
The io_service
object that
the serial port will use to dispatch handlers for any asynchronous
operations performed on the port.
The platform-specific device name for this serial port.
Construct and open a basic_serial_port
.
basic_serial_port( boost::asio::io_service & io_service, const std::string & device);
This constructor creates and opens a serial port for the specified device name.
The io_service
object that
the serial port will use to dispatch handlers for any asynchronous
operations performed on the port.
The platform-specific device name for this serial port.
Construct a basic_serial_port
on an existing
native serial port.
basic_serial_port( boost::asio::io_service & io_service, const native_handle_type & native_serial_port);
This constructor creates a serial port object to hold an existing native serial port.
The io_service
object that
the serial port will use to dispatch handlers for any asynchronous
operations performed on the port.
A native serial port.
Thrown on failure.
Move-construct a basic_serial_port
from another.
basic_serial_port( basic_serial_port && other);
This constructor moves a serial port from one object to another.
The other basic_serial_port
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_serial_port(io_service&) constructor
.
Cancel all asynchronous operations associated with the serial port.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Cancel all asynchronous operations associated with the serial port.
void cancel();
This function causes all outstanding asynchronous read or write operations
to finish immediately, and the handlers for cancelled operations will
be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Cancel all asynchronous operations associated with the serial port.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous read or write operations
to finish immediately, and the handlers for cancelled operations will
be passed the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Close the serial port.
void close();
This function is used to close the serial port. Any asynchronous read
or write operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Thrown on failure.
Close the serial port.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the serial port. Any asynchronous read
or write operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get an option from the serial port.
template< typename GettableSerialPortOption> void get_option( GettableSerialPortOption & option); » more... template< typename GettableSerialPortOption> boost::system::error_code get_option( GettableSerialPortOption & option, boost::system::error_code & ec); » more...
Get an option from the serial port.
template< typename GettableSerialPortOption> void get_option( GettableSerialPortOption & option);
This function is used to get the current value of an option on the serial port.
The option value to be obtained from the serial port.
Thrown on failure.
Get an option from the serial port.
template< typename GettableSerialPortOption> boost::system::error_code get_option( GettableSerialPortOption & option, boost::system::error_code & ec);
This function is used to get the current value of an option on the serial port.
The option value to be obtained from the serial port.
Set to indicate what error occurred, if any.
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_serial_port.hpp
Convenience header: boost/asio.hpp
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Get a reference to the lowest layer.
lowest_layer_type & 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.
A reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
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.
A const reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
A basic_serial_port
is always the
lowest layer.
typedef basic_serial_port< SerialPortService > lowest_layer_type;
Name |
Description |
---|---|
The underlying implementation type of I/O object. |
|
A basic_serial_port is always the lowest layer. |
|
The native representation of a serial port. |
|
(Deprecated: Use native_handle_type.) The native representation of a serial port. |
|
The type of the service that will be used to provide I/O operations. |
Name |
Description |
---|---|
Assign an existing native serial port to the serial port. |
|
Start an asynchronous read. |
|
Start an asynchronous write. |
|
Construct a basic_serial_port without opening it. Construct and open a basic_serial_port. Construct a basic_serial_port on an existing native serial port. Move-construct a basic_serial_port from another. |
|
Cancel all asynchronous operations associated with the serial port. |
|
Close the serial port. |
|
Get the io_service associated with the object. |
|
Get an option from the serial port. |
|
Determine whether the serial port is open. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native serial port representation. |
|
Get the native serial port representation. |
|
Open the serial port using the specified device name. |
|
Move-assign a basic_serial_port from another. |
|
Read some data from the serial port. |
|
Send a break sequence to the serial port. |
|
Set an option on the serial port. |
|
Write some data to the serial port. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_serial_port
class template
provides functionality that is common to all serial ports.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_serial_port.hpp
Convenience header: boost/asio.hpp
(Deprecated: Use native_handle()
.) Get the native serial port representation.
native_type native();
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.
Get the native serial port representation.
native_handle_type native_handle();
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.
The native representation of a serial port.
typedef SerialPortService::native_handle_type native_handle_type;
Header: boost/asio/basic_serial_port.hpp
Convenience header: boost/asio.hpp
(Deprecated: Use native_handle_type.) The native representation of a serial port.
typedef SerialPortService::native_handle_type native_type;
Header: boost/asio/basic_serial_port.hpp
Convenience header: boost/asio.hpp
Open the serial port using the specified device name.
void open( const std::string & device); » more... boost::system::error_code open( const std::string & device, boost::system::error_code & ec); » more...
Open the serial port using the specified device name.
void open( const std::string & device);
This function opens the serial port for the specified device name.
The platform-specific device name.
Thrown on failure.
Open the serial port using the specified device name.
boost::system::error_code open( const std::string & device, boost::system::error_code & ec);
This function opens the serial port using the given platform-specific device name.
The platform-specific device name.
Set the indicate what error occurred, if any.
Move-assign a basic_serial_port
from another.
basic_serial_port & operator=( basic_serial_port && other);
This assignment operator moves a serial port from one object to another.
The other basic_serial_port
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if constructed
using the basic_serial_port(io_service&) constructor
.
Read some data from the serial port.
template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers); » more... template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers, boost::system::error_code & ec); » more...
Read some data from the serial port.
template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers);
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.
One or more buffers into which the data will be read.
The number of bytes read.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
The read_some operation may not read all of the requested number of bytes.
Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
To read into a single data buffer use the buffer
function as follows:
serial_port.read_some(boost::asio::buffer(data, size));
See the buffer
documentation for information on reading into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Read some data from the serial port.
template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers, boost::system::error_code & ec);
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.
One or more buffers into which the data will be read.
Set to indicate what error occurred, if any.
The number of bytes read. Returns 0 if an error occurred.
The read_some operation may not read all of the requested number of bytes.
Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
Send a break sequence to the serial port.
void send_break(); » more... boost::system::error_code send_break( boost::system::error_code & ec); » more...
Send a break sequence to the serial port.
void send_break();
This function causes a break sequence of platform-specific duration to be sent out the serial port.
Thrown on failure.
Send a break sequence to the serial port.
boost::system::error_code send_break( boost::system::error_code & ec);
This function causes a break sequence of platform-specific duration to be sent out the serial port.
Set to indicate what error occurred, if any.
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef SerialPortService service_type;
Header: boost/asio/basic_serial_port.hpp
Convenience header: boost/asio.hpp
Set an option on the serial port.
template< typename SettableSerialPortOption> void set_option( const SettableSerialPortOption & option); » more... template< typename SettableSerialPortOption> boost::system::error_code set_option( const SettableSerialPortOption & option, boost::system::error_code & ec); » more...
Set an option on the serial port.
template< typename SettableSerialPortOption> void set_option( const SettableSerialPortOption & option);
This function is used to set an option on the serial port.
The option value to be set on the serial port.
Thrown on failure.
Set an option on the serial port.
template< typename SettableSerialPortOption> boost::system::error_code set_option( const SettableSerialPortOption & option, boost::system::error_code & ec);
This function is used to set an option on the serial port.
The option value to be set on the serial port.
Set to indicate what error occurred, if any.
Write some data to the serial port.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers); » more... template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers, boost::system::error_code & ec); » more...
Write some data to the serial port.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers);
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.
One or more data buffers to be written to the serial port.
The number of bytes written.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
The write_some operation may not transmit all of the data to the peer.
Consider using the write
function if you need to
ensure that all data is written before the blocking operation completes.
To write a single data buffer use the buffer
function as follows:
serial_port.write_some(boost::asio::buffer(data, size));
See the buffer
documentation for information on writing multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Write some data to the serial port.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers, boost::system::error_code & ec);
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.
One or more data buffers to be written to the serial port.
Set to indicate what error occurred, if any.
The number of bytes written. Returns 0 if an error occurred.
The write_some operation may not transmit all of the data to the peer.
Consider using the write
function if you need to
ensure that all data is written before the blocking operation completes.
Provides signal functionality.
template< typename SignalSetService = signal_set_service> class basic_signal_set : public basic_io_object< SignalSetService >
Name |
Description |
---|---|
The underlying implementation type of I/O object. |
|
The type of the service that will be used to provide I/O operations. |
Name |
Description |
---|---|
Add a signal to a signal_set. |
|
Start an asynchronous operation to wait for a signal to be delivered. |
|
Construct a signal set without adding any signals. Construct a signal set and add one signal. Construct a signal set and add two signals. Construct a signal set and add three signals. |
|
Cancel all operations associated with the signal set. |
|
Remove all signals from a signal_set. |
|
Get the io_service associated with the object. |
|
Remove a signal from a signal_set. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
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 signal_set
typedef.
Distinct objects: Safe.
Shared objects: Unsafe.
Performing an asynchronous wait:
void handler( const boost::system::error_code& error, int signal_number) { if (!error) { // A signal occurred. } } ... // Construct a signal set registered for process termination. boost::asio::signal_set signals(io_service, SIGINT, SIGTERM); // Start an asynchronous wait for one of the signals to occur. signals.async_wait(handler);
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 remove
or erase
member functions) then any queued notifications for that signal are discarded.
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 signal()
or sigaction()
.
POSIX allows signals to be blocked using functions such as sigprocmask()
and 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.
Header: boost/asio/basic_signal_set.hpp
Convenience header: boost/asio.hpp
void add( int signal_number); » more... boost::system::error_code add( int signal_number, boost::system::error_code & ec); » more...
Add a signal to a signal_set.
void add( int signal_number);
This function adds the specified signal to the set. It has no effect if the signal is already in the set.
The signal to be added to the set.
Thrown on failure.
Add a signal to a signal_set.
boost::system::error_code add( int signal_number, boost::system::error_code & ec);
This function adds the specified signal to the set. It has no effect if the signal is already in the set.
The signal to be added to the set.
Set to indicate what error occurred, if any.
Start an asynchronous operation to wait for a signal to be delivered.
template< typename SignalHandler> void-or-deduced async_wait( SignalHandler handler);
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:
boost::asio::error::operation_aborted
.
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:
void handler( const boost::system::error_code& error, // Result of operation. int signal_number // Indicates which signal occurred. );
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 boost::asio::io_service::post()
.
Construct a signal set without adding any signals.
explicit basic_signal_set( boost::asio::io_service & io_service); » more...
Construct a signal set and add one signal.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1); » more...
Construct a signal set and add two signals.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1, int signal_number_2); » more...
Construct a signal set and add three signals.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1, int signal_number_2, int signal_number_3); » more...
Construct a signal set without adding any signals.
basic_signal_set( boost::asio::io_service & io_service);
This constructor creates a signal set without registering for any signals.
The io_service
object that
the signal set will use to dispatch handlers for any asynchronous
operations performed on the set.
Construct a signal set and add one signal.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1);
This constructor creates a signal set and registers for one signal.
The io_service
object that
the signal set will use to dispatch handlers for any asynchronous
operations performed on the set.
The signal number to be added.
This constructor is equivalent to performing:
boost::asio::signal_set signals(io_service); signals.add(signal_number_1);
Construct a signal set and add two signals.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1, int signal_number_2);
This constructor creates a signal set and registers for two signals.
The io_service
object that
the signal set will use to dispatch handlers for any asynchronous
operations performed on the set.
The first signal number to be added.
The second signal number to be added.
This constructor is equivalent to performing:
boost::asio::signal_set signals(io_service); signals.add(signal_number_1); signals.add(signal_number_2);
Construct a signal set and add three signals.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1, int signal_number_2, int signal_number_3);
This constructor creates a signal set and registers for three signals.
The io_service
object that
the signal set will use to dispatch handlers for any asynchronous
operations performed on the set.
The first signal number to be added.
The second signal number to be added.
The third signal number to be added.
This constructor is equivalent to performing:
boost::asio::signal_set signals(io_service); signals.add(signal_number_1); signals.add(signal_number_2); signals.add(signal_number_3);
Cancel all operations associated with the signal set.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Cancel all operations associated with the signal set.
void cancel();
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 boost::asio::error::operation_aborted
error code.
Cancellation does not alter the set of registered signals.
Thrown on failure.
If a registered signal occurred before cancel()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Cancel all operations associated with the signal set.
boost::system::error_code cancel( boost::system::error_code & ec);
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 boost::asio::error::operation_aborted
error code.
Cancellation does not alter the set of registered signals.
Set to indicate what error occurred, if any.
If a registered signal occurred before cancel()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Remove all signals from a signal_set.
void clear(); » more... boost::system::error_code clear( boost::system::error_code & ec); » more...
Remove all signals from a signal_set.
void clear();
This function removes all signals from the set. It has no effect if the set is already empty.
Thrown on failure.
Removes all queued notifications.
Remove all signals from a signal_set.
boost::system::error_code clear( boost::system::error_code & ec);
This function removes all signals from the set. It has no effect if the set is already empty.
Set to indicate what error occurred, if any.
Removes all queued notifications.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_signal_set.hpp
Convenience header: boost/asio.hpp
Remove a signal from a signal_set.
void remove( int signal_number); » more... boost::system::error_code remove( int signal_number, boost::system::error_code & ec); » more...
Remove a signal from a signal_set.
void remove( int signal_number);
This function removes the specified signal from the set. It has no effect if the signal is not in the set.
The signal to be removed from the set.
Thrown on failure.
Removes any notifications that have been queued for the specified signal number.
Remove a signal from a signal_set.
boost::system::error_code remove( int signal_number, boost::system::error_code & ec);
This function removes the specified signal from the set. It has no effect if the signal is not in the set.
The signal to be removed from the set.
Set to indicate what error occurred, if any.
Removes any notifications that have been queued for the specified signal number.
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef SignalSetService service_type;
Header: boost/asio/basic_signal_set.hpp
Convenience header: boost/asio.hpp
Provides socket functionality.
template< typename Protocol, typename SocketService> class basic_socket : public basic_io_object< SocketService >, public socket_base
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_socket without opening it. Construct and open a basic_socket. Construct a basic_socket, opening it and binding it to the given local endpoint. Construct a basic_socket on an existing native socket. Move-construct a basic_socket from another. Move-construct a basic_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_socket from another. Move-assign a basic_socket from a socket of another protocol type. |
|
Get the remote endpoint of the socket. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
|
Protected destructor to prevent deletion through this type. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_socket
class template provides functionality that is common to both stream-oriented
and datagram-oriented sockets.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket); » more... boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec); » more...
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket);
Assign an existing native socket to the socket.
boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec);
Start an asynchronous connect.
template< typename ConnectHandler> void-or-deduced async_connect( const endpoint_type & peer_endpoint, ConnectHandler handler);
This function is used to asynchronously connect a socket to the specified remote endpoint. The function call always returns immediately.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected. Copies will be made of the endpoint object as required.
The handler to be called when the connection operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error // Result of operation );
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 boost::asio::io_service::post()
.
void connect_handler(const boost::system::error_code& error) { if (!error) { // Connect succeeded. } } ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.async_connect(endpoint, connect_handler);
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const; » more... bool at_mark( boost::system::error_code & ec) const; » more...
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
A bool indicating whether the socket is at the out-of-band data mark.
Thrown on failure.
Determine whether the socket is at the out-of-band data mark.
bool at_mark( boost::system::error_code & ec) const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
Set to indicate what error occurred, if any.
A bool indicating whether the socket is at the out-of-band data mark.
Determine the number of bytes available for reading.
std::size_t available() const; » more... std::size_t available( boost::system::error_code & ec) const; » more...
Determine the number of bytes available for reading.
std::size_t available() const;
This function is used to determine the number of bytes that may be read without blocking.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Thrown on failure.
Determine the number of bytes available for reading.
std::size_t available( boost::system::error_code & ec) const;
This function is used to determine the number of bytes that may be read without blocking.
Set to indicate what error occurred, if any.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Construct a basic_socket
without opening it.
explicit basic_socket( boost::asio::io_service & io_service); » more...
Construct and open a basic_socket
.
basic_socket( boost::asio::io_service & io_service, const protocol_type & protocol); » more...
Construct a basic_socket
, opening it and binding
it to the given local endpoint.
basic_socket( boost::asio::io_service & io_service, const endpoint_type & endpoint); » more...
Construct a basic_socket
on an existing native
socket.
basic_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket); » more...
Move-construct a basic_socket
from another.
basic_socket( basic_socket && other); » more...
Move-construct a basic_socket
from a socket of
another protocol type.
template< typename Protocol1, typename SocketService1> basic_socket( basic_socket< Protocol1, SocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0); » more...
Construct a basic_socket
without opening
it.
basic_socket( boost::asio::io_service & io_service);
This constructor creates a socket without opening it.
The io_service
object that
the socket will use to dispatch handlers for any asynchronous operations
performed on the socket.
Construct and open a basic_socket
.
basic_socket( boost::asio::io_service & io_service, const protocol_type & protocol);
This constructor creates and opens a socket.
The io_service
object that
the socket will use to dispatch handlers for any asynchronous operations
performed on the socket.
An object specifying protocol parameters to be used.
Thrown on failure.
Construct a basic_socket
, opening it and
binding it to the given local endpoint.
basic_socket( boost::asio::io_service & io_service, const endpoint_type & endpoint);
This constructor creates a 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.
The io_service
object that
the socket will use to dispatch handlers for any asynchronous operations
performed on the socket.
An endpoint on the local machine to which the socket will be bound.
Thrown on failure.
Construct a basic_socket
on an existing
native socket.
basic_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket);
This constructor creates a socket object to hold an existing native socket.
The io_service
object that
the socket will use to dispatch handlers for any asynchronous operations
performed on the socket.
An object specifying protocol parameters to be used.
A native socket.
Thrown on failure.
Move-construct a basic_socket
from another.
basic_socket( basic_socket && other);
This constructor moves a socket from one object to another.
The other basic_socket
object from
which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_socket(io_service&) constructor
.
Move-construct a basic_socket
from a socket of
another protocol type.
template< typename Protocol1, typename SocketService1> basic_socket( basic_socket< Protocol1, SocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0);
This constructor moves a socket from one object to another.
The other basic_socket
object from
which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_socket(io_service&) constructor
.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint); » more... boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec); » more...
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345));
Bind the socket to the given local endpoint.
boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); boost::system::error_code ec; socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345), ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to permit sending of broadcast messages.
typedef implementation_defined broadcast;
Implements the SOL_SOCKET/SO_BROADCAST socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
IO control command to get the amount of data that can be read without blocking.
typedef implementation_defined bytes_readable;
Implements the FIONREAD IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::bytes_readable command(true); socket.io_control(command); std::size_t bytes_readable = command.get();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Cancel all asynchronous operations associated with the socket.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Cancel all asynchronous operations associated with the socket.
void cancel();
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
Cancel all asynchronous operations associated with the socket.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Close the socket.
void close();
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Thrown on failure. Note that, even if the function indicates an error, the underlying descriptor is closed.
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Close the socket.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any. Note that, even if the function indicates an error, the underlying descriptor is closed.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.close(ec); if (ec) { // An error occurred. }
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint); » more... boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec); » more...
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.connect(endpoint);
Connect the socket to the specified endpoint.
boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); boost::system::error_code ec; socket.connect(endpoint, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to enable socket-level debugging.
typedef implementation_defined debug;
Implements the SOL_SOCKET/SO_DEBUG socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to prevent routing, use local interfaces only.
typedef implementation_defined do_not_route;
Implements the SOL_SOCKET/SO_DONTROUTE socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to report aborted connections on accept.
typedef implementation_defined enable_connection_aborted;
Implements a custom socket option that determines whether or not an accept
operation is permitted to fail with boost::asio::error::connection_aborted
.
By default the option is false.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get an option from the socket.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option) const; » more... template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const; » more...
Get an option from the socket.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Thrown on failure.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; socket.get_option(option); bool is_set = option.value();
Get an option from the socket.
template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Set to indicate what error occurred, if any.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; boost::system::error_code ec; socket.get_option(option, ec); if (ec) { // An error occurred. } bool is_set = option.value();
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the socket.
template< typename IoControlCommand> void io_control( IoControlCommand & command); » more... template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
Perform an IO control command on the socket.
template< typename IoControlCommand> void io_control( IoControlCommand & command);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Thrown on failure.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; socket.io_control(command); std::size_t bytes_readable = command.get();
Perform an IO control command on the socket.
template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Set to indicate what error occurred, if any.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; boost::system::error_code ec; socket.io_control(command, ec); if (ec) { // An error occurred. } std::size_t bytes_readable = command.get();
Inherited from socket_base.
Socket option to send keep-alives.
typedef implementation_defined keep_alive;
Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to specify whether the socket lingers on close if unsent data is present.
typedef implementation_defined linger;
Implements the SOL_SOCKET/SO_LINGER socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option(true, 30); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option; socket.get_option(option); bool is_set = option.enabled(); unsigned short timeout = option.timeout();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Get the local endpoint of the socket.
endpoint_type local_endpoint() const; » more... endpoint_type local_endpoint( boost::system::error_code & ec) const; » more...
Get the local endpoint of the socket.
endpoint_type local_endpoint() const;
This function is used to obtain the locally bound endpoint of the socket.
An object that represents the local endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint();
Get the local endpoint of the socket.
endpoint_type local_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the locally bound endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the local endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint(ec); if (ec) { // An error occurred. }
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer();
This function returns a reference to the lowest layer in a stack of layers.
Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
This function returns a const reference to the lowest layer in a stack
of layers. Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A const reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
A basic_socket
is always the lowest
layer.
typedef basic_socket< Protocol, SocketService > lowest_layer_type;
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_socket without opening it. Construct and open a basic_socket. Construct a basic_socket, opening it and binding it to the given local endpoint. Construct a basic_socket on an existing native socket. Move-construct a basic_socket from another. Move-construct a basic_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_socket from another. Move-assign a basic_socket from a socket of another protocol type. |
|
Get the remote endpoint of the socket. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
|
Protected destructor to prevent deletion through this type. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_socket
class template provides functionality that is common to both stream-oriented
and datagram-oriented sockets.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
The maximum length of the queue of pending incoming connections.
static const int max_connections = implementation_defined;
Inherited from socket_base.
Specify that the data should not be subject to routing.
static const int message_do_not_route = implementation_defined;
Inherited from socket_base.
Specifies that the data marks the end of a record.
static const int message_end_of_record = implementation_defined;
Inherited from socket_base.
Bitmask type for flags that can be passed to send and receive operations.
typedef int message_flags;
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
static const int message_out_of_band = implementation_defined;
Inherited from socket_base.
Peek at incoming data without removing it from the input queue.
static const int message_peek = implementation_defined;
(Deprecated: Use native_handle()
.) Get the native socket representation.
native_type native();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
Get the native socket representation.
native_handle_type native_handle();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
The native representation of a socket.
typedef SocketService::native_handle_type native_handle_type;
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const; » more...
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode); » more... boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec); » more...
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const;
This function is used to retrieve the non-blocking mode of the underlying native socket. This mode has no effect on the behaviour of the socket object's synchronous operations.
true
if the underlying socket
is in non-blocking mode and direct system calls may fail with boost::asio::error::would_block
(or the equivalent system
error).
The current non-blocking mode is cached by the socket object. Consequently, the return value may be incorrect if the non-blocking mode was set directly on the native socket.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Thrown on failure. If the mode
is false
, but the
current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Sets the non-blocking mode of the native socket implementation.
boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Set to indicate what error occurred, if any. If the mode
is false
,
but the current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
(Deprecated: Use native_handle_type.) The native representation of a socket.
typedef SocketService::native_handle_type native_type;
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the socket.
bool non_blocking() const; » more...
Sets the non-blocking mode of the socket.
void non_blocking( bool mode); » more... boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec); » more...
Gets the non-blocking mode of the socket.
bool non_blocking() const;
true
if the socket's synchronous
operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately. If
false
, synchronous operations
will block until complete.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Sets the non-blocking mode of the socket.
void non_blocking( bool mode);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Thrown on failure.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Sets the non-blocking mode of the socket.
boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Set to indicate what error occurred, if any.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from socket_base.
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket.
typedef implementation_defined non_blocking_io;
Implements the FIONBIO IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::non_blocking_io command(true); socket.io_control(command);
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type()); » more... boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec); » more...
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type());
This function opens the socket so that it will use the specified protocol.
An object specifying protocol parameters to be used.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4());
Open the socket using the specified protocol.
boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec);
This function opens the socket so that it will use the specified protocol.
An object specifying which protocol is to be used.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::system::error_code ec; socket.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
Move-assign a basic_socket
from another.
basic_socket & operator=( basic_socket && other); » more...
Move-assign a basic_socket
from a socket of
another protocol type.
template< typename Protocol1, typename SocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_socket >::type & operator=( basic_socket< Protocol1, SocketService1 > && other); » more...
Move-assign a basic_socket
from another.
basic_socket & operator=( basic_socket && other);
This assignment operator moves a socket from one object to another.
The other basic_socket
object from
which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_socket(io_service&) constructor
.
Move-assign a basic_socket
from a socket of
another protocol type.
template< typename Protocol1, typename SocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_socket >::type & operator=( basic_socket< Protocol1, SocketService1 > && other);
This assignment operator moves a socket from one object to another.
The other basic_socket
object from
which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_socket(io_service&) constructor
.
typedef Protocol protocol_type;
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the receive buffer size of a socket.
typedef implementation_defined receive_buffer_size;
Implements the SOL_SOCKET/SO_RCVBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the receive low watermark.
typedef implementation_defined receive_low_watermark;
Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const; » more... endpoint_type remote_endpoint( boost::system::error_code & ec) const; » more...
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const;
This function is used to obtain the remote endpoint of the socket.
An object that represents the remote endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();
Get the remote endpoint of the socket.
endpoint_type remote_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the remote endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the remote endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to allow the socket to be bound to an address that is already in use.
typedef implementation_defined reuse_address;
Implements the SOL_SOCKET/SO_REUSEADDR socket option.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send buffer size of a socket.
typedef implementation_defined send_buffer_size;
Implements the SOL_SOCKET/SO_SNDBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send low watermark.
typedef implementation_defined send_low_watermark;
Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef SocketService service_type;
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option); » more... template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
Set an option on the socket.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Thrown on failure.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); socket.set_option(option);
Set an option on the socket.
template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Set to indicate what error occurred, if any.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); boost::system::error_code ec; socket.set_option(option, ec); if (ec) { // An error occurred. }
Disable sends or receives on the socket.
void shutdown( shutdown_type what); » more... boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec); » more...
Disable sends or receives on the socket.
void shutdown( shutdown_type what);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Thrown on failure.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send);
Disable sends or receives on the socket.
boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Set to indicate what error occurred, if any.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Different ways a socket may be shutdown.
enum shutdown_type
Shutdown the receive side of the socket.
Shutdown the send side of the socket.
Shutdown both send and receive on the socket.
Provides the ability to accept new connections.
template< typename Protocol, typename SocketAcceptorService = socket_acceptor_service<Protocol>> class basic_socket_acceptor : public basic_io_object< SocketAcceptorService >, public socket_base
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of an acceptor. |
|
(Deprecated: Use native_handle_type.) The native representation of an acceptor. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Accept a new connection. Accept a new connection and obtain the endpoint of the peer. |
|
Assigns an existing native acceptor to the acceptor. |
|
Start an asynchronous accept. |
|
Construct an acceptor without opening it. Construct an open acceptor. Construct an acceptor opened on the given endpoint. Construct a basic_socket_acceptor on an existing native acceptor. Move-construct a basic_socket_acceptor from another. Move-construct a basic_socket_acceptor from an acceptor of another protocol type. |
|
Bind the acceptor to the given local endpoint. |
|
Cancel all asynchronous operations associated with the acceptor. |
|
Close the acceptor. |
|
Get the io_service associated with the object. |
|
Get an option from the acceptor. |
|
Perform an IO control command on the acceptor. |
|
Determine whether the acceptor is open. |
|
Place the acceptor into the state where it will listen for new connections. |
|
Get the local endpoint of the acceptor. |
|
(Deprecated: Use native_handle().) Get the native acceptor representation. |
|
Get the native acceptor representation. |
|
Gets the non-blocking mode of the native acceptor implementation. Sets the non-blocking mode of the native acceptor implementation. |
|
Gets the non-blocking mode of the acceptor. Sets the non-blocking mode of the acceptor. |
|
Open the acceptor using the specified protocol. |
|
Move-assign a basic_socket_acceptor from another. Move-assign a basic_socket_acceptor from an acceptor of another protocol type. |
|
Set an option on the acceptor. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_socket_acceptor
class template
is used for accepting new socket connections.
Distinct objects: Safe.
Shared objects: Unsafe.
Opening a socket acceptor with the SO_REUSEADDR option enabled:
boost::asio::ip::tcp::acceptor acceptor(io_service); boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port); acceptor.open(endpoint.protocol()); acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); acceptor.bind(endpoint); acceptor.listen();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
template< typename Protocol1, typename SocketService> void accept( basic_socket< Protocol1, SocketService > & peer, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0); » more... template< typename Protocol1, typename SocketService> boost::system::error_code accept( basic_socket< Protocol1, SocketService > & peer, boost::system::error_code & ec, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0); » more...
Accept a new connection and obtain the endpoint of the peer.
template< typename SocketService> void accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint); » more... template< typename SocketService> boost::system::error_code accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint, boost::system::error_code & ec); » more...
Accept a new connection.
template< typename Protocol1, typename SocketService> void accept( basic_socket< Protocol1, SocketService > & peer, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0);
This function is used to accept a new connection from a peer into the given socket. The function call will block until a new connection has been accepted successfully or an error occurs.
The socket into which the new connection will be accepted.
Thrown on failure.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::socket socket(io_service); acceptor.accept(socket);
Accept a new connection.
template< typename Protocol1, typename SocketService> boost::system::error_code accept( basic_socket< Protocol1, SocketService > & peer, boost::system::error_code & ec, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0);
This function is used to accept a new connection from a peer into the given socket. The function call will block until a new connection has been accepted successfully or an error occurs.
The socket into which the new connection will be accepted.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::soocket socket(io_service); boost::system::error_code ec; acceptor.accept(socket, ec); if (ec) { // An error occurred. }
Accept a new connection and obtain the endpoint of the peer.
template< typename SocketService> void accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint);
This function is used to accept a new connection from a peer into the given socket, and additionally provide the endpoint of the remote peer. The function call will block until a new connection has been accepted successfully or an error occurs.
The socket into which the new connection will be accepted.
An endpoint object which will receive the endpoint of the remote peer.
Thrown on failure.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint; acceptor.accept(socket, endpoint);
Accept a new connection and obtain the endpoint of the peer.
template< typename SocketService> boost::system::error_code accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint, boost::system::error_code & ec);
This function is used to accept a new connection from a peer into the given socket, and additionally provide the endpoint of the remote peer. The function call will block until a new connection has been accepted successfully or an error occurs.
The socket into which the new connection will be accepted.
An endpoint object which will receive the endpoint of the remote peer.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint; boost::system::error_code ec; acceptor.accept(socket, endpoint, ec); if (ec) { // An error occurred. }
Assigns an existing native acceptor to the acceptor.
void assign( const protocol_type & protocol, const native_handle_type & native_acceptor); » more... boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_acceptor, boost::system::error_code & ec); » more...
Assigns an existing native acceptor to the acceptor.
void assign( const protocol_type & protocol, const native_handle_type & native_acceptor);
Assigns an existing native acceptor to the acceptor.
boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_acceptor, boost::system::error_code & ec);
template< typename Protocol1, typename SocketService, typename AcceptHandler> void-or-deduced async_accept( basic_socket< Protocol1, SocketService > & peer, AcceptHandler handler, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0); » more... template< typename SocketService, typename AcceptHandler> void-or-deduced async_accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint, AcceptHandler handler); » more...
Start an asynchronous accept.
template< typename Protocol1, typename SocketService, typename AcceptHandler> void-or-deduced async_accept( basic_socket< Protocol1, SocketService > & peer, AcceptHandler handler, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0);
This function is used to asynchronously accept a new connection into a socket. The function call always returns immediately.
The socket into which the new connection will be accepted. Ownership of the peer object is retained by the caller, which must guarantee that it is valid until the handler is called.
The handler to be called when the accept operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error // Result of operation. );
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 boost::asio::io_service::post()
.
void accept_handler(const boost::system::error_code& error) { if (!error) { // Accept succeeded. } } ... boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::socket socket(io_service); acceptor.async_accept(socket, accept_handler);
Start an asynchronous accept.
template< typename SocketService, typename AcceptHandler> void-or-deduced async_accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint, AcceptHandler handler);
This function is used to asynchronously accept a new connection into a socket, and additionally obtain the endpoint of the remote peer. The function call always returns immediately.
The socket into which the new connection will be accepted. Ownership of the peer object is retained by the caller, which must guarantee that it is valid until the handler is called.
An endpoint object into which the endpoint of the remote peer will be written. Ownership of the peer_endpoint object is retained by the caller, which must guarantee that it is valid until the handler is called.
The handler to be called when the accept operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error // Result of operation. );
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 boost::asio::io_service::post()
.
Construct an acceptor without opening it.
explicit basic_socket_acceptor( boost::asio::io_service & io_service); » more...
Construct an open acceptor.
basic_socket_acceptor( boost::asio::io_service & io_service, const protocol_type & protocol); » more...
Construct an acceptor opened on the given endpoint.
basic_socket_acceptor( boost::asio::io_service & io_service, const endpoint_type & endpoint, bool reuse_addr = true); » more...
Construct a basic_socket_acceptor
on an existing
native acceptor.
basic_socket_acceptor( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_acceptor); » more...
Move-construct a basic_socket_acceptor
from another.
basic_socket_acceptor( basic_socket_acceptor && other); » more...
Move-construct a basic_socket_acceptor
from an
acceptor of another protocol type.
template< typename Protocol1, typename SocketAcceptorService1> basic_socket_acceptor( basic_socket_acceptor< Protocol1, SocketAcceptorService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0); » more...
Construct an acceptor without opening it.
basic_socket_acceptor( boost::asio::io_service & io_service);
This constructor creates an acceptor without opening it to listen for
new connections. The open()
function must be called before the
acceptor can accept new socket connections.
The io_service
object that
the acceptor will use to dispatch handlers for any asynchronous
operations performed on the acceptor.
Construct an open acceptor.
basic_socket_acceptor( boost::asio::io_service & io_service, const protocol_type & protocol);
This constructor creates an acceptor and automatically opens it.
The io_service
object that
the acceptor will use to dispatch handlers for any asynchronous
operations performed on the acceptor.
An object specifying protocol parameters to be used.
Thrown on failure.
Construct an acceptor opened on the given endpoint.
basic_socket_acceptor( boost::asio::io_service & io_service, const endpoint_type & endpoint, bool reuse_addr = true);
This constructor creates an acceptor and automatically opens it to listen for new connections on the specified endpoint.
The io_service
object that
the acceptor will use to dispatch handlers for any asynchronous
operations performed on the acceptor.
An endpoint on the local machine on which the acceptor will listen for new connections.
Whether the constructor should set the socket option socket_base::reuse_address
.
Thrown on failure.
This constructor is equivalent to the following code:
basic_socket_acceptor<Protocol> acceptor(io_service); acceptor.open(endpoint.protocol()); if (reuse_addr) acceptor.set_option(socket_base::reuse_address(true)); acceptor.bind(endpoint); acceptor.listen(listen_backlog);
Construct a basic_socket_acceptor
on an
existing native acceptor.
basic_socket_acceptor( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_acceptor);
This constructor creates an acceptor object to hold an existing native acceptor.
The io_service
object that
the acceptor will use to dispatch handlers for any asynchronous
operations performed on the acceptor.
An object specifying protocol parameters to be used.
A native acceptor.
Thrown on failure.
Move-construct a basic_socket_acceptor
from another.
basic_socket_acceptor( basic_socket_acceptor && other);
This constructor moves an acceptor from one object to another.
The other basic_socket_acceptor
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_socket_acceptor(io_service&) constructor
.
Move-construct a basic_socket_acceptor
from an
acceptor of another protocol type.
template< typename Protocol1, typename SocketAcceptorService1> basic_socket_acceptor( basic_socket_acceptor< Protocol1, SocketAcceptorService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0);
This constructor moves an acceptor from one object to another.
The other basic_socket_acceptor
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_socket(io_service&) constructor
.
Bind the acceptor to the given local endpoint.
void bind( const endpoint_type & endpoint); » more... boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec); » more...
Bind the acceptor to the given local endpoint.
void bind( const endpoint_type & endpoint);
This function binds the socket acceptor to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket acceptor will be bound.
Thrown on failure.
boost::asio::ip::tcp::acceptor acceptor(io_service); boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 12345); acceptor.open(endpoint.protocol()); acceptor.bind(endpoint);
Bind the acceptor to the given local endpoint.
boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec);
This function binds the socket acceptor to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket acceptor will be bound.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 12345); acceptor.open(endpoint.protocol()); boost::system::error_code ec; acceptor.bind(endpoint, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to permit sending of broadcast messages.
typedef implementation_defined broadcast;
Implements the SOL_SOCKET/SO_BROADCAST socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
IO control command to get the amount of data that can be read without blocking.
typedef implementation_defined bytes_readable;
Implements the FIONREAD IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::bytes_readable command(true); socket.io_control(command); std::size_t bytes_readable = command.get();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Cancel all asynchronous operations associated with the acceptor.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Cancel all asynchronous operations associated with the acceptor.
void cancel();
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Cancel all asynchronous operations associated with the acceptor.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Close the acceptor.
void close();
This function is used to close the acceptor. Any asynchronous accept operations will be cancelled immediately.
A subsequent call to open()
is required before the acceptor can
again be used to again perform socket accept operations.
Thrown on failure.
Close the acceptor.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the acceptor. Any asynchronous accept operations will be cancelled immediately.
A subsequent call to open()
is required before the acceptor can
again be used to again perform socket accept operations.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::system::error_code ec; acceptor.close(ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to enable socket-level debugging.
typedef implementation_defined debug;
Implements the SOL_SOCKET/SO_DEBUG socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to prevent routing, use local interfaces only.
typedef implementation_defined do_not_route;
Implements the SOL_SOCKET/SO_DONTROUTE socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to report aborted connections on accept.
typedef implementation_defined enable_connection_aborted;
Implements a custom socket option that determines whether or not an accept
operation is permitted to fail with boost::asio::error::connection_aborted
.
By default the option is false.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get an option from the acceptor.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option); » more... template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec); » more...
Get an option from the acceptor.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option);
This function is used to get the current value of an option on the acceptor.
The option value to be obtained from the acceptor.
Thrown on failure.
Getting the value of the SOL_SOCKET/SO_REUSEADDR option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::reuse_address option; acceptor.get_option(option); bool is_set = option.get();
Get an option from the acceptor.
template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec);
This function is used to get the current value of an option on the acceptor.
The option value to be obtained from the acceptor.
Set to indicate what error occurred, if any.
Getting the value of the SOL_SOCKET/SO_REUSEADDR option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::reuse_address option; boost::system::error_code ec; acceptor.get_option(option, ec); if (ec) { // An error occurred. } bool is_set = option.get();
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the acceptor.
template< typename IoControlCommand> void io_control( IoControlCommand & command); » more... template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
Perform an IO control command on the acceptor.
template< typename IoControlCommand> void io_control( IoControlCommand & command);
This function is used to execute an IO control command on the acceptor.
The IO control command to be performed on the acceptor.
Thrown on failure.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::non_blocking_io command(true); socket.io_control(command);
Perform an IO control command on the acceptor.
template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec);
This function is used to execute an IO control command on the acceptor.
The IO control command to be performed on the acceptor.
Set to indicate what error occurred, if any.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::non_blocking_io command(true); boost::system::error_code ec; socket.io_control(command, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to send keep-alives.
typedef implementation_defined keep_alive;
Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to specify whether the socket lingers on close if unsent data is present.
typedef implementation_defined linger;
Implements the SOL_SOCKET/SO_LINGER socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option(true, 30); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option; socket.get_option(option); bool is_set = option.enabled(); unsigned short timeout = option.timeout();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Place the acceptor into the state where it will listen for new connections.
void listen( int backlog = socket_base::max_connections); » more... boost::system::error_code listen( int backlog, boost::system::error_code & ec); » more...
Place the acceptor into the state where it will listen for new connections.
void listen( int backlog = socket_base::max_connections);
This function puts the socket acceptor into the state where it may accept new connections.
The maximum length of the queue of pending connections.
Thrown on failure.
Place the acceptor into the state where it will listen for new connections.
boost::system::error_code listen( int backlog, boost::system::error_code & ec);
This function puts the socket acceptor into the state where it may accept new connections.
The maximum length of the queue of pending connections.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::system::error_code ec; acceptor.listen(boost::asio::socket_base::max_connections, ec); if (ec) { // An error occurred. }
Get the local endpoint of the acceptor.
endpoint_type local_endpoint() const; » more... endpoint_type local_endpoint( boost::system::error_code & ec) const; » more...
Get the local endpoint of the acceptor.
endpoint_type local_endpoint() const;
This function is used to obtain the locally bound endpoint of the acceptor.
An object that represents the local endpoint of the acceptor.
Thrown on failure.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::endpoint endpoint = acceptor.local_endpoint();
Get the local endpoint of the acceptor.
endpoint_type local_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the locally bound endpoint of the acceptor.
Set to indicate what error occurred, if any.
An object that represents the local endpoint of the acceptor. Returns a default-constructed endpoint object if an error occurred and the error handler did not throw an exception.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = acceptor.local_endpoint(ec); if (ec) { // An error occurred. }
Inherited from socket_base.
The maximum length of the queue of pending incoming connections.
static const int max_connections = implementation_defined;
Inherited from socket_base.
Specify that the data should not be subject to routing.
static const int message_do_not_route = implementation_defined;
Inherited from socket_base.
Specifies that the data marks the end of a record.
static const int message_end_of_record = implementation_defined;
Inherited from socket_base.
Bitmask type for flags that can be passed to send and receive operations.
typedef int message_flags;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
static const int message_out_of_band = implementation_defined;
Inherited from socket_base.
Peek at incoming data without removing it from the input queue.
static const int message_peek = implementation_defined;
(Deprecated: Use native_handle()
.) Get the native acceptor representation.
native_type native();
This function may be used to obtain the underlying representation of the acceptor. This is intended to allow access to native acceptor functionality that is not otherwise provided.
Get the native acceptor representation.
native_handle_type native_handle();
This function may be used to obtain the underlying representation of the acceptor. This is intended to allow access to native acceptor functionality that is not otherwise provided.
The native representation of an acceptor.
typedef SocketAcceptorService::native_handle_type native_handle_type;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the native acceptor implementation.
bool native_non_blocking() const; » more...
Sets the non-blocking mode of the native acceptor implementation.
void native_non_blocking( bool mode); » more... boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec); » more...
Gets the non-blocking mode of the native acceptor implementation.
bool native_non_blocking() const;
This function is used to retrieve the non-blocking mode of the underlying native acceptor. This mode has no effect on the behaviour of the acceptor object's synchronous operations.
true
if the underlying acceptor
is in non-blocking mode and direct system calls may fail with boost::asio::error::would_block
(or the equivalent system
error).
The current non-blocking mode is cached by the acceptor object. Consequently, the return value may be incorrect if the non-blocking mode was set directly on the native acceptor.
Sets the non-blocking mode of the native acceptor implementation.
void native_non_blocking( bool mode);
This function is used to modify the non-blocking mode of the underlying native acceptor. It has no effect on the behaviour of the acceptor object's synchronous operations.
If true
, the underlying
acceptor is put into non-blocking mode and direct system calls
may fail with boost::asio::error::would_block
(or the equivalent system error).
Thrown on failure. If the mode
is false
, but the
current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
Sets the non-blocking mode of the native acceptor implementation.
boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec);
This function is used to modify the non-blocking mode of the underlying native acceptor. It has no effect on the behaviour of the acceptor object's synchronous operations.
If true
, the underlying
acceptor is put into non-blocking mode and direct system calls
may fail with boost::asio::error::would_block
(or the equivalent system error).
Set to indicate what error occurred, if any. If the mode
is false
,
but the current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
(Deprecated: Use native_handle_type.) The native representation of an acceptor.
typedef SocketAcceptorService::native_handle_type native_type;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the acceptor.
bool non_blocking() const; » more...
Sets the non-blocking mode of the acceptor.
void non_blocking( bool mode); » more... boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec); » more...
Gets the non-blocking mode of the acceptor.
bool non_blocking() const;
true
if the acceptor's synchronous
operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately. If
false
, synchronous operations
will block until complete.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Sets the non-blocking mode of the acceptor.
void non_blocking( bool mode);
If true
, the acceptor's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Thrown on failure.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Sets the non-blocking mode of the acceptor.
boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec);
If true
, the acceptor's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Set to indicate what error occurred, if any.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from socket_base.
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket.
typedef implementation_defined non_blocking_io;
Implements the FIONBIO IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::non_blocking_io command(true); socket.io_control(command);
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Open the acceptor using the specified protocol.
void open( const protocol_type & protocol = protocol_type()); » more... boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec); » more...
Open the acceptor using the specified protocol.
void open( const protocol_type & protocol = protocol_type());
This function opens the socket acceptor so that it will use the specified protocol.
An object specifying which protocol is to be used.
Thrown on failure.
boost::asio::ip::tcp::acceptor acceptor(io_service); acceptor.open(boost::asio::ip::tcp::v4());
Open the acceptor using the specified protocol.
boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec);
This function opens the socket acceptor so that it will use the specified protocol.
An object specifying which protocol is to be used.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); boost::system::error_code ec; acceptor.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
Move-assign a basic_socket_acceptor
from another.
basic_socket_acceptor & operator=( basic_socket_acceptor && other); » more...
Move-assign a basic_socket_acceptor
from an
acceptor of another protocol type.
template< typename Protocol1, typename SocketAcceptorService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_socket_acceptor >::type & operator=( basic_socket_acceptor< Protocol1, SocketAcceptorService1 > && other); » more...
Move-assign a basic_socket_acceptor
from another.
basic_socket_acceptor & operator=( basic_socket_acceptor && other);
This assignment operator moves an acceptor from one object to another.
The other basic_socket_acceptor
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_socket_acceptor(io_service&) constructor
.
Move-assign a basic_socket_acceptor
from an
acceptor of another protocol type.
template< typename Protocol1, typename SocketAcceptorService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_socket_acceptor >::type & operator=( basic_socket_acceptor< Protocol1, SocketAcceptorService1 > && other);
This assignment operator moves an acceptor from one object to another.
The other basic_socket_acceptor
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_socket(io_service&) constructor
.
typedef Protocol protocol_type;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the receive buffer size of a socket.
typedef implementation_defined receive_buffer_size;
Implements the SOL_SOCKET/SO_RCVBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the receive low watermark.
typedef implementation_defined receive_low_watermark;
Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to allow the socket to be bound to an address that is already in use.
typedef implementation_defined reuse_address;
Implements the SOL_SOCKET/SO_REUSEADDR socket option.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send buffer size of a socket.
typedef implementation_defined send_buffer_size;
Implements the SOL_SOCKET/SO_SNDBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send low watermark.
typedef implementation_defined send_low_watermark;
Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef SocketAcceptorService service_type;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Set an option on the acceptor.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option); » more... template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
Set an option on the acceptor.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option);
This function is used to set an option on the acceptor.
The new option value to be set on the acceptor.
Thrown on failure.
Setting the SOL_SOCKET/SO_REUSEADDR option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::reuse_address option(true); acceptor.set_option(option);
Set an option on the acceptor.
template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec);
This function is used to set an option on the acceptor.
The new option value to be set on the acceptor.
Set to indicate what error occurred, if any.
Setting the SOL_SOCKET/SO_REUSEADDR option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::reuse_address option(true); boost::system::error_code ec; acceptor.set_option(option, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Different ways a socket may be shutdown.
enum shutdown_type
Shutdown the receive side of the socket.
Shutdown the send side of the socket.
Shutdown both send and receive on the socket.
Iostream interface for a socket.
template< typename Protocol, typename StreamSocketService = stream_socket_service<Protocol>, typename Time = boost::posix_time::ptime, typename TimeTraits = boost::asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>> class basic_socket_iostream
Name |
Description |
---|---|
The duration type. |
|
The endpoint type. |
|
The time type. |
Name |
Description |
---|---|
Construct a basic_socket_iostream without establishing a connection. Establish a connection to an endpoint corresponding to a resolver query. |
|
Close the connection. |
|
Establish a connection to an endpoint corresponding to a resolver query. |
|
Get the last error associated with the stream. |
|
Get the stream's expiry time as an absolute time. Set the stream's expiry time as an absolute time. |
|
Get the timer's expiry time relative to now. Set the stream's expiry time relative to now. |
|
Return a pointer to the underlying streambuf. |
Header: boost/asio/basic_socket_iostream.hpp
Convenience header: boost/asio.hpp
Construct a basic_socket_iostream
without
establishing a connection.
basic_socket_iostream(); » more...
Establish a connection to an endpoint corresponding to a resolver query.
template< typename T1, ... , typename TN> explicit basic_socket_iostream( T1 t1, ... , TN tn); » more...
Construct a basic_socket_iostream
without
establishing a connection.
basic_socket_iostream();
Establish a connection to an endpoint corresponding to a resolver query.
template< typename T1, ... , typename TN> basic_socket_iostream( T1 t1, ... , TN tn);
This constructor automatically establishes a connection based on the supplied resolver query parameters. The arguments are used to construct a resolver query object.
Establish a connection to an endpoint corresponding to a resolver query.
template< typename T1, ... , typename TN> void connect( T1 t1, ... , TN tn);
This function automatically establishes a connection based on the supplied resolver query parameters. The arguments are used to construct a resolver query object.
typedef TimeTraits::duration_type duration_type;
Header: boost/asio/basic_socket_iostream.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_socket_iostream.hpp
Convenience header: boost/asio.hpp
Get the last error associated with the stream.
const boost::system::error_code & error() const;
An error_code
corresponding
to the last error from the stream.
To print the error associated with a failure to establish a connection:
tcp::iostream s("www.boost.org", "http"); if (!s) { std::cout << "Error: " << s.error().message() << std::endl; }
Get the stream's expiry time as an absolute time.
time_type expires_at() const; » more...
Set the stream's expiry time as an absolute time.
void expires_at( const time_type & expiry_time); » more...
Get the stream's expiry time as an absolute time.
time_type expires_at() const;
An absolute time value representing the stream's expiry time.
Set the stream's expiry time as an absolute time.
void expires_at( const time_type & expiry_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 boost::asio::error::operation_aborted
.
The expiry time to be used for the stream.
Get the timer's expiry time relative to now.
duration_type expires_from_now() const; » more...
Set the stream's expiry time relative to now.
void expires_from_now( const duration_type & expiry_time); » more...
Get the timer's expiry time relative to now.
duration_type expires_from_now() const;
A relative time value representing the stream's expiry time.
Set the stream's expiry time relative to now.
void expires_from_now( const duration_type & expiry_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 boost::asio::error::operation_aborted
.
The expiry time to be used for the timer.
Return a pointer to the underlying streambuf.
basic_socket_streambuf< Protocol, StreamSocketService, Time, TimeTraits, TimerService > * rdbuf() const;
typedef TimeTraits::time_type time_type;
Header: boost/asio/basic_socket_iostream.hpp
Convenience header: boost/asio.hpp
Iostream streambuf for a socket.
template< typename Protocol, typename StreamSocketService = stream_socket_service<Protocol>, typename Time = boost::posix_time::ptime, typename TimeTraits = boost::asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>> class basic_socket_streambuf : public basic_socket< Protocol, StreamSocketService >
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
The duration type. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
|
The time type. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_socket_streambuf without establishing a connection. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the connection. Close the socket. |
|
Establish a connection. Connect the socket to the specified endpoint. |
|
Get the stream buffer's expiry time as an absolute time. Set the stream buffer's expiry time as an absolute time. |
|
Get the stream buffer's expiry time relative to now. Set the stream buffer's expiry time relative to now. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Get the last error associated with the stream buffer. |
|
Get the remote endpoint of the socket. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
|
Destructor flushes buffered data. |
Name |
Description |
---|---|
Get the last error associated with the stream buffer. |
|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
|
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
Name |
Description |
---|---|
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket); » more... boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket);
Inherited from basic_socket.
Assign an existing native socket to the socket.
boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec);
Inherited from basic_socket.
Start an asynchronous connect.
template< typename ConnectHandler> void-or-deduced async_connect( const endpoint_type & peer_endpoint, ConnectHandler handler);
This function is used to asynchronously connect a socket to the specified remote endpoint. The function call always returns immediately.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected. Copies will be made of the endpoint object as required.
The handler to be called when the connection operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error // Result of operation );
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 boost::asio::io_service::post()
.
void connect_handler(const boost::system::error_code& error) { if (!error) { // Connect succeeded. } } ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.async_connect(endpoint, connect_handler);
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const; » more... bool at_mark( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
A bool indicating whether the socket is at the out-of-band data mark.
Thrown on failure.
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark( boost::system::error_code & ec) const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
Set to indicate what error occurred, if any.
A bool indicating whether the socket is at the out-of-band data mark.
Determine the number of bytes available for reading.
std::size_t available() const; » more... std::size_t available( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available() const;
This function is used to determine the number of bytes that may be read without blocking.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Thrown on failure.
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available( boost::system::error_code & ec) const;
This function is used to determine the number of bytes that may be read without blocking.
Set to indicate what error occurred, if any.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Construct a basic_socket_streambuf
without
establishing a connection.
basic_socket_streambuf();
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint); » more... boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345));
Inherited from basic_socket.
Bind the socket to the given local endpoint.
boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); boost::system::error_code ec; socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345), ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to permit sending of broadcast messages.
typedef implementation_defined broadcast;
Implements the SOL_SOCKET/SO_BROADCAST socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
IO control command to get the amount of data that can be read without blocking.
typedef implementation_defined bytes_readable;
Implements the FIONREAD IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::bytes_readable command(true); socket.io_control(command); std::size_t bytes_readable = command.get();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Cancel all asynchronous operations associated with the socket.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
void cancel();
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
basic_socket_streambuf< Protocol, StreamSocketService, Time, TimeTraits, TimerService > * close(); » more...
Close the socket.
boost::system::error_code close( boost::system::error_code & ec); » more...
Close the connection.
basic_socket_streambuf< Protocol, StreamSocketService, Time, TimeTraits, TimerService > * close();
this
if a connection was
successfully established, a null pointer otherwise.
Inherited from basic_socket.
Close the socket.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any. Note that, even if the function indicates an error, the underlying descriptor is closed.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.close(ec); if (ec) { // An error occurred. }
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
basic_socket_streambuf< Protocol, StreamSocketService, Time, TimeTraits, TimerService > * connect( const endpoint_type & endpoint); » more... template< typename T1, ... , typename TN> basic_socket_streambuf< Protocol, StreamSocketService > * connect( T1 t1, ... , TN tn); » more...
Connect the socket to the specified endpoint.
boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec); » more...
Establish a connection.
basic_socket_streambuf< Protocol, StreamSocketService, Time, TimeTraits, TimerService > * connect( const endpoint_type & endpoint);
This function establishes a connection to the specified endpoint.
this
if a connection was
successfully established, a null pointer otherwise.
Establish a connection.
template< typename T1, ... , typename TN> basic_socket_streambuf< Protocol, StreamSocketService > * connect( T1 t1, ... , TN tn);
This function automatically establishes a connection based on the supplied resolver query parameters. The arguments are used to construct a resolver query object.
this
if a connection was
successfully established, a null pointer otherwise.
Inherited from basic_socket.
Connect the socket to the specified endpoint.
boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); boost::system::error_code ec; socket.connect(endpoint, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to enable socket-level debugging.
typedef implementation_defined debug;
Implements the SOL_SOCKET/SO_DEBUG socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to prevent routing, use local interfaces only.
typedef implementation_defined do_not_route;
Implements the SOL_SOCKET/SO_DONTROUTE socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
typedef TimeTraits::duration_type duration_type;
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to report aborted connections on accept.
typedef implementation_defined enable_connection_aborted;
Implements a custom socket option that determines whether or not an accept
operation is permitted to fail with boost::asio::error::connection_aborted
.
By default the option is false.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Get the last error associated with the stream buffer.
virtual const boost::system::error_code & error() const;
An error_code
corresponding
to the last error from the stream buffer.
Get the stream buffer's expiry time as an absolute time.
time_type expires_at() const; » more...
Set the stream buffer's expiry time as an absolute time.
void expires_at( const time_type & expiry_time); » more...
Get the stream buffer's expiry time as an absolute time.
time_type expires_at() const;
An absolute time value representing the stream buffer's expiry time.
Set the stream buffer's expiry time as an absolute time.
void expires_at( const time_type & expiry_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 boost::asio::error::operation_aborted
.
The expiry time to be used for the stream.
Get the stream buffer's expiry time relative to now.
duration_type expires_from_now() const; » more...
Set the stream buffer's expiry time relative to now.
void expires_from_now( const duration_type & expiry_time); » more...
Get the stream buffer's expiry time relative to now.
duration_type expires_from_now() const;
A relative time value representing the stream buffer's expiry time.
Set the stream buffer's expiry time relative to now.
void expires_from_now( const duration_type & expiry_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 boost::asio::error::operation_aborted
.
The expiry time to be used for the timer.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get an option from the socket.
void get_option( GettableSocketOption & option) const; » more... boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Thrown on failure.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; socket.get_option(option); bool is_set = option.value();
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Set to indicate what error occurred, if any.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; boost::system::error_code ec; socket.get_option(option, ec); if (ec) { // An error occurred. } bool is_set = option.value();
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the socket.
void io_control( IoControlCommand & command); » more... boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> void io_control( IoControlCommand & command);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Thrown on failure.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; socket.io_control(command); std::size_t bytes_readable = command.get();
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Set to indicate what error occurred, if any.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; boost::system::error_code ec; socket.io_control(command, ec); if (ec) { // An error occurred. } std::size_t bytes_readable = command.get();
friend struct io_handler();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to send keep-alives.
typedef implementation_defined keep_alive;
Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to specify whether the socket lingers on close if unsent data is present.
typedef implementation_defined linger;
Implements the SOL_SOCKET/SO_LINGER socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option(true, 30); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option; socket.get_option(option); bool is_set = option.enabled(); unsigned short timeout = option.timeout();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Get the local endpoint of the socket.
endpoint_type local_endpoint() const; » more... endpoint_type local_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint() const;
This function is used to obtain the locally bound endpoint of the socket.
An object that represents the local endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint();
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the locally bound endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the local endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint(ec); if (ec) { // An error occurred. }
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Inherited from basic_socket.
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer();
This function returns a reference to the lowest layer in a stack of layers.
Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
This function returns a const reference to the lowest layer in a stack
of layers. Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A const reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
A basic_socket
is always the lowest
layer.
typedef basic_socket< Protocol, StreamSocketService > lowest_layer_type;
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_socket without opening it. Construct and open a basic_socket. Construct a basic_socket, opening it and binding it to the given local endpoint. Construct a basic_socket on an existing native socket. Move-construct a basic_socket from another. Move-construct a basic_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_socket from another. Move-assign a basic_socket from a socket of another protocol type. |
|
Get the remote endpoint of the socket. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
|
Protected destructor to prevent deletion through this type. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_socket
class template provides functionality that is common to both stream-oriented
and datagram-oriented sockets.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
The maximum length of the queue of pending incoming connections.
static const int max_connections = implementation_defined;
Inherited from socket_base.
Specify that the data should not be subject to routing.
static const int message_do_not_route = implementation_defined;
Inherited from socket_base.
Specifies that the data marks the end of a record.
static const int message_end_of_record = implementation_defined;
Inherited from socket_base.
Bitmask type for flags that can be passed to send and receive operations.
typedef int message_flags;
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
static const int message_out_of_band = implementation_defined;
Inherited from socket_base.
Peek at incoming data without removing it from the input queue.
static const int message_peek = implementation_defined;
Inherited from basic_socket.
(Deprecated: Use native_handle()
.) Get the native socket representation.
native_type native();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
Inherited from basic_socket.
Get the native socket representation.
native_handle_type native_handle();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
Inherited from basic_socket.
The native representation of a socket.
typedef StreamSocketService::native_handle_type native_handle_type;
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const; » more...
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode); » more... boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const;
This function is used to retrieve the non-blocking mode of the underlying native socket. This mode has no effect on the behaviour of the socket object's synchronous operations.
true
if the underlying socket
is in non-blocking mode and direct system calls may fail with boost::asio::error::would_block
(or the equivalent system
error).
The current non-blocking mode is cached by the socket object. Consequently, the return value may be incorrect if the non-blocking mode was set directly on the native socket.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Thrown on failure. If the mode
is false
, but the
current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Set to indicate what error occurred, if any. If the mode
is false
,
but the current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
(Deprecated: Use native_handle_type.) The native representation of a socket.
typedef StreamSocketService::native_handle_type native_type;
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the socket.
bool non_blocking() const; » more...
Sets the non-blocking mode of the socket.
void non_blocking( bool mode); » more... boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the socket.
bool non_blocking() const;
true
if the socket's synchronous
operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately. If
false
, synchronous operations
will block until complete.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
void non_blocking( bool mode);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Thrown on failure.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Set to indicate what error occurred, if any.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from socket_base.
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket.
typedef implementation_defined non_blocking_io;
Implements the FIONBIO IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::non_blocking_io command(true); socket.io_control(command);
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type()); » more... boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type());
This function opens the socket so that it will use the specified protocol.
An object specifying protocol parameters to be used.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4());
Inherited from basic_socket.
Open the socket using the specified protocol.
boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec);
This function opens the socket so that it will use the specified protocol.
An object specifying which protocol is to be used.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::system::error_code ec; socket.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
Inherited from basic_socket.
typedef Protocol protocol_type;
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Get the last error associated with the stream buffer.
const boost::system::error_code & puberror() const;
An error_code
corresponding
to the last error from the stream buffer.
Inherited from socket_base.
Socket option for the receive buffer size of a socket.
typedef implementation_defined receive_buffer_size;
Implements the SOL_SOCKET/SO_RCVBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the receive low watermark.
typedef implementation_defined receive_low_watermark;
Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const; » more... endpoint_type remote_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const;
This function is used to obtain the remote endpoint of the socket.
An object that represents the remote endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the remote endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the remote endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to allow the socket to be bound to an address that is already in use.
typedef implementation_defined reuse_address;
Implements the SOL_SOCKET/SO_REUSEADDR socket option.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send buffer size of a socket.
typedef implementation_defined send_buffer_size;
Implements the SOL_SOCKET/SO_SNDBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send low watermark.
typedef implementation_defined send_low_watermark;
Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef StreamSocketService service_type;
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
void set_option( const SettableSocketOption & option); » more... boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Thrown on failure.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); socket.set_option(option);
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Set to indicate what error occurred, if any.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); boost::system::error_code ec; socket.set_option(option, ec); if (ec) { // An error occurred. }
Disable sends or receives on the socket.
void shutdown( shutdown_type what); » more... boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Disable sends or receives on the socket.
void shutdown( shutdown_type what);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Thrown on failure.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send);
Inherited from basic_socket.
Disable sends or receives on the socket.
boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Set to indicate what error occurred, if any.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Different ways a socket may be shutdown.
enum shutdown_type
Shutdown the receive side of the socket.
Shutdown the send side of the socket.
Shutdown both send and receive on the socket.
typedef TimeTraits::time_type time_type;
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
friend struct timer_handler();
Header: boost/asio/basic_socket_streambuf.hpp
Convenience header: boost/asio.hpp
Provides stream-oriented socket functionality.
template< typename Protocol, typename StreamSocketService = stream_socket_service<Protocol>> class basic_stream_socket : public basic_socket< Protocol, StreamSocketService >
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Start an asynchronous read. |
|
Start an asynchronous receive. |
|
Start an asynchronous send. |
|
Start an asynchronous write. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_stream_socket without opening it. Construct and open a basic_stream_socket. Construct a basic_stream_socket, opening it and binding it to the given local endpoint. Construct a basic_stream_socket on an existing native socket. Move-construct a basic_stream_socket from another. Move-construct a basic_stream_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_stream_socket from another. Move-assign a basic_stream_socket from a socket of another protocol type. |
|
Read some data from the socket. |
|
Receive some data on the socket. Receive some data on a connected socket. |
|
Get the remote endpoint of the socket. |
|
Send some data on the socket. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
|
Write some data to the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_stream_socket
class template
provides asynchronous and blocking stream-oriented socket functionality.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket); » more... boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket);
Inherited from basic_socket.
Assign an existing native socket to the socket.
boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec);
Inherited from basic_socket.
Start an asynchronous connect.
template< typename ConnectHandler> void-or-deduced async_connect( const endpoint_type & peer_endpoint, ConnectHandler handler);
This function is used to asynchronously connect a socket to the specified remote endpoint. The function call always returns immediately.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected. Copies will be made of the endpoint object as required.
The handler to be called when the connection operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error // Result of operation );
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 boost::asio::io_service::post()
.
void connect_handler(const boost::system::error_code& error) { if (!error) { // Connect succeeded. } } ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.async_connect(endpoint, connect_handler);
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_read_some( const MutableBufferSequence & buffers, ReadHandler handler);
This function is used to asynchronously read data from the stream socket. The function call always returns immediately.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes read. );
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 boost::asio::io_service::post()
.
The read operation may not read all of the requested number of bytes. Consider
using the async_read
function if you need
to ensure that the requested amount of data is read before the asynchronous
operation completes.
To read into a single data buffer use the buffer
function as follows:
socket.async_read_some(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on reading into multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, ReadHandler handler); » more... template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, ReadHandler handler); » more...
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, ReadHandler handler);
This function is used to asynchronously receive data from the stream socket. The function call always returns immediately.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
The receive operation may not receive all of the requested number of
bytes. Consider using the async_read
function if you need
to ensure that the requested amount of data is received before the asynchronous
operation completes.
To receive into a single data buffer use the buffer
function as follows:
socket.async_receive(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, ReadHandler handler);
This function is used to asynchronously receive data from the stream socket. The function call always returns immediately.
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.
Flags specifying how the receive call is to be made.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
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 boost::asio::io_service::post()
.
The receive operation may not receive all of the requested number of
bytes. Consider using the async_read
function if you need
to ensure that the requested amount of data is received before the asynchronous
operation completes.
To receive into a single data buffer use the buffer
function as follows:
socket.async_receive(boost::asio::buffer(data, size), 0, handler);
See the 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 ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, WriteHandler handler); » more... template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, socket_base::message_flags flags, WriteHandler handler); » more...
Start an asynchronous send.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, WriteHandler handler);
This function is used to asynchronously send data on the stream socket. The function call always returns immediately.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
The send operation may not transmit all of the data to the peer. Consider
using the async_write
function if you
need to ensure that all data is written before the asynchronous operation
completes.
To send a single data buffer use the buffer
function as follows:
socket.async_send(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Start an asynchronous send.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, socket_base::message_flags flags, WriteHandler handler);
This function is used to asynchronously send data on the stream socket. The function call always returns immediately.
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.
Flags specifying how the send call is to be made.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
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 boost::asio::io_service::post()
.
The send operation may not transmit all of the data to the peer. Consider
using the async_write
function if you
need to ensure that all data is written before the asynchronous operation
completes.
To send a single data buffer use the buffer
function as follows:
socket.async_send(boost::asio::buffer(data, size), 0, handler);
See the 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> void-or-deduced async_write_some( const ConstBufferSequence & buffers, WriteHandler handler);
This function is used to asynchronously write data to the stream socket. The function call always returns immediately.
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.
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:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes written. );
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 boost::asio::io_service::post()
.
The write operation may not transmit all of the data to the peer. Consider
using the async_write
function if you need
to ensure that all data is written before the asynchronous operation completes.
To write a single data buffer use the buffer
function as follows:
socket.async_write_some(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on writing multiple buffers in one go, and
how to use it with arrays, boost::array or std::vector.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const; » more... bool at_mark( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
A bool indicating whether the socket is at the out-of-band data mark.
Thrown on failure.
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark( boost::system::error_code & ec) const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
Set to indicate what error occurred, if any.
A bool indicating whether the socket is at the out-of-band data mark.
Determine the number of bytes available for reading.
std::size_t available() const; » more... std::size_t available( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available() const;
This function is used to determine the number of bytes that may be read without blocking.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Thrown on failure.
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available( boost::system::error_code & ec) const;
This function is used to determine the number of bytes that may be read without blocking.
Set to indicate what error occurred, if any.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Construct a basic_stream_socket
without opening
it.
explicit basic_stream_socket( boost::asio::io_service & io_service); » more...
Construct and open a basic_stream_socket
.
basic_stream_socket( boost::asio::io_service & io_service, const protocol_type & protocol); » more...
Construct a basic_stream_socket
, opening it
and binding it to the given local endpoint.
basic_stream_socket( boost::asio::io_service & io_service, const endpoint_type & endpoint); » more...
Construct a basic_stream_socket
on an existing
native socket.
basic_stream_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket); » more...
Move-construct a basic_stream_socket
from another.
basic_stream_socket( basic_stream_socket && other); » more...
Move-construct a basic_stream_socket
from a socket
of another protocol type.
template< typename Protocol1, typename StreamSocketService1> basic_stream_socket( basic_stream_socket< Protocol1, StreamSocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0); » more...
Construct a basic_stream_socket
without
opening it.
basic_stream_socket( boost::asio::io_service & io_service);
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.
The io_service
object that
the stream socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
Construct and open a basic_stream_socket
.
basic_stream_socket( boost::asio::io_service & io_service, const protocol_type & protocol);
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.
The io_service
object that
the stream socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
An object specifying protocol parameters to be used.
Thrown on failure.
Construct a basic_stream_socket
, opening
it and binding it to the given local endpoint.
basic_stream_socket( boost::asio::io_service & io_service, const endpoint_type & 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.
The io_service
object that
the stream socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
An endpoint on the local machine to which the stream socket will be bound.
Thrown on failure.
Construct a basic_stream_socket
on an existing
native socket.
basic_stream_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket);
This constructor creates a stream socket object to hold an existing native socket.
The io_service
object that
the stream socket will use to dispatch handlers for any asynchronous
operations performed on the socket.
An object specifying protocol parameters to be used.
The new underlying socket implementation.
Thrown on failure.
Move-construct a basic_stream_socket
from another.
basic_stream_socket( basic_stream_socket && other);
This constructor moves a stream socket from one object to another.
The other basic_stream_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_stream_socket(io_service&) constructor
.
Move-construct a basic_stream_socket
from a socket
of another protocol type.
template< typename Protocol1, typename StreamSocketService1> basic_stream_socket( basic_stream_socket< Protocol1, StreamSocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0);
This constructor moves a stream socket from one object to another.
The other basic_stream_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_stream_socket(io_service&) constructor
.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint); » more... boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345));
Inherited from basic_socket.
Bind the socket to the given local endpoint.
boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); boost::system::error_code ec; socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345), ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to permit sending of broadcast messages.
typedef implementation_defined broadcast;
Implements the SOL_SOCKET/SO_BROADCAST socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
IO control command to get the amount of data that can be read without blocking.
typedef implementation_defined bytes_readable;
Implements the FIONREAD IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::bytes_readable command(true); socket.io_control(command); std::size_t bytes_readable = command.get();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Cancel all asynchronous operations associated with the socket.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
void cancel();
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
close()
function to simultaneously cancel the outstanding operations and
close the socket.
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Close the socket.
void close();
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Thrown on failure. Note that, even if the function indicates an error, the underlying descriptor is closed.
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Inherited from basic_socket.
Close the socket.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any. Note that, even if the function indicates an error, the underlying descriptor is closed.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.close(ec); if (ec) { // An error occurred. }
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint); » more... boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); socket.connect(endpoint);
Inherited from basic_socket.
Connect the socket to the specified endpoint.
boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec);
This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.
The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is not returned to the closed state.
The remote endpoint to which the socket will be connected.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("1.2.3.4"), 12345); boost::system::error_code ec; socket.connect(endpoint, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to enable socket-level debugging.
typedef implementation_defined debug;
Implements the SOL_SOCKET/SO_DEBUG socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to prevent routing, use local interfaces only.
typedef implementation_defined do_not_route;
Implements the SOL_SOCKET/SO_DONTROUTE socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to report aborted connections on accept.
typedef implementation_defined enable_connection_aborted;
Implements a custom socket option that determines whether or not an accept
operation is permitted to fail with boost::asio::error::connection_aborted
.
By default the option is false.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get an option from the socket.
void get_option( GettableSocketOption & option) const; » more... boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Thrown on failure.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; socket.get_option(option); bool is_set = option.value();
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Set to indicate what error occurred, if any.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; boost::system::error_code ec; socket.get_option(option, ec); if (ec) { // An error occurred. } bool is_set = option.value();
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the socket.
void io_control( IoControlCommand & command); » more... boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> void io_control( IoControlCommand & command);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Thrown on failure.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; socket.io_control(command); std::size_t bytes_readable = command.get();
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Set to indicate what error occurred, if any.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; boost::system::error_code ec; socket.io_control(command, ec); if (ec) { // An error occurred. } std::size_t bytes_readable = command.get();
Inherited from socket_base.
Socket option to send keep-alives.
typedef implementation_defined keep_alive;
Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to specify whether the socket lingers on close if unsent data is present.
typedef implementation_defined linger;
Implements the SOL_SOCKET/SO_LINGER socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option(true, 30); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option; socket.get_option(option); bool is_set = option.enabled(); unsigned short timeout = option.timeout();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Get the local endpoint of the socket.
endpoint_type local_endpoint() const; » more... endpoint_type local_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint() const;
This function is used to obtain the locally bound endpoint of the socket.
An object that represents the local endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint();
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the locally bound endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the local endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint(ec); if (ec) { // An error occurred. }
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Inherited from basic_socket.
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer();
This function returns a reference to the lowest layer in a stack of layers.
Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
This function returns a const reference to the lowest layer in a stack
of layers. Since a basic_socket
cannot contain
any further layers, it simply returns a reference to itself.
A const reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
A basic_socket
is always the lowest
layer.
typedef basic_socket< Protocol, StreamSocketService > lowest_layer_type;
Name |
Description |
---|---|
Socket option to permit sending of broadcast messages. |
|
IO control command to get the amount of data that can be read without blocking. |
|
Socket option to enable socket-level debugging. |
|
Socket option to prevent routing, use local interfaces only. |
|
Socket option to report aborted connections on accept. |
|
The endpoint type. |
|
The underlying implementation type of I/O object. |
|
Socket option to send keep-alives. |
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
A basic_socket is always the lowest layer. |
|
Bitmask type for flags that can be passed to send and receive operations. |
|
The native representation of a socket. |
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
The protocol type. |
|
Socket option for the receive buffer size of a socket. |
|
Socket option for the receive low watermark. |
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
Socket option for the send buffer size of a socket. |
|
Socket option for the send low watermark. |
|
The type of the service that will be used to provide I/O operations. |
|
Different ways a socket may be shutdown. |
Name |
Description |
---|---|
Assign an existing native socket to the socket. |
|
Start an asynchronous connect. |
|
Determine whether the socket is at the out-of-band data mark. |
|
Determine the number of bytes available for reading. |
|
Construct a basic_socket without opening it. Construct and open a basic_socket. Construct a basic_socket, opening it and binding it to the given local endpoint. Construct a basic_socket on an existing native socket. Move-construct a basic_socket from another. Move-construct a basic_socket from a socket of another protocol type. |
|
Bind the socket to the given local endpoint. |
|
Cancel all asynchronous operations associated with the socket. |
|
Close the socket. |
|
Connect the socket to the specified endpoint. |
|
Get the io_service associated with the object. |
|
Get an option from the socket. |
|
Perform an IO control command on the socket. |
|
Determine whether the socket is open. |
|
Get the local endpoint of the socket. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
Get the native socket representation. |
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
Open the socket using the specified protocol. |
|
Move-assign a basic_socket from another. Move-assign a basic_socket from a socket of another protocol type. |
|
Get the remote endpoint of the socket. |
|
Set an option on the socket. |
|
Disable sends or receives on the socket. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
|
Protected destructor to prevent deletion through this type. |
Name |
Description |
---|---|
The maximum length of the queue of pending incoming connections. |
|
Specify that the data should not be subject to routing. |
|
Specifies that the data marks the end of a record. |
|
Process out-of-band data. |
|
Peek at incoming data without removing it from the input queue. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_socket
class template provides functionality that is common to both stream-oriented
and datagram-oriented sockets.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
The maximum length of the queue of pending incoming connections.
static const int max_connections = implementation_defined;
Inherited from socket_base.
Specify that the data should not be subject to routing.
static const int message_do_not_route = implementation_defined;
Inherited from socket_base.
Specifies that the data marks the end of a record.
static const int message_end_of_record = implementation_defined;
Inherited from socket_base.
Bitmask type for flags that can be passed to send and receive operations.
typedef int message_flags;
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
static const int message_out_of_band = implementation_defined;
Inherited from socket_base.
Peek at incoming data without removing it from the input queue.
static const int message_peek = implementation_defined;
Inherited from basic_socket.
(Deprecated: Use native_handle()
.) Get the native socket representation.
native_type native();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
Inherited from basic_socket.
Get the native socket representation.
native_handle_type native_handle();
This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.
The native representation of a socket.
typedef StreamSocketService::native_handle_type native_handle_type;
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const; » more...
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode); » more... boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const;
This function is used to retrieve the non-blocking mode of the underlying native socket. This mode has no effect on the behaviour of the socket object's synchronous operations.
true
if the underlying socket
is in non-blocking mode and direct system calls may fail with boost::asio::error::would_block
(or the equivalent system
error).
The current non-blocking mode is cached by the socket object. Consequently, the return value may be incorrect if the non-blocking mode was set directly on the native socket.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Thrown on failure. If the mode
is false
, but the
current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec);
This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Set to indicate what error occurred, if any. If the mode
is false
,
but the current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
(Deprecated: Use native_handle_type.) The native representation of a socket.
typedef StreamSocketService::native_handle_type native_type;
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the socket.
bool non_blocking() const; » more...
Sets the non-blocking mode of the socket.
void non_blocking( bool mode); » more... boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the socket.
bool non_blocking() const;
true
if the socket's synchronous
operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately. If
false
, synchronous operations
will block until complete.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
void non_blocking( bool mode);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Thrown on failure.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Set to indicate what error occurred, if any.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from socket_base.
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket.
typedef implementation_defined non_blocking_io;
Implements the FIONBIO IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::non_blocking_io command(true); socket.io_control(command);
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type()); » more... boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type());
This function opens the socket so that it will use the specified protocol.
An object specifying protocol parameters to be used.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4());
Inherited from basic_socket.
Open the socket using the specified protocol.
boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec);
This function opens the socket so that it will use the specified protocol.
An object specifying which protocol is to be used.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::system::error_code ec; socket.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
Move-assign a basic_stream_socket
from another.
basic_stream_socket & operator=( basic_stream_socket && other); » more...
Move-assign a basic_stream_socket
from a socket
of another protocol type.
template< typename Protocol1, typename StreamSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_stream_socket >::type & operator=( basic_stream_socket< Protocol1, StreamSocketService1 > && other); » more...
Move-assign a basic_stream_socket
from another.
basic_stream_socket & operator=( basic_stream_socket && other);
This assignment operator moves a stream socket from one object to another.
The other basic_stream_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_stream_socket(io_service&) constructor
.
Move-assign a basic_stream_socket
from a socket
of another protocol type.
template< typename Protocol1, typename StreamSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_stream_socket >::type & operator=( basic_stream_socket< Protocol1, StreamSocketService1 > && other);
This assignment operator moves a stream socket from one object to another.
The other basic_stream_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_stream_socket(io_service&) constructor
.
typedef Protocol protocol_type;
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Read some data from the socket.
template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers); » more... template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers, boost::system::error_code & ec); » more...
Read some data from the socket.
template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers);
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.
One or more buffers into which the data will be read.
The number of bytes read.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
The read_some operation may not read all of the requested number of bytes.
Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
To read into a single data buffer use the buffer
function as follows:
socket.read_some(boost::asio::buffer(data, size));
See the buffer
documentation for information on reading into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Read some data from the socket.
template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers, boost::system::error_code & ec);
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.
One or more buffers into which the data will be read.
Set to indicate what error occurred, if any.
The number of bytes read. Returns 0 if an error occurred.
The read_some operation may not read all of the requested number of bytes.
Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
Receive some data on the socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers); » more... template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags); » more...
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Receive some data on the socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers);
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.
One or more buffers into which the data will be received.
The number of bytes received.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
The receive operation may not receive all of the requested number of
bytes. Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
To receive into a single data buffer use the buffer
function as follows:
socket.receive(boost::asio::buffer(data, size));
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Receive some data on the socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags);
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.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
The number of bytes received.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
The receive operation may not receive all of the requested number of
bytes. Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
To receive into a single data buffer use the buffer
function as follows:
socket.receive(boost::asio::buffer(data, size), 0);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec);
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.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
Set to indicate what error occurred, if any.
The number of bytes received. Returns 0 if an error occurred.
The receive operation may not receive all of the requested number of
bytes. Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
Inherited from socket_base.
Socket option for the receive buffer size of a socket.
typedef implementation_defined receive_buffer_size;
Implements the SOL_SOCKET/SO_RCVBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the receive low watermark.
typedef implementation_defined receive_low_watermark;
Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const; » more... endpoint_type remote_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const;
This function is used to obtain the remote endpoint of the socket.
An object that represents the remote endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the remote endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the remote endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to allow the socket to be bound to an address that is already in use.
typedef implementation_defined reuse_address;
Implements the SOL_SOCKET/SO_REUSEADDR socket option.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers); » more... template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags); » more... template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Send some data on the socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers);
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.
One or more data buffers to be sent on the socket.
The number of bytes sent.
Thrown on failure.
The send operation may not transmit all of the data to the peer. Consider
using the write
function if you need to ensure that all data is written before the blocking
operation completes.
To send a single data buffer use the buffer
function as follows:
socket.send(boost::asio::buffer(data, size));
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Send some data on the socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags);
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.
One or more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
The number of bytes sent.
Thrown on failure.
The send operation may not transmit all of the data to the peer. Consider
using the write
function if you need to ensure that all data is written before the blocking
operation completes.
To send a single data buffer use the buffer
function as follows:
socket.send(boost::asio::buffer(data, size), 0);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Send some data on the socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec);
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.
One or more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
Set to indicate what error occurred, if any.
The number of bytes sent. Returns 0 if an error occurred.
The send operation may not transmit all of the data to the peer. Consider
using the write
function if you need to ensure that all data is written before the blocking
operation completes.
Inherited from socket_base.
Socket option for the send buffer size of a socket.
typedef implementation_defined send_buffer_size;
Implements the SOL_SOCKET/SO_SNDBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send low watermark.
typedef implementation_defined send_low_watermark;
Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef StreamSocketService service_type;
Header: boost/asio/basic_stream_socket.hpp
Convenience header: boost/asio.hpp
void set_option( const SettableSocketOption & option); » more... boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Thrown on failure.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); socket.set_option(option);
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Set to indicate what error occurred, if any.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); boost::system::error_code ec; socket.set_option(option, ec); if (ec) { // An error occurred. }
Disable sends or receives on the socket.
void shutdown( shutdown_type what); » more... boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Disable sends or receives on the socket.
void shutdown( shutdown_type what);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Thrown on failure.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send);
Inherited from basic_socket.
Disable sends or receives on the socket.
boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Set to indicate what error occurred, if any.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Different ways a socket may be shutdown.
enum shutdown_type
Shutdown the receive side of the socket.
Shutdown the send side of the socket.
Shutdown both send and receive on the socket.
Write some data to the socket.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers); » more... template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers, boost::system::error_code & ec); » more...
Write some data to the socket.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers);
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.
One or more data buffers to be written to the socket.
The number of bytes written.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
The write_some operation may not transmit all of the data to the peer.
Consider using the write
function if you need to
ensure that all data is written before the blocking operation completes.
To write a single data buffer use the buffer
function as follows:
socket.write_some(boost::asio::buffer(data, size));
See the buffer
documentation for information on writing multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Write some data to the socket.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers, boost::system::error_code & ec);
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.
One or more data buffers to be written to the socket.
Set to indicate what error occurred, if any.
The number of bytes written. Returns 0 if an error occurred.
The write_some operation may not transmit all of the data to the peer.
Consider using the write
function if you need to
ensure that all data is written before the blocking operation completes.
Automatically resizable buffer class based on std::streambuf.
template< typename Allocator = std::allocator<char>> class basic_streambuf : noncopyable
Name |
Description |
---|---|
The type used to represent the input sequence as a list of buffers. |
|
The type used to represent the output sequence as a list of buffers. |
Name |
Description |
---|---|
Construct a basic_streambuf object. |
|
Move characters from the output sequence to the input sequence. |
|
Remove characters from the input sequence. |
|
Get a list of buffers that represents the input sequence. |
|
Get the maximum size of the basic_streambuf. |
|
Get a list of buffers that represents the output sequence, with the given size. |
|
Get the size of the input sequence. |
Name |
Description |
---|---|
Override std::streambuf behaviour. |
|
Override std::streambuf behaviour. |
The basic_streambuf
class
is derived from std::streambuf
to associate the streambuf's
input and output sequences with one or more character arrays. These character
arrays are internal to the 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 basic_streambuf
object are appended to the input sequence of the same object.
The basic_streambuf
class's
public interface is intended to permit the following implementation strategies:
The constructor for basic_streambuf
accepts a size_t
argument specifying the maximum
of the sum of the sizes of the input sequence and output sequence. During
the lifetime of the basic_streambuf
object, the following invariant holds:
size() <= max_size()
Any member function that would, if successful, cause the invariant to be
violated shall throw an exception of class std::length_error
.
The constructor for 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 basic_streambuf
object.
Writing directly from an streambuf to a socket:
boost::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
Reading from a socket directly into a streambuf:
boost::asio::streambuf b; // reserve 512 bytes in output sequence boost::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;
Header: boost/asio/basic_streambuf.hpp
Convenience header: boost/asio.hpp
Construct a basic_streambuf
object.
basic_streambuf( std::size_t maximum_size = (std::numeric_limits< std::size_t >::max)(), const Allocator & allocator = Allocator());
Constructs a streambuf with the specified maximum size. The initial size of the streambuf's input sequence is 0.
Move characters from the output sequence to the input sequence.
void commit( std::size_t n);
Appends n
characters from
the start of the output sequence to the input sequence. The beginning of
the output sequence is advanced by n
characters.
Requires a preceding call prepare(x)
where x >=
n
, and no intervening operations
that modify the input or output sequence.
If 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.
The type used to represent the input sequence as a list of buffers.
typedef implementation_defined const_buffers_type;
Header: boost/asio/basic_streambuf.hpp
Convenience header: boost/asio.hpp
Remove characters from the input sequence.
void consume( std::size_t n);
Removes n
characters from
the beginning of the input sequence.
If n
is greater than the
size of the input sequence, the entire input sequence is consumed and no
error is issued.
Get a list of buffers that represents the input sequence.
const_buffers_type data() const;
An object of type const_buffers_type
that satisfies ConstBufferSequence requirements, representing all character
arrays in the input sequence.
The returned object is invalidated by any basic_streambuf
member function that modifies the input sequence or output sequence.
Get the maximum size of the basic_streambuf
.
std::size_t max_size() const;
The allowed maximum of the sum of the sizes of the input sequence and output sequence.
The type used to represent the output sequence as a list of buffers.
typedef implementation_defined mutable_buffers_type;
Header: boost/asio/basic_streambuf.hpp
Convenience header: boost/asio.hpp
Override std::streambuf behaviour.
int_type overflow( int_type c);
Behaves according to the specification of std::streambuf::overflow()
, with the specialisation that std::length_error
is thrown if appending the
character to the input sequence would require the condition size() > max_size()
to be true.
Get a list of buffers that represents the output sequence, with the given size.
mutable_buffers_type prepare( std::size_t n);
Ensures that the output sequence can accommodate n
characters, reallocating character array objects as necessary.
An object of type 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 n
.
If size()
+ n
> max_size()
.
The returned object is invalidated by any basic_streambuf
member function that modifies the input sequence or output sequence.
Get the size of the input sequence.
std::size_t size() const;
The size of the input sequence. The value is equal to that calculated for
s
in the following 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); }
Provides waitable timer functionality.
template< typename Clock, typename WaitTraits = boost::asio::wait_traits<Clock>, typename WaitableTimerService = waitable_timer_service<Clock, WaitTraits>> class basic_waitable_timer : public basic_io_object< WaitableTimerService >
Name |
Description |
---|---|
The clock type. |
|
The duration type of the clock. |
|
The underlying implementation type of I/O object. |
|
The type of the service that will be used to provide I/O operations. |
|
The time point type of the clock. |
|
The wait traits type. |
Name |
Description |
---|---|
Start an asynchronous wait on the timer. |
|
Constructor. Constructor to set a particular expiry time as an absolute time. Constructor to set a particular expiry time relative to now. |
|
Cancel any asynchronous operations that are waiting on the timer. |
|
Cancels one asynchronous operation that is waiting on the timer. |
|
Get the timer's expiry time as an absolute time. Set the timer's expiry time as an absolute time. |
|
Get the timer's expiry time relative to now. Set the timer's expiry time relative to now. |
|
Get the io_service associated with the object. |
|
Perform a blocking wait on the timer. |
Name |
Description |
---|---|
Get the underlying implementation of the I/O object. |
|
Get the service associated with the I/O object. |
Name |
Description |
---|---|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
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 steady_timer
, system_timer
or high_resolution_timer
typedefs.
This waitable timer functionality is for use with the C++11 standard library's
<chrono>
facility, or with the Boost.Chrono library.
Distinct objects: Safe.
Shared objects: Unsafe.
Performing a blocking wait (C++11):
// Construct a timer without setting an expiry time. boost::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();
Performing an asynchronous wait (C++11):
void handler(const boost::system::error_code& error) { if (!error) { // Timer expired. } } ... // Construct a timer with an absolute expiry time. boost::asio::steady_timer timer(io_service, std::chrono::steady_clock::now() + std::chrono::seconds(60)); // Start an asynchronous wait. timer.async_wait(handler);
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:
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 boost::system::error_code& e) { if (e != boost::asio::error::operation_aborted) { // Timer was not cancelled, take necessary action. } }
boost::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.
boost::asio::error::operation_aborted
.
Header: boost/asio/basic_waitable_timer.hpp
Convenience header: boost/asio.hpp
Start an asynchronous wait on the timer.
template< typename WaitHandler> void-or-deduced async_wait( WaitHandler handler);
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:
boost::asio::error::operation_aborted
.
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:
void handler( const boost::system::error_code& error // Result of operation. );
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 boost::asio::io_service::post()
.
explicit basic_waitable_timer( boost::asio::io_service & io_service); » more...
Constructor to set a particular expiry time as an absolute time.
basic_waitable_timer( boost::asio::io_service & io_service, const time_point & expiry_time); » more...
Constructor to set a particular expiry time relative to now.
basic_waitable_timer( boost::asio::io_service & io_service, const duration & expiry_time); » more...
Constructor.
basic_waitable_timer( boost::asio::io_service & io_service);
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.
The io_service
object that
the timer will use to dispatch handlers for any asynchronous operations
performed on the timer.
Constructor to set a particular expiry time as an absolute time.
basic_waitable_timer( boost::asio::io_service & io_service, const time_point & expiry_time);
This constructor creates a timer and sets the expiry time.
The io_service
object that
the timer will use to dispatch handlers for any asynchronous operations
performed on the timer.
The expiry time to be used for the timer, expressed as an absolute time.
Constructor to set a particular expiry time relative to now.
basic_waitable_timer( boost::asio::io_service & io_service, const duration & expiry_time);
This constructor creates a timer and sets the expiry time.
The io_service
object that
the timer will use to dispatch handlers for any asynchronous operations
performed on the timer.
The expiry time to be used for the timer, relative to now.
Cancel any asynchronous operations that are waiting on the timer.
std::size_t cancel(); » more... std::size_t cancel( boost::system::error_code & ec); » more...
Cancel any asynchronous operations that are waiting on the timer.
std::size_t cancel();
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 boost::asio::error::operation_aborted
error code.
Cancelling the timer does not change the expiry time.
The number of asynchronous operations that were cancelled.
Thrown on failure.
If the timer has already expired when cancel()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Cancel any asynchronous operations that are waiting on the timer.
std::size_t cancel( boost::system::error_code & ec);
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 boost::asio::error::operation_aborted
error code.
Cancelling the timer does not change the expiry time.
Set to indicate what error occurred, if any.
The number of asynchronous operations that were cancelled.
If the timer has already expired when cancel()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Cancels one asynchronous operation that is waiting on the timer.
std::size_t cancel_one(); » more... std::size_t cancel_one( boost::system::error_code & ec); » more...
Cancels one asynchronous operation that is waiting on the timer.
std::size_t cancel_one();
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 boost::asio::error::operation_aborted
error code.
Cancelling the timer does not change the expiry time.
The number of asynchronous operations that were cancelled. That is, either 0 or 1.
Thrown on failure.
If the timer has already expired when cancel_one()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Cancels one asynchronous operation that is waiting on the timer.
std::size_t cancel_one( boost::system::error_code & ec);
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 boost::asio::error::operation_aborted
error code.
Cancelling the timer does not change the expiry time.
Set to indicate what error occurred, if any.
The number of asynchronous operations that were cancelled. That is, either 0 or 1.
If the timer has already expired when cancel_one()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
typedef Clock clock_type;
Header: boost/asio/basic_waitable_timer.hpp
Convenience header: boost/asio.hpp
The duration type of the clock.
typedef clock_type::duration duration;
Header: boost/asio/basic_waitable_timer.hpp
Convenience header: boost/asio.hpp
Get the timer's expiry time as an absolute time.
time_point expires_at() const; » more...
Set the timer's expiry time as an absolute time.
std::size_t expires_at( const time_point & expiry_time); » more... std::size_t expires_at( const time_point & expiry_time, boost::system::error_code & ec); » more...
Get the timer's expiry time as an absolute time.
time_point expires_at() const;
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.
Set the timer's expiry time as an absolute time.
std::size_t expires_at( const time_point & expiry_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 boost::asio::error::operation_aborted
error code.
The expiry time to be used for the timer.
The number of asynchronous operations that were cancelled.
Thrown on failure.
If the timer has already expired when expires_at()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Set the timer's expiry time as an absolute time.
std::size_t expires_at( const time_point & expiry_time, boost::system::error_code & ec);
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 boost::asio::error::operation_aborted
error code.
The expiry time to be used for the timer.
Set to indicate what error occurred, if any.
The number of asynchronous operations that were cancelled.
If the timer has already expired when expires_at()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Get the timer's expiry time relative to now.
duration expires_from_now() const; » more...
Set the timer's expiry time relative to now.
std::size_t expires_from_now( const duration & expiry_time); » more... std::size_t expires_from_now( const duration & expiry_time, boost::system::error_code & ec); » more...
Get the timer's expiry time relative to now.
duration expires_from_now() const;
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.
Set the timer's expiry time relative to now.
std::size_t expires_from_now( const duration & expiry_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 boost::asio::error::operation_aborted
error code.
The expiry time to be used for the timer.
The number of asynchronous operations that were cancelled.
Thrown on failure.
If the timer has already expired when expires_from_now()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Set the timer's expiry time relative to now.
std::size_t expires_from_now( const duration & expiry_time, boost::system::error_code & ec);
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 boost::asio::error::operation_aborted
error code.
The expiry time to be used for the timer.
Set to indicate what error occurred, if any.
The number of asynchronous operations that were cancelled.
If the timer has already expired when expires_from_now()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_waitable_timer.hpp
Convenience header: boost/asio.hpp
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef WaitableTimerService service_type;
Header: boost/asio/basic_waitable_timer.hpp
Convenience header: boost/asio.hpp
The time point type of the clock.
typedef clock_type::time_point time_point;
Header: boost/asio/basic_waitable_timer.hpp
Convenience header: boost/asio.hpp
typedef WaitTraits traits_type;
Header: boost/asio/basic_waitable_timer.hpp
Convenience header: boost/asio.hpp
Perform a blocking wait on the timer.
void wait(); » more... void wait( boost::system::error_code & ec); » more...
Perform a blocking wait on the timer.
void wait();
This function is used to wait for the timer to expire. This function blocks and does not return until the timer has expired.
Thrown on failure.
Perform a blocking wait on the timer.
void wait( boost::system::error_code & ec);
This function is used to wait for the timer to expire. This function blocks and does not return until the timer has expired.
Set to indicate what error occurred, if any.
Context object the represents the currently executing coroutine.
template< typename Handler> class basic_yield_context
Name |
Description |
---|---|
The coroutine callee type, used by the implementation. |
|
The coroutine caller type, used by the implementation. |
Name |
Description |
---|---|
Construct a yield context to represent the specified coroutine. |
|
Return a yield context that sets the specified error_code. |
The basic_yield_context
class is used
to represent the currently executing stackful coroutine. A basic_yield_context
may be passed
as a handler to an asynchronous operation. For example:
template <typename Handler> void my_coroutine(basic_yield_context<Handler> yield) { ... std::size_t n = my_socket.async_read_some(buffer, yield); ... }
The initiating function (async_read_some in the above example) suspends the current coroutine. The coroutine is resumed when the asynchronous operation completes, and the result of the operation is returned.
Header: boost/asio/spawn.hpp
Convenience header: None
Construct a yield context to represent the specified coroutine.
basic_yield_context( const detail::weak_ptr< callee_type > & coro, caller_type & ca, Handler & handler);
Most applications do not need to use this constructor. Instead, the spawn()
function passes a yield context as an argument to the coroutine function.
The coroutine callee type, used by the implementation.
typedef implementation_defined callee_type;
When using Boost.Coroutine v1, this type is:
typename coroutine<void()>
When using Boost.Coroutine v2 (unidirectional coroutines), this type is:
push_coroutine<void>
Header: boost/asio/spawn.hpp
Convenience header: None
The coroutine caller type, used by the implementation.
typedef implementation_defined caller_type;
When using Boost.Coroutine v1, this type is:
typename coroutine<void()>::caller_type
When using Boost.Coroutine v2 (unidirectional coroutines), this type is:
pull_coroutine<void>
Header: boost/asio/spawn.hpp
Convenience header: None
Return a yield context that sets the specified error_code.
basic_yield_context operator[]( boost::system::error_code & ec) const;
By default, when a yield context is used with an asynchronous operation, a non-success error_code is converted to system_error and thrown. This operator may be used to specify an error_code object that should instead be set with the asynchronous operation's result. For example:
template <typename Handler> void my_coroutine(basic_yield_context<Handler> yield) { ... std::size_t n = my_socket.async_read_some(buffer, yield[ec]); if (ec) { // An error occurred. } ... }
The boost::asio::buffer
function is used to create a buffer
object to represent raw memory, an array of POD elements, a vector of POD
elements, or a std::string.
mutable_buffers_1 buffer( const mutable_buffer & b); » more... mutable_buffers_1 buffer( const mutable_buffer & b, std::size_t max_size_in_bytes); » more... const_buffers_1 buffer( const const_buffer & b); » more... const_buffers_1 buffer( const const_buffer & b, std::size_t max_size_in_bytes); » more... mutable_buffers_1 buffer( void * data, std::size_t size_in_bytes); » more... const_buffers_1 buffer( const void * data, std::size_t size_in_bytes); » more... template< typename PodType, std::size_t N> mutable_buffers_1 buffer( PodType (&data)[N]); » more... template< typename PodType, std::size_t N> mutable_buffers_1 buffer( PodType (&data)[N], std::size_t max_size_in_bytes); » more... template< typename PodType, std::size_t N> const_buffers_1 buffer( const PodType (&data)[N]); » more... template< typename PodType, std::size_t N> const_buffers_1 buffer( const PodType (&data)[N], std::size_t max_size_in_bytes); » more... template< typename PodType, std::size_t N> mutable_buffers_1 buffer( boost::array< PodType, N > & data); » more... template< typename PodType, std::size_t N> mutable_buffers_1 buffer( boost::array< PodType, N > & data, std::size_t max_size_in_bytes); » more... template< typename PodType, std::size_t N> const_buffers_1 buffer( boost::array< const PodType, N > & data); » more... template< typename PodType, std::size_t N> const_buffers_1 buffer( boost::array< const PodType, N > & data, std::size_t max_size_in_bytes); » more... template< typename PodType, std::size_t N> const_buffers_1 buffer( const boost::array< PodType, N > & data); » more... template< typename PodType, std::size_t N> const_buffers_1 buffer( const boost::array< PodType, N > & data, std::size_t max_size_in_bytes); » more... template< typename PodType, std::size_t N> mutable_buffers_1 buffer( std::array< PodType, N > & data); » more... template< typename PodType, std::size_t N> mutable_buffers_1 buffer( std::array< PodType, N > & data, std::size_t max_size_in_bytes); » more... template< typename PodType, std::size_t N> const_buffers_1 buffer( std::array< const PodType, N > & data); » more... template< typename PodType, std::size_t N> const_buffers_1 buffer( std::array< const PodType, N > & data, std::size_t max_size_in_bytes); » more... template< typename PodType, std::size_t N> const_buffers_1 buffer( const std::array< PodType, N > & data); » more... template< typename PodType, std::size_t N> const_buffers_1 buffer( const std::array< PodType, N > & data, std::size_t max_size_in_bytes); » more... template< typename PodType, typename Allocator> mutable_buffers_1 buffer( std::vector< PodType, Allocator > & data); » more... template< typename PodType, typename Allocator> mutable_buffers_1 buffer( std::vector< PodType, Allocator > & data, std::size_t max_size_in_bytes); » more... template< typename PodType, typename Allocator> const_buffers_1 buffer( const std::vector< PodType, Allocator > & data); » more... template< typename PodType, typename Allocator> const_buffers_1 buffer( const std::vector< PodType, Allocator > & data, std::size_t max_size_in_bytes); » more... template< typename Elem, typename Traits, typename Allocator> const_buffers_1 buffer( const std::basic_string< Elem, Traits, Allocator > & data); » more... template< typename Elem, typename Traits, typename Allocator> const_buffers_1 buffer( const std::basic_string< Elem, Traits, Allocator > & data, std::size_t max_size_in_bytes); » more...
A buffer object represents a contiguous region of memory as a 2-tuple consisting
of a pointer and size in bytes. A tuple of the form {void*, size_t}
specifies a mutable (modifiable) region
of memory. Similarly, a tuple of the form {const void*, size_t}
specifies a const (non-modifiable) region
of memory. These two forms correspond to the classes mutable_buffer
and const_buffer
, respectively. To mirror
C++'s conversion rules, a mutable_buffer
is implicitly convertible
to a const_buffer
,
and the opposite conversion is not permitted.
The simplest use case involves reading or writing a single buffer of a specified size:
sock.send(boost::asio::buffer(data, size));
In the above example, the return value of boost::asio::buffer
meets the requirements of the ConstBufferSequence concept so that it may
be directly passed to the socket's write function. A buffer created for modifiable
memory also meets the requirements of the MutableBufferSequence concept.
An individual buffer may be created from a builtin array, std::vector, std::array or boost::array of POD elements. This helps prevent buffer overruns by automatically determining the size of the buffer:
char d1[128]; size_t bytes_transferred = sock.receive(boost::asio::buffer(d1)); std::vector<char> d2(128); bytes_transferred = sock.receive(boost::asio::buffer(d2)); std::array<char, 128> d3; bytes_transferred = sock.receive(boost::asio::buffer(d3)); boost::array<char, 128> d4; bytes_transferred = sock.receive(boost::asio::buffer(d4));
In all three cases above, the buffers created are exactly 128 bytes long.
Note that a vector is never automatically resized when
creating or using a buffer. The buffer size is determined using the vector's
size()
member function, and not its capacity.
The contents of a buffer may be accessed using the buffer_size
and buffer_cast
functions:
boost::asio::mutable_buffer b1 = ...; std::size_t s1 = boost::asio::buffer_size(b1); unsigned char* p1 = boost::asio::buffer_cast<unsigned char*>(b1); boost::asio::const_buffer b2 = ...; std::size_t s2 = boost::asio::buffer_size(b2); const void* p2 = boost::asio::buffer_cast<const void*>(b2);
The boost::asio::buffer_cast
function permits violations
of type safety, so uses of it in application code should be carefully considered.
For convenience, the buffer_size
function also works
on buffer sequences (that is, types meeting the ConstBufferSequence or MutableBufferSequence
type requirements). In this case, the function returns the total size of
all buffers in the sequence.
The buffer_copy
function may be used to copy raw bytes between individual buffers and buffer
sequences.
In particular, when used with the buffer_size
, the buffer_copy
function can be used
to linearise a sequence of buffers. For example:
vector<const_buffer> buffers = ...; vector<unsigned char> data(boost::asio::buffer_size(buffers)); boost::asio::buffer_copy(boost::asio::buffer(data), buffers);
Note that buffer_copy
is implemented in terms
of memcpy
, and consequently
it cannot be used to copy between overlapping memory regions.
A buffer object does not have any ownership of the memory it refers to. It is the responsibility of the application to ensure the memory region remains valid until it is no longer required for an I/O operation. When the memory is no longer available, the buffer is said to have been invalidated.
For the boost::asio::buffer
overloads that accept an argument
of type std::vector, the buffer objects returned are invalidated by any vector
operation that also invalidates all references, pointers and iterators referring
to the elements in the sequence (C++ Std, 23.2.4)
For the boost::asio::buffer
overloads that accept an argument
of type std::basic_string, the buffer objects returned are invalidated according
to the rules defined for invalidation of references, pointers and iterators
referring to elements of the sequence (C++ Std, 21.3).
Buffer objects may be manipulated using simple arithmetic in a safe way which helps prevent buffer overruns. Consider an array initialised as follows:
boost::array<char, 6> a = { 'a', 'b', 'c', 'd', 'e' };
A buffer object b1
created
using:
b1 = boost::asio::buffer(a);
represents the entire array, { 'a', 'b', 'c',
'd', 'e' }
. An optional
second argument to the boost::asio::buffer
function may be used to limit the size, in bytes, of the buffer:
b2 = boost::asio::buffer(a, 3);
such that b2
represents the
data { 'a', 'b',
'c' }
.
Even if the size argument exceeds the actual size of the array, the size
of the buffer object created will be limited to the array size.
An offset may be applied to an existing buffer to create a new one:
b3 = b1 + 2;
where b3
will set to represent
{ 'c', 'd',
'e' }
.
If the offset exceeds the size of the existing buffer, the newly created
buffer will be empty.
Both an offset and size may be specified to create a buffer that corresponds to a specific range of bytes within an existing buffer:
b4 = boost::asio::buffer(b1 + 1, 3);
so that b4
will refer to
the bytes { 'b', 'c',
'd' }
.
To read or write using multiple buffers (i.e. scatter-gather I/O), multiple buffer objects may be assigned into a container that supports the MutableBufferSequence (for read) or ConstBufferSequence (for write) concepts:
char d1[128]; std::vector<char> d2(128); boost::array<char, 128> d3; boost::array<mutable_buffer, 3> bufs1 = { boost::asio::buffer(d1), boost::asio::buffer(d2), boost::asio::buffer(d3) }; bytes_transferred = sock.receive(bufs1); std::vector<const_buffer> bufs2; bufs2.push_back(boost::asio::buffer(d1)); bufs2.push_back(boost::asio::buffer(d2)); bufs2.push_back(boost::asio::buffer(d3)); bytes_transferred = sock.send(bufs2);
Header: boost/asio/buffer.hpp
Convenience header: boost/asio.hpp
Create a new modifiable buffer from an existing buffer.
mutable_buffers_1 buffer( const mutable_buffer & b);
mutable_buffers_1(b)
.
Create a new modifiable buffer from an existing buffer.
mutable_buffers_1 buffer( const mutable_buffer & b, std::size_t max_size_in_bytes);
A mutable_buffers_1
value equivalent
to:
mutable_buffers_1( buffer_cast<void*>(b), min(buffer_size(b), max_size_in_bytes));
Create a new non-modifiable buffer from an existing buffer.
const_buffers_1 buffer( const const_buffer & b);
const_buffers_1(b)
.
Create a new non-modifiable buffer from an existing buffer.
const_buffers_1 buffer( const const_buffer & b, std::size_t max_size_in_bytes);
A const_buffers_1
value equivalent to:
const_buffers_1( buffer_cast<const void*>(b), min(buffer_size(b), max_size_in_bytes));
Create a new modifiable buffer that represents the given memory range.
mutable_buffers_1 buffer( void * data, std::size_t size_in_bytes);
mutable_buffers_1(data, size_in_bytes)
.
Create a new non-modifiable buffer that represents the given memory range.
const_buffers_1 buffer( const void * data, std::size_t size_in_bytes);
const_buffers_1(data, size_in_bytes)
.
Create a new modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> mutable_buffers_1 buffer( PodType (&data)[N]);
A mutable_buffers_1
value equivalent
to:
mutable_buffers_1( static_cast<void*>(data), N * sizeof(PodType));
Create a new modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> mutable_buffers_1 buffer( PodType (&data)[N], std::size_t max_size_in_bytes);
A mutable_buffers_1
value equivalent
to:
mutable_buffers_1( static_cast<void*>(data), min(N * sizeof(PodType), max_size_in_bytes));
Create a new non-modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> const_buffers_1 buffer( const PodType (&data)[N]);
A const_buffers_1
value equivalent to:
const_buffers_1( static_cast<const void*>(data), N * sizeof(PodType));
Create a new non-modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> const_buffers_1 buffer( const PodType (&data)[N], std::size_t max_size_in_bytes);
A const_buffers_1
value equivalent to:
const_buffers_1( static_cast<const void*>(data), min(N * sizeof(PodType), max_size_in_bytes));
Create a new modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> mutable_buffers_1 buffer( boost::array< PodType, N > & data);
A mutable_buffers_1
value equivalent
to:
mutable_buffers_1( data.data(), data.size() * sizeof(PodType));
Create a new modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> mutable_buffers_1 buffer( boost::array< PodType, N > & data, std::size_t max_size_in_bytes);
A mutable_buffers_1
value equivalent
to:
mutable_buffers_1( data.data(), min(data.size() * sizeof(PodType), max_size_in_bytes));
Create a new non-modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> const_buffers_1 buffer( boost::array< const PodType, N > & data);
A const_buffers_1
value equivalent to:
const_buffers_1( data.data(), data.size() * sizeof(PodType));
Create a new non-modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> const_buffers_1 buffer( boost::array< const PodType, N > & data, std::size_t max_size_in_bytes);
A const_buffers_1
value equivalent to:
const_buffers_1( data.data(), min(data.size() * sizeof(PodType), max_size_in_bytes));
Create a new non-modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> const_buffers_1 buffer( const boost::array< PodType, N > & data);
A const_buffers_1
value equivalent to:
const_buffers_1( data.data(), data.size() * sizeof(PodType));
Create a new non-modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> const_buffers_1 buffer( const boost::array< PodType, N > & data, std::size_t max_size_in_bytes);
A const_buffers_1
value equivalent to:
const_buffers_1( data.data(), min(data.size() * sizeof(PodType), max_size_in_bytes));
Create a new modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> mutable_buffers_1 buffer( std::array< PodType, N > & data);
A mutable_buffers_1
value equivalent
to:
mutable_buffers_1( data.data(), data.size() * sizeof(PodType));
Create a new modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> mutable_buffers_1 buffer( std::array< PodType, N > & data, std::size_t max_size_in_bytes);
A mutable_buffers_1
value equivalent
to:
mutable_buffers_1( data.data(), min(data.size() * sizeof(PodType), max_size_in_bytes));
Create a new non-modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> const_buffers_1 buffer( std::array< const PodType, N > & data);
A const_buffers_1
value equivalent to:
const_buffers_1( data.data(), data.size() * sizeof(PodType));
Create a new non-modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> const_buffers_1 buffer( std::array< const PodType, N > & data, std::size_t max_size_in_bytes);
A const_buffers_1
value equivalent to:
const_buffers_1( data.data(), min(data.size() * sizeof(PodType), max_size_in_bytes));
Create a new non-modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> const_buffers_1 buffer( const std::array< PodType, N > & data);
A const_buffers_1
value equivalent to:
const_buffers_1( data.data(), data.size() * sizeof(PodType));
Create a new non-modifiable buffer that represents the given POD array.
template< typename PodType, std::size_t N> const_buffers_1 buffer( const std::array< PodType, N > & data, std::size_t max_size_in_bytes);
A const_buffers_1
value equivalent to:
const_buffers_1( data.data(), min(data.size() * sizeof(PodType), max_size_in_bytes));
Create a new modifiable buffer that represents the given POD vector.
template< typename PodType, typename Allocator> mutable_buffers_1 buffer( std::vector< PodType, Allocator > & data);
A mutable_buffers_1
value equivalent
to:
mutable_buffers_1( data.size() ? &data[0] : 0, data.size() * sizeof(PodType));
The buffer is invalidated by any vector operation that would also invalidate iterators.
Create a new modifiable buffer that represents the given POD vector.
template< typename PodType, typename Allocator> mutable_buffers_1 buffer( std::vector< PodType, Allocator > & data, std::size_t max_size_in_bytes);
A mutable_buffers_1
value equivalent
to:
mutable_buffers_1( data.size() ? &data[0] : 0, min(data.size() * sizeof(PodType), max_size_in_bytes));
The buffer is invalidated by any vector operation that would also invalidate iterators.
Create a new non-modifiable buffer that represents the given POD vector.
template< typename PodType, typename Allocator> const_buffers_1 buffer( const std::vector< PodType, Allocator > & data);
A const_buffers_1
value equivalent to:
const_buffers_1( data.size() ? &data[0] : 0, data.size() * sizeof(PodType));
The buffer is invalidated by any vector operation that would also invalidate iterators.
Create a new non-modifiable buffer that represents the given POD vector.
template< typename PodType, typename Allocator> const_buffers_1 buffer( const std::vector< PodType, Allocator > & data, std::size_t max_size_in_bytes);
A const_buffers_1
value equivalent to:
const_buffers_1( data.size() ? &data[0] : 0, min(data.size() * sizeof(PodType), max_size_in_bytes));
The buffer is invalidated by any vector operation that would also invalidate iterators.
Create a new non-modifiable buffer that represents the given string.
template< typename Elem, typename Traits, typename Allocator> const_buffers_1 buffer( const std::basic_string< Elem, Traits, Allocator > & data);
const_buffers_1(data.data(), data.size() * sizeof(Elem))
.
The buffer is invalidated by any non-const operation called on the given string object.
Create a new non-modifiable buffer that represents the given string.
template< typename Elem, typename Traits, typename Allocator> const_buffers_1 buffer( const std::basic_string< Elem, Traits, Allocator > & data, std::size_t max_size_in_bytes);
A const_buffers_1
value equivalent to:
const_buffers_1( data.data(), min(data.size() * sizeof(Elem), max_size_in_bytes));
The buffer is invalidated by any non-const operation called on the given string object.
The boost::asio::buffer_cast
function is used to obtain
a pointer to the underlying memory region associated with a buffer.
template< typename PointerToPodType> PointerToPodType buffer_cast( const mutable_buffer & b); » more... template< typename PointerToPodType> PointerToPodType buffer_cast( const const_buffer & b); » more...
To access the memory of a non-modifiable buffer, use:
boost::asio::const_buffer b1 = ...; const unsigned char* p1 = boost::asio::buffer_cast<const unsigned char*>(b1);
To access the memory of a modifiable buffer, use:
boost::asio::mutable_buffer b2 = ...; unsigned char* p2 = boost::asio::buffer_cast<unsigned char*>(b2);
The boost::asio::buffer_cast
function permits violations
of type safety, so uses of it in application code should be carefully considered.
Header: boost/asio/buffer.hpp
Convenience header: boost/asio.hpp
Cast a non-modifiable buffer to a specified pointer to POD type.
template< typename PointerToPodType> PointerToPodType buffer_cast( const mutable_buffer & b);
Cast a non-modifiable buffer to a specified pointer to POD type.
template< typename PointerToPodType> PointerToPodType buffer_cast( const const_buffer & b);
The boost::asio::buffer_copy
function is used to copy bytes
from a source buffer (or buffer sequence) to a target buffer (or buffer sequence).
std::size_t buffer_copy( const mutable_buffer & target, const const_buffer & source); » more... std::size_t buffer_copy( const mutable_buffer & target, const const_buffers_1 & source); » more... std::size_t buffer_copy( const mutable_buffer & target, const mutable_buffer & source); » more... std::size_t buffer_copy( const mutable_buffer & target, const mutable_buffers_1 & source); » more... template< typename ConstBufferSequence> std::size_t buffer_copy( const mutable_buffer & target, const ConstBufferSequence & source); » more... std::size_t buffer_copy( const mutable_buffers_1 & target, const const_buffer & source); » more... std::size_t buffer_copy( const mutable_buffers_1 & target, const const_buffers_1 & source); » more... std::size_t buffer_copy( const mutable_buffers_1 & target, const mutable_buffer & source); » more... std::size_t buffer_copy( const mutable_buffers_1 & target, const mutable_buffers_1 & source); » more... template< typename ConstBufferSequence> std::size_t buffer_copy( const mutable_buffers_1 & target, const ConstBufferSequence & source); » more... template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const const_buffer & source); » more... template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const const_buffers_1 & source); » more... template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const mutable_buffer & source); » more... template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const mutable_buffers_1 & source); » more... template< typename MutableBufferSequence, typename ConstBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const ConstBufferSequence & source); » more... std::size_t buffer_copy( const mutable_buffer & target, const const_buffer & source, std::size_t max_bytes_to_copy); » more... std::size_t buffer_copy( const mutable_buffer & target, const const_buffers_1 & source, std::size_t max_bytes_to_copy); » more... std::size_t buffer_copy( const mutable_buffer & target, const mutable_buffer & source, std::size_t max_bytes_to_copy); » more... std::size_t buffer_copy( const mutable_buffer & target, const mutable_buffers_1 & source, std::size_t max_bytes_to_copy); » more... template< typename ConstBufferSequence> std::size_t buffer_copy( const mutable_buffer & target, const ConstBufferSequence & source, std::size_t max_bytes_to_copy); » more... std::size_t buffer_copy( const mutable_buffers_1 & target, const const_buffer & source, std::size_t max_bytes_to_copy); » more... std::size_t buffer_copy( const mutable_buffers_1 & target, const const_buffers_1 & source, std::size_t max_bytes_to_copy); » more... std::size_t buffer_copy( const mutable_buffers_1 & target, const mutable_buffer & source, std::size_t max_bytes_to_copy); » more... std::size_t buffer_copy( const mutable_buffers_1 & target, const mutable_buffers_1 & source, std::size_t max_bytes_to_copy); » more... template< typename ConstBufferSequence> std::size_t buffer_copy( const mutable_buffers_1 & target, const ConstBufferSequence & source, std::size_t max_bytes_to_copy); » more... template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const const_buffer & source, std::size_t max_bytes_to_copy); » more... template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const const_buffers_1 & source, std::size_t max_bytes_to_copy); » more... template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const mutable_buffer & source, std::size_t max_bytes_to_copy); » more... template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const mutable_buffers_1 & source, std::size_t max_bytes_to_copy); » more... template< typename MutableBufferSequence, typename ConstBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const ConstBufferSequence & source, std::size_t max_bytes_to_copy); » more...
The buffer_copy
function
is available in two forms:
buffer_copy(target, source)
buffer_copy(target, source, max_bytes_to_copy)
Both forms return the number of bytes actually copied. The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
If
specified, max_bytes_to_copy
.
This prevents buffer overflow, regardless of the buffer sizes used in the copy operation.
Note that buffer_copy
is implemented in terms
of memcpy
, and consequently
it cannot be used to copy between overlapping memory regions.
Header: boost/asio/buffer.hpp
Convenience header: boost/asio.hpp
Copies bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffer & target, const const_buffer & source);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffer & target, const const_buffers_1 & source);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffer & target, const mutable_buffer & source);
A modifiable buffer representing the memory region to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffer & target, const mutable_buffers_1 & source);
A modifiable buffer representing the memory region to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer sequence to a target buffer.
template< typename ConstBufferSequence> std::size_t buffer_copy( const mutable_buffer & target, const ConstBufferSequence & source);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer sequence representing the memory regions from which the bytes will be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffers_1 & target, const const_buffer & source);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffers_1 & target, const const_buffers_1 & source);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffers_1 & target, const mutable_buffer & source);
A modifiable buffer representing the memory region to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffers_1 & target, const mutable_buffers_1 & source);
A modifiable buffer representing the memory region to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer sequence to a target buffer.
template< typename ConstBufferSequence> std::size_t buffer_copy( const mutable_buffers_1 & target, const ConstBufferSequence & source);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer sequence representing the memory regions from which the bytes will be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer sequence.
template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const const_buffer & source);
A modifiable buffer sequence representing the memory regions to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer sequence.
template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const const_buffers_1 & source);
A modifiable buffer sequence representing the memory regions to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer sequence.
template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const mutable_buffer & source);
A modifiable buffer sequence representing the memory regions to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer to a target buffer sequence.
template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const mutable_buffers_1 & source);
A modifiable buffer sequence representing the memory regions to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies bytes from a source buffer sequence to a target buffer sequence.
template< typename MutableBufferSequence, typename ConstBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const ConstBufferSequence & source);
A modifiable buffer sequence representing the memory regions to which the bytes will be copied.
A non-modifiable buffer sequence representing the memory regions from which the bytes will be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffer & target, const const_buffer & source, std::size_t max_bytes_to_copy);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffer & target, const const_buffers_1 & source, std::size_t max_bytes_to_copy);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffer & target, const mutable_buffer & source, std::size_t max_bytes_to_copy);
A modifiable buffer representing the memory region to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffer & target, const mutable_buffers_1 & source, std::size_t max_bytes_to_copy);
A modifiable buffer representing the memory region to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer sequence to a target buffer.
template< typename ConstBufferSequence> std::size_t buffer_copy( const mutable_buffer & target, const ConstBufferSequence & source, std::size_t max_bytes_to_copy);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer sequence representing the memory regions from which the bytes will be copied.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffers_1 & target, const const_buffer & source, std::size_t max_bytes_to_copy);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffers_1 & target, const const_buffers_1 & source, std::size_t max_bytes_to_copy);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffers_1 & target, const mutable_buffer & source, std::size_t max_bytes_to_copy);
A modifiable buffer representing the memory region to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer.
std::size_t buffer_copy( const mutable_buffers_1 & target, const mutable_buffers_1 & source, std::size_t max_bytes_to_copy);
A modifiable buffer representing the memory region to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer sequence to a target buffer.
template< typename ConstBufferSequence> std::size_t buffer_copy( const mutable_buffers_1 & target, const ConstBufferSequence & source, std::size_t max_bytes_to_copy);
A modifiable buffer representing the memory region to which the bytes will be copied.
A non-modifiable buffer sequence representing the memory regions from which the bytes will be copied.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer sequence.
template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const const_buffer & source, std::size_t max_bytes_to_copy);
A modifiable buffer sequence representing the memory regions to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer sequence.
template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const const_buffers_1 & source, std::size_t max_bytes_to_copy);
A modifiable buffer sequence representing the memory regions to which the bytes will be copied.
A non-modifiable buffer representing the memory region from which the bytes will be copied.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer sequence.
template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const mutable_buffer & source, std::size_t max_bytes_to_copy);
A modifiable buffer sequence representing the memory regions to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer to a target buffer sequence.
template< typename MutableBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const mutable_buffers_1 & source, std::size_t max_bytes_to_copy);
A modifiable buffer sequence representing the memory regions to which the bytes will be copied.
A modifiable buffer representing the memory region from which the bytes will be copied. The contents of the source buffer will not be modified.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
Copies a limited number of bytes from a source buffer sequence to a target buffer sequence.
template< typename MutableBufferSequence, typename ConstBufferSequence> std::size_t buffer_copy( const MutableBufferSequence & target, const ConstBufferSequence & source, std::size_t max_bytes_to_copy);
A modifiable buffer sequence representing the memory regions to which the bytes will be copied.
A non-modifiable buffer sequence representing the memory regions from which the bytes will be copied.
The maximum number of bytes to be copied.
The number of bytes copied.
The number of bytes copied is the lesser of:
buffer_size(target)
buffer_size(source)
max_bytes_to_copy
This function is implemented in terms of memcpy
,
and consequently it cannot be used to copy between overlapping memory regions.
The boost::asio::buffer_size
function determines the total
number of bytes in a buffer or buffer sequence.
std::size_t buffer_size( const mutable_buffer & b); » more... std::size_t buffer_size( const mutable_buffers_1 & b); » more... std::size_t buffer_size( const const_buffer & b); » more... std::size_t buffer_size( const const_buffers_1 & b); » more... template< typename BufferSequence> std::size_t buffer_size( const BufferSequence & b); » more...
Header: boost/asio/buffer.hpp
Convenience header: boost/asio.hpp
Get the number of bytes in a modifiable buffer.
std::size_t buffer_size( const mutable_buffer & b);
Get the number of bytes in a modifiable buffer.
std::size_t buffer_size( const mutable_buffers_1 & b);
Get the number of bytes in a non-modifiable buffer.
std::size_t buffer_size( const const_buffer & b);
Get the number of bytes in a non-modifiable buffer.
std::size_t buffer_size( const const_buffers_1 & b);
Get the total number of bytes in a buffer sequence.
template< typename BufferSequence> std::size_t buffer_size( const BufferSequence & b);
The BufferSequence
template
parameter may meet either of the ConstBufferSequence
or MutableBufferSequence
type requirements.
Adds buffering to the read-related operations of a stream.
template< typename Stream> class buffered_read_stream : noncopyable
Name |
Description |
---|---|
The type of the lowest layer. |
|
The type of the next layer. |
Name |
Description |
---|---|
Start an asynchronous fill. |
|
Start an asynchronous read. The buffer into which the data will be read must be valid for the lifetime of the asynchronous operation. |
|
Start an asynchronous write. The data being written must be valid for the lifetime of the asynchronous operation. |
|
Construct, passing the specified argument to initialise the next layer. |
|
Close the stream. |
|
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. 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. |
|
Get the io_service associated with the object. |
|
Determine the amount of data that may be read without blocking. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
Get a reference to the next layer. |
|
Peek at the incoming data on the stream. Returns the number of bytes read. Throws an exception on failure. Peek at the incoming data on the stream. Returns the number of bytes read, or 0 if an error occurred. |
|
Read some data from the stream. Returns the number of bytes read. Throws an exception on failure. Read some data from the stream. Returns the number of bytes read or 0 if an error occurred. |
|
Write the given data to the stream. Returns the number of bytes written. Throws an exception on failure. Write the given data to the stream. Returns the number of bytes written, or 0 if an error occurred. |
Name |
Description |
---|---|
The default buffer size. |
The buffered_read_stream
class template
can be used to add buffering to the synchronous and asynchronous read operations
of a stream.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/buffered_read_stream.hpp
Convenience header: boost/asio.hpp
template< typename ReadHandler> void-or-deduced async_fill( ReadHandler handler);
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> void-or-deduced async_read_some( const MutableBufferSequence & buffers, ReadHandler handler);
Start an asynchronous write. The data being written must be valid for the lifetime of the asynchronous operation.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_write_some( const ConstBufferSequence & buffers, WriteHandler handler);
Construct, passing the specified argument to initialise the next layer.
template< typename Arg> explicit buffered_read_stream( Arg & a); » more... template< typename Arg> buffered_read_stream( Arg & a, std::size_t buffer_size); » more...
Construct, passing the specified argument to initialise the next layer.
template< typename Arg> buffered_read_stream( Arg & a);
Construct, passing the specified argument to initialise the next layer.
template< typename Arg> buffered_read_stream( Arg & a, std::size_t buffer_size);
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Close the stream.
boost::system::error_code close( boost::system::error_code & ec);
static const std::size_t default_buffer_size = implementation_defined;
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(); » more...
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( boost::system::error_code & ec); » more...
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( boost::system::error_code & ec);
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
Determine the amount of data that may be read without blocking.
std::size_t in_avail(); » more... std::size_t in_avail( boost::system::error_code & ec); » more...
Determine the amount of data that may be read without blocking.
std::size_t in_avail();
Determine the amount of data that may be read without blocking.
std::size_t in_avail( boost::system::error_code & ec);
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer();
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
typedef next_layer_type::lowest_layer_type lowest_layer_type;
Header: boost/asio/buffered_read_stream.hpp
Convenience header: boost/asio.hpp
typedef remove_reference< Stream >::type next_layer_type;
Header: boost/asio/buffered_read_stream.hpp
Convenience header: boost/asio.hpp
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); » more...
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, boost::system::error_code & ec); » more...
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, boost::system::error_code & ec);
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); » more...
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, boost::system::error_code & ec); » more...
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, boost::system::error_code & 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); » more...
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, boost::system::error_code & ec); » more...
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.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers, boost::system::error_code & ec);
Adds buffering to the read- and write-related operations of a stream.
template< typename Stream> class buffered_stream : noncopyable
Name |
Description |
---|---|
The type of the lowest layer. |
|
The type of the next layer. |
Name |
Description |
---|---|
Start an asynchronous fill. |
|
Start an asynchronous flush. |
|
Start an asynchronous read. The buffer into which the data will be read must be valid for the lifetime of the asynchronous operation. |
|
Start an asynchronous write. The data being written must be valid for the lifetime of the asynchronous operation. |
|
Construct, passing the specified argument to initialise the next layer. |
|
Close the stream. |
|
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. 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. |
|
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. 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. |
|
Get the io_service associated with the object. |
|
Determine the amount of data that may be read without blocking. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
Get a reference to the next layer. |
|
Peek at the incoming data on the stream. Returns the number of bytes read. Throws an exception on failure. Peek at the incoming data on the stream. Returns the number of bytes read, or 0 if an error occurred. |
|
Read some data from the stream. Returns the number of bytes read. Throws an exception on failure. Read some data from the stream. Returns the number of bytes read or 0 if an error occurred. |
|
Write the given data to the stream. Returns the number of bytes written. Throws an exception on failure. Write the given data to the stream. Returns the number of bytes written, or 0 if an error occurred. |
The buffered_stream
class template can be used to add buffering to the synchronous and asynchronous
read and write operations of a stream.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/buffered_stream.hpp
Convenience header: boost/asio.hpp
template< typename ReadHandler> void-or-deduced async_fill( ReadHandler handler);
template< typename WriteHandler> void-or-deduced async_flush( WriteHandler handler);
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> void-or-deduced async_read_some( const MutableBufferSequence & buffers, ReadHandler handler);
Start an asynchronous write. The data being written must be valid for the lifetime of the asynchronous operation.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_write_some( const ConstBufferSequence & buffers, WriteHandler handler);
Construct, passing the specified argument to initialise the next layer.
template< typename Arg> explicit buffered_stream( Arg & a); » more... template< typename Arg> explicit buffered_stream( Arg & a, std::size_t read_buffer_size, std::size_t write_buffer_size); » more...
Construct, passing the specified argument to initialise the next layer.
template< typename Arg> buffered_stream( Arg & a);
Construct, passing the specified argument to initialise the next layer.
template< typename Arg> buffered_stream( Arg & a, std::size_t read_buffer_size, std::size_t write_buffer_size);
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Close the stream.
boost::system::error_code close( boost::system::error_code & ec);
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(); » more...
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( boost::system::error_code & ec); » more...
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( boost::system::error_code & 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(); » more...
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( boost::system::error_code & ec); » more...
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( boost::system::error_code & ec);
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
Determine the amount of data that may be read without blocking.
std::size_t in_avail(); » more... std::size_t in_avail( boost::system::error_code & ec); » more...
Determine the amount of data that may be read without blocking.
std::size_t in_avail();
Determine the amount of data that may be read without blocking.
std::size_t in_avail( boost::system::error_code & ec);
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer();
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
typedef next_layer_type::lowest_layer_type lowest_layer_type;
Header: boost/asio/buffered_stream.hpp
Convenience header: boost/asio.hpp
typedef remove_reference< Stream >::type next_layer_type;
Header: boost/asio/buffered_stream.hpp
Convenience header: boost/asio.hpp
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); » more...
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, boost::system::error_code & ec); » more...
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, boost::system::error_code & ec);
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); » more...
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, boost::system::error_code & ec); » more...
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, boost::system::error_code & 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); » more...
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, boost::system::error_code & ec); » more...
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.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers, boost::system::error_code & ec);
Adds buffering to the write-related operations of a stream.
template< typename Stream> class buffered_write_stream : noncopyable
Name |
Description |
---|---|
The type of the lowest layer. |
|
The type of the next layer. |
Name |
Description |
---|---|
Start an asynchronous flush. |
|
Start an asynchronous read. The buffer into which the data will be read must be valid for the lifetime of the asynchronous operation. |
|
Start an asynchronous write. The data being written must be valid for the lifetime of the asynchronous operation. |
|
Construct, passing the specified argument to initialise the next layer. |
|
Close the stream. |
|
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. 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. |
|
Get the io_service associated with the object. |
|
Determine the amount of data that may be read without blocking. |
|
Get a reference to the lowest layer. Get a const reference to the lowest layer. |
|
Get a reference to the next layer. |
|
Peek at the incoming data on the stream. Returns the number of bytes read. Throws an exception on failure. Peek at the incoming data on the stream. Returns the number of bytes read, or 0 if an error occurred. |
|
Read some data from the stream. Returns the number of bytes read. Throws an exception on failure. Read some data from the stream. Returns the number of bytes read or 0 if an error occurred. |
|
Write the given data to the stream. Returns the number of bytes written. Throws an exception on failure. 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. |
Name |
Description |
---|---|
The default buffer size. |
The buffered_write_stream
class template
can be used to add buffering to the synchronous and asynchronous write operations
of a stream.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/buffered_write_stream.hpp
Convenience header: boost/asio.hpp
template< typename WriteHandler> void-or-deduced async_flush( WriteHandler handler);
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> void-or-deduced async_read_some( const MutableBufferSequence & buffers, ReadHandler handler);
Start an asynchronous write. The data being written must be valid for the lifetime of the asynchronous operation.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_write_some( const ConstBufferSequence & buffers, WriteHandler handler);
Construct, passing the specified argument to initialise the next layer.
template< typename Arg> explicit buffered_write_stream( Arg & a); » more... template< typename Arg> buffered_write_stream( Arg & a, std::size_t buffer_size); » more...
Construct, passing the specified argument to initialise the next layer.
template< typename Arg> buffered_write_stream( Arg & a);
Construct, passing the specified argument to initialise the next layer.
template< typename Arg> buffered_write_stream( Arg & a, std::size_t buffer_size);
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Close the stream.
boost::system::error_code close( boost::system::error_code & ec);
static const std::size_t default_buffer_size = implementation_defined;
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(); » more...
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( boost::system::error_code & ec); » more...
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( boost::system::error_code & ec);
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
Determine the amount of data that may be read without blocking.
std::size_t in_avail(); » more... std::size_t in_avail( boost::system::error_code & ec); » more...
Determine the amount of data that may be read without blocking.
std::size_t in_avail();
Determine the amount of data that may be read without blocking.
std::size_t in_avail( boost::system::error_code & ec);
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer();
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
typedef next_layer_type::lowest_layer_type lowest_layer_type;
Header: boost/asio/buffered_write_stream.hpp
Convenience header: boost/asio.hpp
typedef remove_reference< Stream >::type next_layer_type;
Header: boost/asio/buffered_write_stream.hpp
Convenience header: boost/asio.hpp
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); » more...
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, boost::system::error_code & ec); » more...
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, boost::system::error_code & ec);
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); » more...
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, boost::system::error_code & ec); » more...
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, boost::system::error_code & ec);