#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/websockets/websocket_basic_stream.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <limits>
#include <ostream>
#include <utility>
#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/log/net_log_event_type.h"
#include "net/socket/client_socket_handle.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/websockets/websocket_basic_stream_adapters.h"
#include "net/websockets/websocket_errors.h"
#include "net/websockets/websocket_frame.h"
namespace net {
namespace {
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = …;
constexpr uint64_t kMaxControlFramePayload = …;
#if BUILDFLAG(IS_ANDROID)
constexpr size_t kLargeReadBufferSize = 32 * 1024;
#else
constexpr size_t kLargeReadBufferSize = …;
#endif
constexpr size_t kSmallReadBufferSize = …;
constexpr double kThresholdInBytesPerSecond = …;
int CalculateSerializedSizeAndTurnOnMaskBit(
std::vector<std::unique_ptr<WebSocketFrame>>* frames) { … }
base::Value::Dict NetLogBufferSizeParam(int buffer_size) { … }
base::Value::Dict NetLogFrameHeaderParam(const WebSocketFrameHeader* header) { … }
}
WebSocketBasicStream::BufferSizeManager::BufferSizeManager() = default;
WebSocketBasicStream::BufferSizeManager::~BufferSizeManager() = default;
void WebSocketBasicStream::BufferSizeManager::OnRead(base::TimeTicks now) { … }
void WebSocketBasicStream::BufferSizeManager::OnReadComplete(
base::TimeTicks now,
int size) { … }
WebSocketBasicStream::WebSocketBasicStream(
std::unique_ptr<Adapter> connection,
const scoped_refptr<GrowableIOBuffer>& http_read_buffer,
const std::string& sub_protocol,
const std::string& extensions,
const NetLogWithSource& net_log)
: … { … }
WebSocketBasicStream::~WebSocketBasicStream() { … }
int WebSocketBasicStream::ReadFrames(
std::vector<std::unique_ptr<WebSocketFrame>>* frames,
CompletionOnceCallback callback) { … }
int WebSocketBasicStream::WriteFrames(
std::vector<std::unique_ptr<WebSocketFrame>>* frames,
CompletionOnceCallback callback) { … }
void WebSocketBasicStream::Close() { … }
std::string WebSocketBasicStream::GetSubProtocol() const { … }
std::string WebSocketBasicStream::GetExtensions() const { … }
const NetLogWithSource& WebSocketBasicStream::GetNetLogWithSource() const { … }
std::unique_ptr<WebSocketBasicStream>
WebSocketBasicStream::CreateWebSocketBasicStreamForTesting(
std::unique_ptr<ClientSocketHandle> connection,
const scoped_refptr<GrowableIOBuffer>& http_read_buffer,
const std::string& sub_protocol,
const std::string& extensions,
const NetLogWithSource& net_log,
WebSocketMaskingKeyGeneratorFunction key_generator_function) { … }
int WebSocketBasicStream::ReadEverything(
std::vector<std::unique_ptr<WebSocketFrame>>* frames) { … }
void WebSocketBasicStream::OnReadComplete(
std::vector<std::unique_ptr<WebSocketFrame>>* frames,
int result) { … }
int WebSocketBasicStream::WriteEverything(
const scoped_refptr<DrainableIOBuffer>& buffer) { … }
void WebSocketBasicStream::OnWriteComplete(
const scoped_refptr<DrainableIOBuffer>& buffer,
int result) { … }
int WebSocketBasicStream::HandleReadResult(
int result,
std::vector<std::unique_ptr<WebSocketFrame>>* frames) { … }
int WebSocketBasicStream::ConvertChunksToFrames(
std::vector<std::unique_ptr<WebSocketFrameChunk>>* frame_chunks,
std::vector<std::unique_ptr<WebSocketFrame>>* frames) { … }
int WebSocketBasicStream::ConvertChunkToFrame(
std::unique_ptr<WebSocketFrameChunk> chunk,
std::unique_ptr<WebSocketFrame>* frame) { … }
std::unique_ptr<WebSocketFrame> WebSocketBasicStream::CreateFrame(
bool is_final_chunk,
base::span<const char> data) { … }
void WebSocketBasicStream::AddToIncompleteControlFrameBody(
base::span<const char> data) { … }
}