diff options
Diffstat (limited to 'chromium/net/third_party/quiche/src/quiche/quic/core/io/socket.h')
-rw-r--r-- | chromium/net/third_party/quiche/src/quiche/quic/core/io/socket.h | 63 |
1 files changed, 11 insertions, 52 deletions
diff --git a/chromium/net/third_party/quiche/src/quiche/quic/core/io/socket.h b/chromium/net/third_party/quiche/src/quiche/quic/core/io/socket.h index fcc6418ac49..8d32bc380af 100644 --- a/chromium/net/third_party/quiche/src/quiche/quic/core/io/socket.h +++ b/chromium/net/third_party/quiche/src/quiche/quic/core/io/socket.h @@ -16,7 +16,6 @@ #include "quiche/quic/platform/api/quic_ip_address_family.h" #include "quiche/quic/platform/api/quic_socket_address.h" #include "quiche/common/platform/api/quiche_export.h" -#include "quiche/common/platform/api/quiche_mem_slice.h" #if defined(_WIN32) #include <winsock2.h> @@ -32,57 +31,6 @@ using SocketFd = int; inline constexpr SocketFd kInvalidSocketFd = -1; #endif -// A read/write socket. -// -// Warning regarding blocking calls: Code in the QUICHE library typically -// handles IO on a single thread, so if making calls from that typical -// environment, it would be problematic to make a blocking call and block that -// single thread. -class QUICHE_EXPORT_PRIVATE Socket { - public: - class AsyncVisitor { - public: - virtual ~AsyncVisitor() = default; - - // If the operation completed without error, `data` is set to the received - // data. - virtual void ReceiveComplete( - absl::StatusOr<quiche::QuicheMemSlice> data) = 0; - - virtual void SendComplete(absl::Status status) = 0; - }; - - virtual ~Socket() = default; - - // Blocking read. Receives and returns a buffer of up to `max_size` bytes from - // socket. Returns status on error. - virtual absl::StatusOr<quiche::QuicheMemSlice> ReceiveBlocking( - QuicByteCount max_size) = 0; - - // Asynchronous read. Receives up to `max_size` bytes from socket. If - // no data is synchronously available to be read, waits until some data is - // available or the socket is closed. On completion, calls ReceiveComplete() - // on the visitor, potentially before return from ReceiveAsync(). - // - // After calling, the socket must not be destroyed until ReceiveComplete() is - // called. - virtual void ReceiveAsync(QuicByteCount max_size) = 0; - - // Blocking write. Sends all of `data` (potentially via multiple underlying - // socket sends). - virtual absl::Status SendBlocking(std::string data) = 0; - virtual absl::Status SendBlocking(quiche::QuicheMemSlice data) = 0; - - // Asynchronous write. Sends all of `data` (potentially via multiple - // underlying socket sends). On completion, calls SendComplete() on the - // visitor, potentially before return from SendAsync(). - // - // After calling, the socket must not be destroyed until SendComplete() is - // called. - virtual void SendAsync(std::string data) = 0; - virtual void SendAsync(quiche::QuicheMemSlice data) = 0; -}; - // Low-level platform-agnostic socket operations. Closely follows the behavior // of basic POSIX socket APIs, diverging mostly only to convert to/from cleaner // and platform-agnostic types. @@ -92,6 +40,17 @@ enum class SocketProtocol { kTcp, }; +inline absl::string_view GetProtocolName(SocketProtocol protocol) { + switch (protocol) { + case SocketProtocol::kUdp: + return "UDP"; + case SocketProtocol::kTcp: + return "TCP"; + } + + return "unknown"; +} + struct QUICHE_EXPORT_PRIVATE AcceptResult { // Socket for interacting with the accepted connection. SocketFd fd; |