Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: net/websockets/websocket_frame.h

Issue 9956013: Add WebSocketFrameParser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added DISALLOW_COPY_AND_ASSIGN. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/net.gyp ('k') | net/websockets/websocket_frame.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #ifndef NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
7 #pragma once
8
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/base/net_export.h"
14
15 namespace net {
16
17 // Represents a WebSocket frame header.
18 //
19 // Members of this class correspond to each element in WebSocket frame header
20 // (see http://tools.ietf.org/html/rfc6455#section-5.2).
21 struct NET_EXPORT_PRIVATE WebSocketFrameHeader {
22 typedef int OpCode;
23 static const OpCode kOpCodeContinuation;
24 static const OpCode kOpCodeText;
25 static const OpCode kOpCodeBinary;
26 static const OpCode kOpCodeClose;
27 static const OpCode kOpCodePing;
28 static const OpCode kOpCodePong;
29
30 // These values must be a compile-time constant. "enum hack" is used here
31 // to make MSVC happy.
32 enum {
33 kBaseHeaderSize = 2,
34 kMaximumExtendedLengthSize = 8,
35 kMaskingKeyLength = 4
36 };
37
38 // Members below correspond to each item in WebSocket frame header.
39 // See <http://tools.ietf.org/html/rfc6455#section-5.2> for details.
40 bool final;
41 bool reserved1;
42 bool reserved2;
43 bool reserved3;
44 OpCode opcode;
45 bool masked;
46 uint64 payload_length;
47 };
48
49 // Contains payload data of part of a WebSocket frame.
50 //
51 // Payload of a WebSocket frame may be divided into multiple chunks.
52 // You need to look at |final_chunk| member variable to detect the end of a
53 // series of chunk objects of a WebSocket frame.
54 //
55 // Frame dissection is necessary to handle WebSocket frame stream containing
56 // abritrarily large frames in the browser process. Because the server may send
57 // a huge frame that doesn't fit in the memory, we cannot store the entire
58 // payload data in the memory.
59 //
60 // Users of this struct should treat WebSocket frames as a data stream; it's
61 // important to keep the frame data flowing, especially in the browser process.
62 // Users should not let the data stuck somewhere in the pipeline.
63 struct NET_EXPORT_PRIVATE WebSocketFrameChunk {
64 WebSocketFrameChunk();
65 ~WebSocketFrameChunk();
66
67 // Non-null |header| is provided only if this chunk is the first part of
68 // a series of chunks.
69 scoped_ptr<WebSocketFrameHeader> header;
70
71 // Indicates this part is the last chunk of a frame.
72 bool final_chunk;
73
74 // |data| is always unmasked even if the frame is masked.
75 std::vector<char> data;
76 };
77
78 } // namespace net
79
80 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
OLDNEW
« no previous file with comments | « net/net.gyp ('k') | net/websockets/websocket_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698