19namespace basic_socket {
26 typedef lib::shared_ptr<type>
ptr;
31 typedef lib::shared_ptr<lib::asio::io_service::strand>
strand_ptr;
33 typedef lib::asio::local::stream_protocol::socket
socket_type;
41 return shared_from_this();
48 lib::asio::local::stream_protocol::socket &
get_socket() {
61 return "UNIX Socket Endpoint";
65 if (m_state != READY) {
72 callback(lib::error_code());
76 callback(lib::error_code());
81 if (m_state != UNINITIALIZED) {
85 m_socket = lib::make_shared<lib::asio::local::stream_protocol::socket>(*service);
89 return lib::error_code();
97 lib::asio::error_code ec;
103 lib::asio::error_code ec;
104 m_socket->shutdown(lib::asio::ip::tcp::socket::shutdown_both, ec);
109 return lib::error_code();
112 template <
typename ErrorCodeType>
158template <
typename config>
188 typedef lib::shared_ptr<lib::asio::local::stream_protocol::acceptor>
acceptor_ptr;
190 typedef lib::shared_ptr<lib::asio::steady_timer>
timer_ptr;
192 typedef lib::shared_ptr<lib::asio::io_service::work>
work_ptr;
197 , m_state(UNINITIALIZED)
203 if (m_acceptor && m_state == LISTENING)
204 ::unlink(m_acceptor->local_endpoint().path().c_str());
214#ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
224#ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
227 , m_tcp_pre_init_handler(src.m_tcp_pre_init_handler)
228 , m_tcp_post_init_handler(src.m_tcp_post_init_handler)
229 , m_io_service(src.m_io_service)
230 , m_acceptor(src.m_acceptor)
233 , m_state(src.m_state)
235 src.m_io_service = NULL;
236 src.m_acceptor = NULL;
237 src.m_state = UNINITIALIZED;
244 return socket_type::is_secure();
257 if (m_state != UNINITIALIZED) {
259 "asio::init_asio called from the wrong state");
268 m_acceptor = lib::make_shared<lib::asio::local::stream_protocol::acceptor>(*m_io_service);
271 ec = lib::error_code();
299 m_tcp_pre_init_handler = h;
328 m_tcp_post_init_handler = h;
343 return *m_io_service;
354 void listen(lib::asio::local::stream_protocol::endpoint
const & ep, lib::error_code & ec)
356 if (m_state != READY) {
358 "asio::listen called from the wrong state");
366 lib::asio::error_code bec;
369 boost::system::error_code test_ec;
370 lib::asio::local::stream_protocol::socket test_socket(
get_io_service());
371 test_socket.connect(ep, test_ec);
374 if(test_ec == boost::system::errc::success)
375 bec = boost::system::errc::make_error_code(boost::system::errc::address_in_use);
377 else if(test_ec == boost::system::errc::connection_refused)
378 ::unlink(ep.path().c_str());
379 else if(test_ec != boost::system::errc::no_such_file_or_directory)
384 m_acceptor->open(ep.protocol(),bec);
387 m_acceptor->bind(ep,bec);
390 m_acceptor->listen(boost::asio::socket_base::max_listen_connections,bec);
393 if (m_acceptor->is_open()) {
400 ec = lib::error_code();
410 void listen(lib::asio::local::stream_protocol::endpoint
const & ep) {
425 if (m_state != LISTENING) {
427 "asio::listen called from the wrong state");
433 ::unlink(m_acceptor->local_endpoint().path().c_str());
436 ec = lib::error_code();
457 return (m_state == LISTENING);
462 return m_io_service->run();
470 return m_io_service->run_one();
475 m_io_service->stop();
480 return m_io_service->poll();
485 return m_io_service->poll_one();
490 m_io_service->reset();
495 return m_io_service->stopped();
511 m_work = lib::make_shared<lib::asio::io_service::work>(
512 lib::ref(*m_io_service)
541 timer_ptr new_timer = lib::make_shared<lib::asio::steady_timer>(
546 new_timer->async_wait(
552 lib::placeholders::_1
569 lib::asio::error_code
const & ec)
572 if (ec == lib::asio::error::operation_aborted) {
576 "asio handle_timer error: "+ec.message());
581 callback(lib::error_code());
592 lib::error_code & ec)
594 if (m_state != LISTENING) {
602 if (config::enable_multithreading) {
603 m_acceptor->async_accept(
604 tcon->get_raw_socket(),
605 tcon->get_strand()->wrap(lib::bind(
609 lib::placeholders::_1
613 m_acceptor->async_accept(
614 tcon->get_raw_socket(),
619 lib::placeholders::_1
654 lib::error_code ret_ec;
659 if (asio_ec == lib::asio::errc::operation_canceled) {
683 lib::error_code ret_ec;
688 "asio handle_connect_timeout timer cancelled");
699 tcon->cancel_socket_checked();
706 if (ec == lib::asio::error::operation_aborted ||
723 "Async connect to "+tcon->get_remote_endpoint()+
" successful.");
726 callback(lib::error_code());
745 ec = tcon->init_asio(m_io_service);
748 tcon->set_tcp_pre_init_handler(m_tcp_pre_init_handler);
749 tcon->set_tcp_post_init_handler(m_tcp_post_init_handler);
751 return lib::error_code();
755 template <
typename error_type>
756 void log_err(
log::level l,
char const * msg, error_type
const & ec) {
758 s << msg <<
" error: " << ec <<
" (" << ec.message() <<
")";
759 m_elog->write(
l,
s.str());
lib::asio::local::stream_protocol::socket socket_type
Type of the ASIO socket being used.
lib::error_code get_ec() const
void async_shutdown(socket::shutdown_handler h)
lib::shared_ptr< lib::asio::io_service::strand > strand_ptr
Type of a pointer to the Asio io_service strand being used.
lib::asio::error_code cancel_socket()
lib::asio::local::stream_protocol::socket & get_raw_socket()
lib::error_code translate_ec(ErrorCodeType)
lib::shared_ptr< socket_type > socket_ptr
Type of a shared pointer to the socket being used.
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection socket component.
void set_handle(connection_hdl hdl)
lib::asio::local::stream_protocol::socket & get_socket()
lib::asio::local::stream_protocol::socket & get_next_layer()
void post_init(init_handler callback)
lib::error_code translate_ec(lib::error_code ec)
lib::error_code init_asio(io_service_ptr service, strand_ptr, bool)
void pre_init(init_handler callback)
local_connection type
Type of this connection socket component.
lib::asio::io_service * io_service_ptr
Type of a pointer to the Asio io_service being used.
std::string get_remote_endpoint(lib::error_code &ec) const
socket_con_type::ptr socket_con_ptr
local_connection socket_con_type
The type of the corresponding connection socket component.
local_endpoint type
The type of this endpoint socket component.
Asio based endpoint transport component.
lib::asio::io_service & get_io_service()
Retrieve a reference to the endpoint's io_service.
void handle_connect_timeout(transport_con_ptr tcon, timer_ptr, connect_handler callback, lib::error_code const &ec)
Asio connect timeout handler.
void stop_listening()
Stop listening.
void reset()
wraps the reset method of the internal io_service object
config::alog_type alog_type
Type of the access logging policy.
bool is_secure() const
Return whether or not the endpoint produces secure connections.
void stop()
wraps the stop method of the internal io_service object
void listen(lib::asio::local::stream_protocol::endpoint const &ep)
Set up endpoint for listening manually.
std::size_t run()
wraps the run method of the internal io_service object
lib::shared_ptr< lib::asio::io_service::work > work_ptr
Type of a shared pointer to an io_service work object.
bool is_listening() const
Check if the endpoint is listening.
lib::shared_ptr< lib::asio::steady_timer > timer_ptr
Type of timer handle.
void handle_accept(accept_handler callback, lib::asio::error_code const &asio_ec)
config::socket_type socket_type
Type of the socket policy.
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
asio::connection< config > transport_con_type
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
timer_ptr set_timer(long duration, timer_handler callback)
Call back a function after a period of time.
std::size_t poll()
wraps the poll method of the internal io_service object
void init_logging(alog_type *a, elog_type *e)
Initialize logging.
void init_asio(io_service_ptr ptr)
initialize asio transport with external io_service
local_endpoint< config > type
Type of this endpoint transport component.
config::elog_type elog_type
Type of the error logging policy.
void async_accept(transport_con_ptr tcon, accept_handler callback)
Accept the next connection attempt and assign it to con.
socket_con_type::ptr socket_con_ptr
Type of a shared pointer to the socket connection component.
socket_type::socket_con_type socket_con_type
Type of the socket connection component.
void handle_connect(transport_con_ptr tcon, timer_ptr con_timer, connect_handler callback, lib::asio::error_code const &ec)
void set_tcp_post_init_handler(tcp_init_handler h)
Sets the tcp post init handler.
void handle_timer(timer_ptr, timer_handler callback, lib::asio::error_code const &ec)
Timer handler.
config::concurrency_type concurrency_type
Type of the concurrency policy.
lib::asio::io_service * io_service_ptr
Type of a pointer to the ASIO io_service being used.
void set_tcp_init_handler(tcp_init_handler h)
Sets the tcp pre init handler (deprecated)
void stop_listening(lib::error_code &ec)
Stop listening (exception free)
void stop_perpetual()
Clears the endpoint's perpetual flag, allowing it to exit when empty.
lib::shared_ptr< lib::asio::local::stream_protocol::acceptor > acceptor_ptr
Type of a shared pointer to the acceptor being used.
bool stopped() const
wraps the stopped method of the internal io_service object
std::size_t poll_one()
wraps the poll_one method of the internal io_service object
void start_perpetual()
Marks the endpoint as perpetual, stopping it from exiting when empty.
void listen(lib::asio::local::stream_protocol::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
transport_con_type::ptr transport_con_ptr
std::size_t run_one()
wraps the run_one method of the internal io_service object
void async_accept(transport_con_ptr tcon, accept_handler callback, lib::error_code &ec)
Accept the next connection attempt and assign it to con (exception free)
@ async_accept_not_listening
@ operation_canceled
The requested operation was canceled.
@ invalid_state
The connection was in the wrong state for this operation.
lib::error_code make_error_code(error::value e)
boost::posix_time::time_duration milliseconds(long duration)
uint32_t level
Type of a channel package.
lib::function< void(connection_hdl, lib::asio::ip::tcp::socket &)> socket_init_handler
The signature of the socket init handler for this socket policy.
@ invalid_state
A function was called in a state that it was illegal to do so.
lib::function< void(lib::asio::error_code const &)> shutdown_handler
lib::error_code make_error_code(error::value e)
lib::function< void(connection_hdl)> tcp_init_handler
@ pass_through
underlying transport pass through
@ operation_aborted
Operation aborted.
lib::function< void(lib::error_code const &)> accept_handler
The type and signature of the callback passed to the accept method.
lib::function< void(lib::error_code const &)> timer_handler
The type and signature of the callback passed to the read method.
lib::function< void(lib::error_code const &)> connect_handler
The type and signature of the callback passed to the connect method.
lib::function< void(lib::error_code const &)> init_handler
The type and signature of the callback passed to the init hook.
Namespace for the WebSocket++ project.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
static level const devel
Development messages (warning: very chatty)
static level const devel
Low level debugging information (warning: very chatty)
static level const library