blob: e13e1eb7a9724370a9cd803abb536e84d93ff3f8 [file] [log] [blame]
[email protected]adb225d2013-08-30 13:14:431// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/websockets/websocket_basic_stream.h"
6
tfarinaea94afc232015-10-20 04:23:367#include <stddef.h>
tfarina8a2c66c22015-10-13 19:14:498#include <stdint.h>
[email protected]adb225d2013-08-30 13:14:439#include <algorithm>
10#include <limits>
11#include <string>
yhirano592ff7f2015-12-07 08:45:1912#include <utility>
[email protected]adb225d2013-08-30 13:14:4313#include <vector>
14
[email protected]adb225d2013-08-30 13:14:4315#include "base/bind.h"
16#include "base/logging.h"
[email protected]cb154062014-01-17 03:32:4017#include "base/numerics/safe_conversions.h"
[email protected]adb225d2013-08-30 13:14:4318#include "net/base/io_buffer.h"
19#include "net/base/net_errors.h"
20#include "net/socket/client_socket_handle.h"
21#include "net/websockets/websocket_errors.h"
22#include "net/websockets/websocket_frame.h"
23#include "net/websockets/websocket_frame_parser.h"
24
25namespace net {
26
27namespace {
28
tfarina8a2c66c22015-10-13 19:14:4929// This uses type uint64_t to match the definition of
[email protected]2f5d9f62013-09-26 12:14:2830// WebSocketFrameHeader::payload_length in websocket_frame.h.
tfarina8a2c66c22015-10-13 19:14:4931const uint64_t kMaxControlFramePayload = 125;
[email protected]2f5d9f62013-09-26 12:14:2832
[email protected]adb225d2013-08-30 13:14:4333// The number of bytes to attempt to read at a time.
34// TODO(ricea): See if there is a better number or algorithm to fulfill our
35// requirements:
36// 1. We would like to use minimal memory on low-bandwidth or idle connections
37// 2. We would like to read as close to line speed as possible on
38// high-bandwidth connections
39// 3. We can't afford to cause jank on the IO thread by copying large buffers
40// around
41// 4. We would like to hit any sweet-spots that might exist in terms of network
42// packet sizes / encryption block sizes / IPC alignment issues, etc.
43const int kReadBufferSize = 32 * 1024;
44
[email protected]9576544a2013-10-11 08:36:3345// Returns the total serialized size of |frames|. This function assumes that
46// |frames| will be serialized with mask field. This function forces the
47// masked bit of the frames on.
48int CalculateSerializedSizeAndTurnOnMaskBit(
danakj9c5cab52016-04-16 00:54:3349 std::vector<std::unique_ptr<WebSocketFrame>>* frames) {
tfarina8a2c66c22015-10-13 19:14:4950 const uint64_t kMaximumTotalSize = std::numeric_limits<int>::max();
[email protected]9576544a2013-10-11 08:36:3351
tfarina8a2c66c22015-10-13 19:14:4952 uint64_t total_size = 0;
yhirano592ff7f2015-12-07 08:45:1953 for (const auto& frame : *frames) {
[email protected]9576544a2013-10-11 08:36:3354 // Force the masked bit on.
55 frame->header.masked = true;
56 // We enforce flow control so the renderer should never be able to force us
57 // to cache anywhere near 2GB of frames.
tfarina8a2c66c22015-10-13 19:14:4958 uint64_t frame_size = frame->header.payload_length +
59 GetWebSocketFrameHeaderSize(frame->header);
pkasting4bff6be2014-10-15 17:54:3460 CHECK_LE(frame_size, kMaximumTotalSize - total_size)
[email protected]9576544a2013-10-11 08:36:3361 << "Aborting to prevent overflow";
62 total_size += frame_size;
63 }
pkasting4bff6be2014-10-15 17:54:3464 return static_cast<int>(total_size);
[email protected]9576544a2013-10-11 08:36:3365}
66
[email protected]adb225d2013-08-30 13:14:4367} // namespace
68
69WebSocketBasicStream::WebSocketBasicStream(
danakj9c5cab52016-04-16 00:54:3370 std::unique_ptr<ClientSocketHandle> connection,
[email protected]86602d3f2013-11-06 00:08:2271 const scoped_refptr<GrowableIOBuffer>& http_read_buffer,
72 const std::string& sub_protocol,
73 const std::string& extensions)
[email protected]adb225d2013-08-30 13:14:4374 : read_buffer_(new IOBufferWithSize(kReadBufferSize)),
dchengc7eeda422015-12-26 03:56:4875 connection_(std::move(connection)),
[email protected]86602d3f2013-11-06 00:08:2276 http_read_buffer_(http_read_buffer),
77 sub_protocol_(sub_protocol),
78 extensions_(extensions),
[email protected]adb225d2013-08-30 13:14:4379 generate_websocket_masking_key_(&GenerateWebSocketMaskingKey) {
[email protected]50133d7a2013-11-07 13:08:3680 // http_read_buffer_ should not be set if it contains no data.
dchengb206dc412014-08-26 19:46:2381 if (http_read_buffer_.get() && http_read_buffer_->offset() == 0)
[email protected]50133d7a2013-11-07 13:08:3682 http_read_buffer_ = NULL;
[email protected]adb225d2013-08-30 13:14:4383 DCHECK(connection_->is_initialized());
84}
85
86WebSocketBasicStream::~WebSocketBasicStream() { Close(); }
87
yhirano592ff7f2015-12-07 08:45:1988int WebSocketBasicStream::ReadFrames(
danakj9c5cab52016-04-16 00:54:3389 std::vector<std::unique_ptr<WebSocketFrame>>* frames,
yhirano592ff7f2015-12-07 08:45:1990 const CompletionCallback& callback) {
[email protected]2f5d9f62013-09-26 12:14:2891 DCHECK(frames->empty());
[email protected]adb225d2013-08-30 13:14:4392 // If there is data left over after parsing the HTTP headers, attempt to parse
93 // it as WebSocket frames.
dchengb206dc412014-08-26 19:46:2394 if (http_read_buffer_.get()) {
[email protected]adb225d2013-08-30 13:14:4395 DCHECK_GE(http_read_buffer_->offset(), 0);
96 // We cannot simply copy the data into read_buffer_, as it might be too
97 // large.
98 scoped_refptr<GrowableIOBuffer> buffered_data;
99 buffered_data.swap(http_read_buffer_);
melandory1346cde2016-06-11 00:42:12100 DCHECK(!http_read_buffer_);
danakj9c5cab52016-04-16 00:54:33101 std::vector<std::unique_ptr<WebSocketFrameChunk>> frame_chunks;
[email protected]adb225d2013-08-30 13:14:43102 if (!parser_.Decode(buffered_data->StartOfBuffer(),
103 buffered_data->offset(),
[email protected]2f5d9f62013-09-26 12:14:28104 &frame_chunks))
[email protected]adb225d2013-08-30 13:14:43105 return WebSocketErrorToNetError(parser_.websocket_error());
[email protected]2f5d9f62013-09-26 12:14:28106 if (!frame_chunks.empty()) {
107 int result = ConvertChunksToFrames(&frame_chunks, frames);
108 if (result != ERR_IO_PENDING)
109 return result;
110 }
[email protected]adb225d2013-08-30 13:14:43111 }
112
[email protected]2f5d9f62013-09-26 12:14:28113 // Run until socket stops giving us data or we get some frames.
[email protected]adb225d2013-08-30 13:14:43114 while (true) {
115 // base::Unretained(this) here is safe because net::Socket guarantees not to
116 // call any callbacks after Disconnect(), which we call from the
[email protected]2f5d9f62013-09-26 12:14:28117 // destructor. The caller of ReadFrames() is required to keep |frames|
[email protected]adb225d2013-08-30 13:14:43118 // valid.
[email protected]2f5d9f62013-09-26 12:14:28119 int result = connection_->socket()->Read(
120 read_buffer_.get(),
121 read_buffer_->size(),
122 base::Bind(&WebSocketBasicStream::OnReadComplete,
123 base::Unretained(this),
124 base::Unretained(frames),
125 callback));
[email protected]adb225d2013-08-30 13:14:43126 if (result == ERR_IO_PENDING)
127 return result;
[email protected]2f5d9f62013-09-26 12:14:28128 result = HandleReadResult(result, frames);
[email protected]adb225d2013-08-30 13:14:43129 if (result != ERR_IO_PENDING)
130 return result;
[email protected]2f5d9f62013-09-26 12:14:28131 DCHECK(frames->empty());
[email protected]adb225d2013-08-30 13:14:43132 }
133}
134
yhirano592ff7f2015-12-07 08:45:19135int WebSocketBasicStream::WriteFrames(
danakj9c5cab52016-04-16 00:54:33136 std::vector<std::unique_ptr<WebSocketFrame>>* frames,
yhirano592ff7f2015-12-07 08:45:19137 const CompletionCallback& callback) {
[email protected]adb225d2013-08-30 13:14:43138 // This function always concatenates all frames into a single buffer.
139 // TODO(ricea): Investigate whether it would be better in some cases to
140 // perform multiple writes with smaller buffers.
141 //
142 // First calculate the size of the buffer we need to allocate.
[email protected]9576544a2013-10-11 08:36:33143 int total_size = CalculateSerializedSizeAndTurnOnMaskBit(frames);
[email protected]adb225d2013-08-30 13:14:43144 scoped_refptr<IOBufferWithSize> combined_buffer(
145 new IOBufferWithSize(total_size));
[email protected]9576544a2013-10-11 08:36:33146
[email protected]adb225d2013-08-30 13:14:43147 char* dest = combined_buffer->data();
148 int remaining_size = total_size;
yhirano592ff7f2015-12-07 08:45:19149 for (const auto& frame : *frames) {
[email protected]adb225d2013-08-30 13:14:43150 WebSocketMaskingKey mask = generate_websocket_masking_key_();
[email protected]2f5d9f62013-09-26 12:14:28151 int result =
152 WriteWebSocketFrameHeader(frame->header, &mask, dest, remaining_size);
153 DCHECK_NE(ERR_INVALID_ARGUMENT, result)
[email protected]adb225d2013-08-30 13:14:43154 << "WriteWebSocketFrameHeader() says that " << remaining_size
155 << " is not enough to write the header in. This should not happen.";
156 CHECK_GE(result, 0) << "Potentially security-critical check failed";
157 dest += result;
158 remaining_size -= result;
159
tfarina8a2c66c22015-10-13 19:14:49160 CHECK_LE(frame->header.payload_length,
161 static_cast<uint64_t>(remaining_size));
pkasting4bff6be2014-10-15 17:54:34162 const int frame_size = static_cast<int>(frame->header.payload_length);
[email protected]403ee6e2014-01-27 10:10:44163 if (frame_size > 0) {
[email protected]403ee6e2014-01-27 10:10:44164 const char* const frame_data = frame->data->data();
165 std::copy(frame_data, frame_data + frame_size, dest);
166 MaskWebSocketFramePayload(mask, 0, dest, frame_size);
167 dest += frame_size;
168 remaining_size -= frame_size;
169 }
[email protected]adb225d2013-08-30 13:14:43170 }
171 DCHECK_EQ(0, remaining_size) << "Buffer size calculation was wrong; "
172 << remaining_size << " bytes left over.";
173 scoped_refptr<DrainableIOBuffer> drainable_buffer(
dchengb206dc412014-08-26 19:46:23174 new DrainableIOBuffer(combined_buffer.get(), total_size));
[email protected]adb225d2013-08-30 13:14:43175 return WriteEverything(drainable_buffer, callback);
176}
177
178void WebSocketBasicStream::Close() { connection_->socket()->Disconnect(); }
179
180std::string WebSocketBasicStream::GetSubProtocol() const {
181 return sub_protocol_;
182}
183
184std::string WebSocketBasicStream::GetExtensions() const { return extensions_; }
185
[email protected]adb225d2013-08-30 13:14:43186/*static*/
danakj9c5cab52016-04-16 00:54:33187std::unique_ptr<WebSocketBasicStream>
[email protected]adb225d2013-08-30 13:14:43188WebSocketBasicStream::CreateWebSocketBasicStreamForTesting(
danakj9c5cab52016-04-16 00:54:33189 std::unique_ptr<ClientSocketHandle> connection,
[email protected]adb225d2013-08-30 13:14:43190 const scoped_refptr<GrowableIOBuffer>& http_read_buffer,
191 const std::string& sub_protocol,
192 const std::string& extensions,
193 WebSocketMaskingKeyGeneratorFunction key_generator_function) {
danakj9c5cab52016-04-16 00:54:33194 std::unique_ptr<WebSocketBasicStream> stream(new WebSocketBasicStream(
dchengc7eeda422015-12-26 03:56:48195 std::move(connection), http_read_buffer, sub_protocol, extensions));
[email protected]adb225d2013-08-30 13:14:43196 stream->generate_websocket_masking_key_ = key_generator_function;
dchengc7eeda422015-12-26 03:56:48197 return stream;
[email protected]adb225d2013-08-30 13:14:43198}
199
200int WebSocketBasicStream::WriteEverything(
201 const scoped_refptr<DrainableIOBuffer>& buffer,
202 const CompletionCallback& callback) {
203 while (buffer->BytesRemaining() > 0) {
204 // The use of base::Unretained() here is safe because on destruction we
205 // disconnect the socket, preventing any further callbacks.
[email protected]2f5d9f62013-09-26 12:14:28206 int result = connection_->socket()->Write(
207 buffer.get(),
208 buffer->BytesRemaining(),
209 base::Bind(&WebSocketBasicStream::OnWriteComplete,
210 base::Unretained(this),
211 buffer,
212 callback));
[email protected]adb225d2013-08-30 13:14:43213 if (result > 0) {
214 buffer->DidConsume(result);
215 } else {
216 return result;
217 }
218 }
219 return OK;
220}
221
222void WebSocketBasicStream::OnWriteComplete(
223 const scoped_refptr<DrainableIOBuffer>& buffer,
224 const CompletionCallback& callback,
225 int result) {
226 if (result < 0) {
[email protected]2f5d9f62013-09-26 12:14:28227 DCHECK_NE(ERR_IO_PENDING, result);
[email protected]adb225d2013-08-30 13:14:43228 callback.Run(result);
229 return;
230 }
231
[email protected]2f5d9f62013-09-26 12:14:28232 DCHECK_NE(0, result);
[email protected]adb225d2013-08-30 13:14:43233 buffer->DidConsume(result);
234 result = WriteEverything(buffer, callback);
235 if (result != ERR_IO_PENDING)
236 callback.Run(result);
237}
238
239int WebSocketBasicStream::HandleReadResult(
240 int result,
danakj9c5cab52016-04-16 00:54:33241 std::vector<std::unique_ptr<WebSocketFrame>>* frames) {
[email protected]adb225d2013-08-30 13:14:43242 DCHECK_NE(ERR_IO_PENDING, result);
[email protected]2f5d9f62013-09-26 12:14:28243 DCHECK(frames->empty());
[email protected]adb225d2013-08-30 13:14:43244 if (result < 0)
245 return result;
246 if (result == 0)
247 return ERR_CONNECTION_CLOSED;
danakj9c5cab52016-04-16 00:54:33248 std::vector<std::unique_ptr<WebSocketFrameChunk>> frame_chunks;
[email protected]2f5d9f62013-09-26 12:14:28249 if (!parser_.Decode(read_buffer_->data(), result, &frame_chunks))
[email protected]adb225d2013-08-30 13:14:43250 return WebSocketErrorToNetError(parser_.websocket_error());
[email protected]2f5d9f62013-09-26 12:14:28251 if (frame_chunks.empty())
252 return ERR_IO_PENDING;
253 return ConvertChunksToFrames(&frame_chunks, frames);
[email protected]adb225d2013-08-30 13:14:43254}
255
[email protected]2f5d9f62013-09-26 12:14:28256int WebSocketBasicStream::ConvertChunksToFrames(
danakj9c5cab52016-04-16 00:54:33257 std::vector<std::unique_ptr<WebSocketFrameChunk>>* frame_chunks,
258 std::vector<std::unique_ptr<WebSocketFrame>>* frames) {
[email protected]2f5d9f62013-09-26 12:14:28259 for (size_t i = 0; i < frame_chunks->size(); ++i) {
danakj9c5cab52016-04-16 00:54:33260 std::unique_ptr<WebSocketFrame> frame;
yhirano592ff7f2015-12-07 08:45:19261 int result = ConvertChunkToFrame(std::move((*frame_chunks)[i]), &frame);
[email protected]2f5d9f62013-09-26 12:14:28262 if (result != OK)
263 return result;
264 if (frame)
dchengc7eeda422015-12-26 03:56:48265 frames->push_back(std::move(frame));
[email protected]2f5d9f62013-09-26 12:14:28266 }
yhirano592ff7f2015-12-07 08:45:19267 frame_chunks->clear();
[email protected]2f5d9f62013-09-26 12:14:28268 if (frames->empty())
269 return ERR_IO_PENDING;
270 return OK;
271}
272
273int WebSocketBasicStream::ConvertChunkToFrame(
danakj9c5cab52016-04-16 00:54:33274 std::unique_ptr<WebSocketFrameChunk> chunk,
275 std::unique_ptr<WebSocketFrame>* frame) {
[email protected]2f5d9f62013-09-26 12:14:28276 DCHECK(frame->get() == NULL);
277 bool is_first_chunk = false;
278 if (chunk->header) {
279 DCHECK(current_frame_header_ == NULL)
280 << "Received the header for a new frame without notification that "
281 << "the previous frame was complete (bug in WebSocketFrameParser?)";
282 is_first_chunk = true;
283 current_frame_header_.swap(chunk->header);
284 }
dchengb206dc412014-08-26 19:46:23285 const int chunk_size = chunk->data.get() ? chunk->data->size() : 0;
[email protected]2f5d9f62013-09-26 12:14:28286 DCHECK(current_frame_header_) << "Unexpected header-less chunk received "
287 << "(final_chunk = " << chunk->final_chunk
288 << ", data size = " << chunk_size
289 << ") (bug in WebSocketFrameParser?)";
290 scoped_refptr<IOBufferWithSize> data_buffer;
291 data_buffer.swap(chunk->data);
292 const bool is_final_chunk = chunk->final_chunk;
293 const WebSocketFrameHeader::OpCode opcode = current_frame_header_->opcode;
294 if (WebSocketFrameHeader::IsKnownControlOpCode(opcode)) {
295 bool protocol_error = false;
296 if (!current_frame_header_->final) {
297 DVLOG(1) << "WebSocket protocol error. Control frame, opcode=" << opcode
298 << " received with FIN bit unset.";
299 protocol_error = true;
300 }
301 if (current_frame_header_->payload_length > kMaxControlFramePayload) {
302 DVLOG(1) << "WebSocket protocol error. Control frame, opcode=" << opcode
303 << ", payload_length=" << current_frame_header_->payload_length
304 << " exceeds maximum payload length for a control message.";
305 protocol_error = true;
306 }
307 if (protocol_error) {
308 current_frame_header_.reset();
309 return ERR_WS_PROTOCOL_ERROR;
310 }
311 if (!is_final_chunk) {
312 DVLOG(2) << "Encountered a split control frame, opcode " << opcode;
dchengb206dc412014-08-26 19:46:23313 if (incomplete_control_frame_body_.get()) {
[email protected]2f5d9f62013-09-26 12:14:28314 DVLOG(3) << "Appending to an existing split control frame.";
315 AddToIncompleteControlFrameBody(data_buffer);
316 } else {
317 DVLOG(3) << "Creating new storage for an incomplete control frame.";
318 incomplete_control_frame_body_ = new GrowableIOBuffer();
319 // This method checks for oversize control frames above, so as long as
320 // the frame parser is working correctly, this won't overflow. If a bug
321 // does cause it to overflow, it will CHECK() in
322 // AddToIncompleteControlFrameBody() without writing outside the buffer.
323 incomplete_control_frame_body_->SetCapacity(kMaxControlFramePayload);
324 AddToIncompleteControlFrameBody(data_buffer);
325 }
326 return OK;
327 }
dchengb206dc412014-08-26 19:46:23328 if (incomplete_control_frame_body_.get()) {
[email protected]2f5d9f62013-09-26 12:14:28329 DVLOG(2) << "Rejoining a split control frame, opcode " << opcode;
330 AddToIncompleteControlFrameBody(data_buffer);
331 const int body_size = incomplete_control_frame_body_->offset();
332 DCHECK_EQ(body_size,
333 static_cast<int>(current_frame_header_->payload_length));
334 scoped_refptr<IOBufferWithSize> body = new IOBufferWithSize(body_size);
335 memcpy(body->data(),
336 incomplete_control_frame_body_->StartOfBuffer(),
337 body_size);
338 incomplete_control_frame_body_ = NULL; // Frame now complete.
339 DCHECK(is_final_chunk);
340 *frame = CreateFrame(is_final_chunk, body);
341 return OK;
342 }
343 }
344
345 // Apply basic sanity checks to the |payload_length| field from the frame
346 // header. A check for exact equality can only be used when the whole frame
347 // arrives in one chunk.
348 DCHECK_GE(current_frame_header_->payload_length,
tfarina8a2c66c22015-10-13 19:14:49349 base::checked_cast<uint64_t>(chunk_size));
[email protected]2f5d9f62013-09-26 12:14:28350 DCHECK(!is_first_chunk || !is_final_chunk ||
351 current_frame_header_->payload_length ==
tfarina8a2c66c22015-10-13 19:14:49352 base::checked_cast<uint64_t>(chunk_size));
[email protected]2f5d9f62013-09-26 12:14:28353
354 // Convert the chunk to a complete frame.
355 *frame = CreateFrame(is_final_chunk, data_buffer);
356 return OK;
357}
358
danakj9c5cab52016-04-16 00:54:33359std::unique_ptr<WebSocketFrame> WebSocketBasicStream::CreateFrame(
[email protected]2f5d9f62013-09-26 12:14:28360 bool is_final_chunk,
361 const scoped_refptr<IOBufferWithSize>& data) {
danakj9c5cab52016-04-16 00:54:33362 std::unique_ptr<WebSocketFrame> result_frame;
[email protected]2f5d9f62013-09-26 12:14:28363 const bool is_final_chunk_in_message =
364 is_final_chunk && current_frame_header_->final;
dchengb206dc412014-08-26 19:46:23365 const int data_size = data.get() ? data->size() : 0;
[email protected]2f5d9f62013-09-26 12:14:28366 const WebSocketFrameHeader::OpCode opcode = current_frame_header_->opcode;
[email protected]e678d4fe2013-10-11 11:27:55367 // Empty frames convey no useful information unless they are the first frame
368 // (containing the type and flags) or have the "final" bit set.
369 if (is_final_chunk_in_message || data_size > 0 ||
370 current_frame_header_->opcode !=
371 WebSocketFrameHeader::kOpCodeContinuation) {
[email protected]2f5d9f62013-09-26 12:14:28372 result_frame.reset(new WebSocketFrame(opcode));
373 result_frame->header.CopyFrom(*current_frame_header_);
374 result_frame->header.final = is_final_chunk_in_message;
375 result_frame->header.payload_length = data_size;
376 result_frame->data = data;
377 // Ensure that opcodes Text and Binary are only used for the first frame in
[email protected]d52c0c42014-02-19 08:27:47378 // the message. Also clear the reserved bits.
379 // TODO(ricea): If a future extension requires the reserved bits to be
380 // retained on continuation frames, make this behaviour conditional on a
381 // flag set at construction time.
382 if (!is_final_chunk && WebSocketFrameHeader::IsKnownDataOpCode(opcode)) {
[email protected]2f5d9f62013-09-26 12:14:28383 current_frame_header_->opcode = WebSocketFrameHeader::kOpCodeContinuation;
[email protected]d52c0c42014-02-19 08:27:47384 current_frame_header_->reserved1 = false;
385 current_frame_header_->reserved2 = false;
386 current_frame_header_->reserved3 = false;
387 }
[email protected]2f5d9f62013-09-26 12:14:28388 }
389 // Make sure that a frame header is not applied to any chunks that do not
390 // belong to it.
391 if (is_final_chunk)
392 current_frame_header_.reset();
dchengc7eeda422015-12-26 03:56:48393 return result_frame;
[email protected]2f5d9f62013-09-26 12:14:28394}
395
396void WebSocketBasicStream::AddToIncompleteControlFrameBody(
397 const scoped_refptr<IOBufferWithSize>& data_buffer) {
dchengb206dc412014-08-26 19:46:23398 if (!data_buffer.get())
[email protected]2f5d9f62013-09-26 12:14:28399 return;
400 const int new_offset =
401 incomplete_control_frame_body_->offset() + data_buffer->size();
402 CHECK_GE(incomplete_control_frame_body_->capacity(), new_offset)
403 << "Control frame body larger than frame header indicates; frame parser "
404 "bug?";
405 memcpy(incomplete_control_frame_body_->data(),
406 data_buffer->data(),
407 data_buffer->size());
408 incomplete_control_frame_body_->set_offset(new_offset);
409}
410
yhirano592ff7f2015-12-07 08:45:19411void WebSocketBasicStream::OnReadComplete(
danakj9c5cab52016-04-16 00:54:33412 std::vector<std::unique_ptr<WebSocketFrame>>* frames,
yhirano592ff7f2015-12-07 08:45:19413 const CompletionCallback& callback,
414 int result) {
[email protected]2f5d9f62013-09-26 12:14:28415 result = HandleReadResult(result, frames);
[email protected]adb225d2013-08-30 13:14:43416 if (result == ERR_IO_PENDING)
[email protected]2f5d9f62013-09-26 12:14:28417 result = ReadFrames(frames, callback);
[email protected]adb225d2013-08-30 13:14:43418 if (result != ERR_IO_PENDING)
419 callback.Run(result);
420}
421
422} // namespace net