7 #include <liburing/io_uring.h> 10 #include <boost/asio/buffer.hpp> 11 #include <boost/asio/ip/tcp.hpp> 13 #include "absl/base/attributes.h" 14 #include "util/sync_stream_interface.h" 29 using native_handle_type = int;
30 using endpoint_type = ::boost::asio::ip::tcp::endpoint;
31 using error_code = std::error_code;
32 using expected_size_t = nonstd::expected<size_t, error_code>;
48 ABSL_MUST_USE_RESULT error_code Listen(
unsigned port,
unsigned backlog,
49 uint32_t sock_opts_mask = 0);
51 ABSL_MUST_USE_RESULT error_code Accept(
FiberSocket* peer);
53 ABSL_MUST_USE_RESULT error_code Connect(
const endpoint_type& ep);
55 ABSL_MUST_USE_RESULT error_code Shutdown(
int how);
57 ABSL_MUST_USE_RESULT error_code Close();
60 expected_size_t Send(
const iovec* ptr,
size_t len)
override;
62 expected_size_t Send(
const boost::asio::const_buffer& b) {
63 iovec v{const_cast<void*>(b.data()), b.size()};
67 expected_size_t Recv(iovec* ptr,
size_t len)
override;
69 expected_size_t Recv(
const boost::asio::mutable_buffer& mb) {
70 iovec v{mb.data(), mb.size()};
74 native_handle_type native_handle()
const {
83 endpoint_type LocalEndpoint()
const;
84 endpoint_type RemoteEndpoint()
const;
89 return fd_ >= 0 && (fd_ & IS_SHUTDOWN) == 0;
92 void set_proactor(
Proactor* p) { p_ = p;}
94 Proactor* proactor() {
return p_; }
96 static bool IsConnClosed(
const error_code& ec) {
97 return (ec == std::errc::connection_aborted) || (ec == std::errc::connection_reset);
102 enum { FD_MASK = 0x1fffffff };
103 enum { IS_SHUTDOWN = 0x20000000 };
bool IsOpen() const
IsOpen does not promise that the socket is TCP connected or live,.
void Detach()
Removes the ownership over file descriptor. Use with caution.