OLD | NEW |
---|---|
(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/ref_counted.h" | |
13 #include "net/base/net_export.h" | |
14 | |
15 namespace net { | |
16 | |
17 // Represents a WebSocket frame header which may be shared by multiple | |
18 // WebSocketPartialFrames. | |
19 // | |
20 // Members of this class correspond to each element in WebSocket frame header | |
21 // (see http://tools.ietf.org/html/rfc6455#section-5.2). | |
22 struct NET_EXPORT_PRIVATE WebSocketFrameHeader | |
23 : public base::RefCounted<WebSocketFrameHeader> { | |
mmenke
2012/05/02 16:15:41
May be worth considering not refcounting this, jus
Yuta Kitamura
2012/05/08 08:21:58
After some consideration, I decided to not refcoun
| |
24 typedef int OpCode; | |
25 static const OpCode kOpCodeContinuation; | |
26 static const OpCode kOpCodeText; | |
27 static const OpCode kOpCodeBinary; | |
28 static const OpCode kOpCodeClose; | |
29 static const OpCode kOpCodePing; | |
30 static const OpCode kOpCodePong; | |
31 | |
32 // These values must be a compile-time constant. "enum hack" is used here | |
33 // to make MSVC happy. | |
34 enum { | |
35 kBaseHeaderSize = 2, | |
36 kMaximumExtendedLengthSize = 8, | |
37 kMaskingKeyLength = 4 | |
38 }; | |
39 | |
40 // Members below correspond to each item in WebSocket frame header. | |
41 // See <http://tools.ietf.org/html/rfc6455#section-5.2> for details. | |
42 bool final; | |
43 bool reserved1; | |
44 bool reserved2; | |
45 bool reserved3; | |
46 OpCode opcode; | |
47 bool masked; | |
48 uint64 payload_length; | |
49 }; | |
50 | |
51 // Contains payload data of a WebSocket frame. | |
52 // | |
53 // Payload of a WebSocket frame may be divided into multiple | |
54 // WebSocketPartialFrame objects. You need to look at |final_part| member | |
55 // variable to detect the end of a series of partial frame objects. | |
56 // | |
57 // Frame dissection is necessary to handle WebSocket frame stream containing | |
58 // abritrarily large frames in the browser process. Because the server may send | |
59 // a huge frame that doesn't fit in the memory, we cannot store the entire | |
60 // payload data in the memory. | |
61 // | |
62 // Users of this struct should treat WebSocket frames as a data stream; it's | |
63 // important to keep the frame data flowing, especially in the browser process. | |
64 // Users should not let the data stuck somewhere in the pipeline. | |
65 struct NET_EXPORT_PRIVATE WebSocketPartialFrame { | |
Yuta Kitamura
2012/05/08 08:21:58
I'm going to rename this class to "WebSocketFrameC
| |
66 WebSocketPartialFrame(); | |
67 ~WebSocketPartialFrame(); | |
68 | |
69 // |header| may be shared among multiple WebSocketPartialFrames. | |
70 scoped_refptr<const WebSocketFrameHeader> header; | |
71 | |
72 // Indicates this part is the last of partial frames. | |
73 bool final_part; | |
74 | |
75 // |data| is always unmasked even if the frame is masked. | |
76 std::vector<char> data; | |
77 }; | |
78 | |
79 } // namespace net | |
80 | |
81 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ | |
OLD | NEW |