Chromium Code Reviews| Index: net/websockets/websocket_frame.h |
| diff --git a/net/websockets/websocket_frame.h b/net/websockets/websocket_frame.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8874bf89b1ef00d54d105f1a37744fee61c067bb |
| --- /dev/null |
| +++ b/net/websockets/websocket_frame.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ |
| +#define NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ |
| +#pragma once |
| + |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "net/base/net_export.h" |
| + |
| +namespace net { |
| + |
| +// Represents a WebSocket frame header which may be shared by multiple |
| +// WebSocketPartialFrames. |
| +struct NET_EXPORT_PRIVATE WebSocketFrameHeader |
| + : public base::RefCounted<WebSocketFrameHeader> { |
| + typedef int OpCode; |
| + static const OpCode kOpCodeContinuation; |
| + static const OpCode kOpCodeText; |
| + static const OpCode kOpCodeBinary; |
| + static const OpCode kOpCodeClose; |
| + static const OpCode kOpCodePing; |
| + static const OpCode kOpCodePong; |
| + |
| + // This value must be a compile-time constant. "enum hack" is used here |
| + // to make MSVC happy. |
| + enum { kMaskingKeyLength = 4 }; |
| + |
| + // Members below correspond to each item in WebSocket frame header. |
| + // See <http://tools.ietf.org/html/rfc6455#section-5.2> for details. |
|
Takashi Toyoshima
2012/04/04 05:46:21
Usually, we don't use <> to refer URLs.
I could no
Yuta Kitamura
2012/04/09 08:17:57
$ git grep "<http" |wc -l
197
To my understanding
Yuta Kitamura
2012/04/09 12:12:26
Counted the number of instances of "one space befo
|
| + bool final; |
| + bool reserved1; |
| + bool reserved2; |
| + bool reserved3; |
| + OpCode opcode; |
| + bool masked; |
| + uint64 payload_length; |
| +}; |
| + |
| +// Contains payload data of a WebSocket frame. |
| +// |
| +// Payload of a WebSocket frame may be divided into multiple |
| +// WebSocketPartialFrame objects. You need to look at |final_part| member |
| +// variable to detect the end of a series of partial frame objects. |
| +// |
| +// Frame dissection is necessary to handle WebSocket frame stream containing |
| +// abritrarily large frames in the browser process. Because the server may send |
| +// a huge frame that doesn't fit in the memory, we cannot store the entire |
| +// payload data in the memory. |
| +// |
| +// Users of this struct should treat WebSocket frames as a data stream; it's |
| +// important to keep the frame data flowing, especially in the browser. |
| +// Do not let the data stuck somewhere in the pipeline. |
| +struct NET_EXPORT_PRIVATE WebSocketPartialFrame { |
| + WebSocketPartialFrame(); |
| + ~WebSocketPartialFrame(); |
| + |
| + // |header| may be shared among multiple WebSocketPartialFrames. |
| + scoped_refptr<const WebSocketFrameHeader> header; |
| + |
| + // Indicates this part is the last of partial frames. |
| + bool final_part; |
| + |
| + // |data| is always unmasked even if the frame is masked. |
| + std::vector<char> data; |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ |