6 #include <boost/asio/ip/tcp.hpp> 8 #include "util/asio/asio_utils.h" 9 #include "util/asio/detail/fiber_socket_impl.h" 17 using error_code = ::boost::system::error_code;
18 using next_layer_type = ::boost::asio::ip::tcp::socket;
19 using lowest_layer_type = next_layer_type::lowest_layer_type;
27 size_t rbuf_size = 1 << 12)
28 : impl_(new detail::FiberSocketImpl{hname, port, cntx, rbuf_size}) {}
31 FiberSyncSocket(FiberSyncSocket&& other) : impl_(std::move(other.impl_)) {}
37 error_code ClientWaitToConnect(uint32_t ms) {
38 return impl_->ClientWaitToConnect(ms);
44 template <
typename MBS>
size_t read_some(
const MBS& bufs, error_code& ec) {
45 return impl_->read_some(bufs, ec);
50 template <
typename MBS>
size_t read_some(
const MBS& bufs);
54 template <
typename BS>
size_t write_some(
const BS& bufs, error_code& ec) {
55 return impl_->write_some(bufs, ec);
60 template <
typename BS>
size_t write_some(
const BS& bufs);
62 auto native_handle() {
return impl_->native_handle(); }
64 bool is_open()
const {
return impl_ && impl_->is_open(); }
69 void Shutdown(error_code& ec) {
73 next_layer_type::endpoint_type remote_endpoint(error_code& ec)
const {
74 return impl_->remote_endpoint(ec);
77 error_code status()
const {
return impl_->status(); }
80 next_layer_type& next_layer() {
return impl_->next_layer(); }
81 lowest_layer_type& lowest_layer() {
return impl_->next_layer().lowest_layer(); }
84 IoContext& context() {
return impl_->context(); }
86 bool keep_alive()
const {
return impl_->keep_alive(); }
87 void set_keep_alive(
bool flag) { impl_->set_keep_alive(flag); }
90 std::unique_ptr<detail::FiberSocketImpl> impl_;
93 static_assert(std::is_move_constructible<FiberSyncSocket>::value,
"");
FiberSyncSocket(const std::string &hname, const std::string &port, IoContext *cntx, size_t rbuf_size=1<< 12)
Client socket constructor.