OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/websockets/websocket_frame.h" | 5 #include "net/websockets/websocket_frame.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 DCHECK_GE(data_size, 0); | 172 DCHECK_GE(data_size, 0); |
173 | 173 |
174 // Most of the masking is done one word at a time, except for the beginning | 174 // Most of the masking is done one word at a time, except for the beginning |
175 // and the end of the buffer which may be unaligned. We use size_t to get the | 175 // and the end of the buffer which may be unaligned. We use size_t to get the |
176 // word size for this architecture. We require it be a multiple of | 176 // word size for this architecture. We require it be a multiple of |
177 // kMaskingKeyLength in size. | 177 // kMaskingKeyLength in size. |
178 typedef size_t PackedMaskType; | 178 typedef size_t PackedMaskType; |
179 PackedMaskType packed_mask_key = 0; | 179 PackedMaskType packed_mask_key = 0; |
180 static const size_t kPackedMaskKeySize = sizeof(packed_mask_key); | 180 static const size_t kPackedMaskKeySize = sizeof(packed_mask_key); |
181 COMPILE_ASSERT((kPackedMaskKeySize >= kMaskingKeyLength && | 181 static_assert((kPackedMaskKeySize >= kMaskingKeyLength && |
182 kPackedMaskKeySize % kMaskingKeyLength == 0), | 182 kPackedMaskKeySize % kMaskingKeyLength == 0), |
183 word_size_is_not_multiple_of_mask_length); | 183 "word size is not a multiple of mask length"); |
184 char* const end = data + data_size; | 184 char* const end = data + data_size; |
185 // If the buffer is too small for the vectorised version to be useful, revert | 185 // If the buffer is too small for the vectorised version to be useful, revert |
186 // to the byte-at-a-time implementation early. | 186 // to the byte-at-a-time implementation early. |
187 if (data_size <= static_cast<int>(kPackedMaskKeySize * 2)) { | 187 if (data_size <= static_cast<int>(kPackedMaskKeySize * 2)) { |
188 MaskWebSocketFramePayloadByBytes( | 188 MaskWebSocketFramePayloadByBytes( |
189 masking_key, frame_offset % kMaskingKeyLength, data, end); | 189 masking_key, frame_offset % kMaskingKeyLength, data, end); |
190 return; | 190 return; |
191 } | 191 } |
192 const size_t data_modulus = | 192 const size_t data_modulus = |
193 reinterpret_cast<size_t>(data) % kPackedMaskKeySize; | 193 reinterpret_cast<size_t>(data) % kPackedMaskKeySize; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 230 } |
231 | 231 |
232 MaskWebSocketFramePayloadByBytes( | 232 MaskWebSocketFramePayloadByBytes( |
233 masking_key, | 233 masking_key, |
234 (frame_offset + (aligned_end - data)) % kMaskingKeyLength, | 234 (frame_offset + (aligned_end - data)) % kMaskingKeyLength, |
235 aligned_end, | 235 aligned_end, |
236 end); | 236 end); |
237 } | 237 } |
238 | 238 |
239 } // namespace net | 239 } // namespace net |
OLD | NEW |