47class Base :
public RC<thread_unsafe_refcount>
52 virtual void async_send(
const openvpn_io::const_buffer &buf,
53 Function<
void(
const openvpn_io::error_code &,
const size_t)> &&callback) = 0;
56 Function<
void(
const openvpn_io::error_code &,
const size_t)> &&callback) = 0;
81#ifdef ASIO_HAS_LOCAL_SOCKETS
88#if defined(OPENVPN_POLYSOCK_SUPPORTS_ALT_ROUTING)
89 virtual bool alt_routing_enabled()
const
117 TCP(openvpn_io::io_context &io_context,
125 Function<
void(
const openvpn_io::error_code &,
const size_t)> &&callback)
override
127 socket.async_send(buf, std::move(callback));
131 Function<
void(
const openvpn_io::error_code &,
const size_t)> &&callback)
override
133 socket.async_receive(buf, std::move(callback));
136#if !defined(OPENVPN_POLYSOCK_SUPPORTS_ALT_ROUTING)
143 catch (
const std::exception &)
158 catch (
const std::exception &)
166 socket.non_blocking(state);
171 socket.set_option(openvpn_io::ip::tcp::no_delay(
true));
174#if !defined(OPENVPN_PLATFORM_WIN)
177 const int fd =
socket.native_handle();
186 socket.shutdown(openvpn_io::ip::tcp::socket::shutdown_send);
188 socket.shutdown(openvpn_io::ip::tcp::socket::shutdown_receive);
208 return socket.native_handle();
211#if defined(OPENVPN_POLYSOCK_SUPPORTS_ALT_ROUTING)
214 const char *proto = (
socket.alt_routing_enabled() ?
"TCP ALT " :
"TCP ");
215 return proto +
socket.to_string();
218 bool alt_routing_enabled()
const override
220 return socket.alt_routing_enabled();
223 AltRouting::Socket
socket;
224#elif defined(OPENVPN_POLYSOCK_SUPPORTS_BIND)
225 AsioBoundSocket::Socket
socket;
231#ifdef ASIO_HAS_LOCAL_SOCKETS
232struct Unix :
public Base
236 Unix(openvpn_io::io_context &io_context,
243 void async_send(
const openvpn_io::const_buffer &buf,
244 Function<
void(
const openvpn_io::error_code &,
const size_t)> &&callback)
override
249 void async_receive(
const openvpn_io::mutable_buffer &buf,
250 Function<
void(
const openvpn_io::error_code &,
const size_t)> &&callback)
override
252 socket.async_receive(buf, std::move(callback));
255 std::string remote_endpoint_str()
const override
260 bool remote_ip_port(IP::Addr &,
unsigned int &)
const override
265 void non_blocking(
const bool state)
override
267 socket.non_blocking(state);
270 bool peercreds(SockOpt::Creds &cr)
override
272 return SockOpt::peercreds(socket.native_handle(), cr);
277 const int fd = socket.native_handle();
279 SockOpt::set_cloexec(fd);
282#if !defined(OPENVPN_PLATFORM_MAC)
286 void shutdown(
const unsigned int flags)
override
288 if (
flags & SHUTDOWN_SEND)
289 socket.shutdown(openvpn_io::ip::tcp::socket::shutdown_send);
290 else if (
flags & SHUTDOWN_RECV)
291 socket.shutdown(openvpn_io::ip::tcp::socket::shutdown_receive);
295 void close()
override
300 bool is_open()
const override
302 return socket.is_open();
305 bool is_local()
const override
310 openvpn_io::detail::socket_type native_handle()
override
312 return socket.native_handle();
315 openvpn_io::local::stream_protocol::socket socket;
319#if defined(OPENVPN_PLATFORM_WIN)
320struct NamedPipe :
public Base
322 typedef RCPtr<NamedPipe> Ptr;
324 NamedPipe(openvpn_io::windows::stream_handle &&handle_arg,
327 handle(std::move(handle_arg))
331 void async_send(
const openvpn_io::const_buffer &buf,
332 Function<
void(
const openvpn_io::error_code &,
const size_t)> &&callback)
override
334 handle.async_write_some(buf, std::move(callback));
337 void async_receive(
const openvpn_io::mutable_buffer &buf,
338 Function<
void(
const openvpn_io::error_code &,
const size_t)> &&callback)
override
340 handle.async_read_some(buf, std::move(callback));
343 std::string remote_endpoint_str()
const override
348 bool remote_ip_port(IP::Addr &,
unsigned int &)
const override
353 void non_blocking(
const bool state)
override
357 void close()
override
362 bool is_open()
const override
364 return handle.is_open();
367 bool is_local()
const override
372 openvpn_io::windows::stream_handle handle;
HTTPBase< HTTPCore, Config, Status, HTTP::ReplyType, ContentInfo, olong, RC< thread_unsafe_refcount > > Base