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

Side by Side Diff: net/websockets/websocket_channel.cc

Issue 826973002: replace COMPILE_ASSERT with static_assert in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: apply fixups Created 5 years, 11 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
« no previous file with comments | « net/websockets/websocket_basic_handshake_stream.cc ('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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_channel.h" 5 #include "net/websockets/websocket_channel.h"
6 6
7 #include <limits.h> // for INT_MAX 7 #include <limits.h> // for INT_MAX
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <deque> 10 #include <deque>
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 if (code == kWebSocketErrorNoStatusReceived) { 1059 if (code == kWebSocketErrorNoStatusReceived) {
1060 // Special case: translate kWebSocketErrorNoStatusReceived into a Close 1060 // Special case: translate kWebSocketErrorNoStatusReceived into a Close
1061 // frame with no payload. 1061 // frame with no payload.
1062 DCHECK(reason.empty()); 1062 DCHECK(reason.empty());
1063 body = new IOBuffer(0); 1063 body = new IOBuffer(0);
1064 } else { 1064 } else {
1065 const size_t payload_length = kWebSocketCloseCodeLength + reason.length(); 1065 const size_t payload_length = kWebSocketCloseCodeLength + reason.length();
1066 body = new IOBuffer(payload_length); 1066 body = new IOBuffer(payload_length);
1067 size = payload_length; 1067 size = payload_length;
1068 base::WriteBigEndian(body->data(), code); 1068 base::WriteBigEndian(body->data(), code);
1069 COMPILE_ASSERT(sizeof(code) == kWebSocketCloseCodeLength, 1069 static_assert(sizeof(code) == kWebSocketCloseCodeLength,
1070 they_should_both_be_two); 1070 "they should both be two");
1071 std::copy( 1071 std::copy(
1072 reason.begin(), reason.end(), body->data() + kWebSocketCloseCodeLength); 1072 reason.begin(), reason.end(), body->data() + kWebSocketCloseCodeLength);
1073 } 1073 }
1074 if (SendFrameFromIOBuffer( 1074 if (SendFrameFromIOBuffer(
1075 true, WebSocketFrameHeader::kOpCodeClose, body, size) == 1075 true, WebSocketFrameHeader::kOpCodeClose, body, size) ==
1076 CHANNEL_DELETED) 1076 CHANNEL_DELETED)
1077 return CHANNEL_DELETED; 1077 return CHANNEL_DELETED;
1078 return CHANNEL_ALIVE; 1078 return CHANNEL_ALIVE;
1079 } 1079 }
1080 1080
(...skipping 14 matching lines...) Expand all
1095 << static_cast<int>(buffer->data()[0]) << ")"; 1095 << static_cast<int>(buffer->data()[0]) << ")";
1096 *code = kWebSocketErrorProtocolError; 1096 *code = kWebSocketErrorProtocolError;
1097 *message = 1097 *message =
1098 "Received a broken close frame containing an invalid size body."; 1098 "Received a broken close frame containing an invalid size body.";
1099 return false; 1099 return false;
1100 } 1100 }
1101 1101
1102 const char* data = buffer->data(); 1102 const char* data = buffer->data();
1103 uint16 unchecked_code = 0; 1103 uint16 unchecked_code = 0;
1104 base::ReadBigEndian(data, &unchecked_code); 1104 base::ReadBigEndian(data, &unchecked_code);
1105 COMPILE_ASSERT(sizeof(unchecked_code) == kWebSocketCloseCodeLength, 1105 static_assert(sizeof(unchecked_code) == kWebSocketCloseCodeLength,
1106 they_should_both_be_two_bytes); 1106 "they should both be two bytes");
1107 1107
1108 switch (unchecked_code) { 1108 switch (unchecked_code) {
1109 case kWebSocketErrorNoStatusReceived: 1109 case kWebSocketErrorNoStatusReceived:
1110 case kWebSocketErrorAbnormalClosure: 1110 case kWebSocketErrorAbnormalClosure:
1111 case kWebSocketErrorTlsHandshake: 1111 case kWebSocketErrorTlsHandshake:
1112 *code = kWebSocketErrorProtocolError; 1112 *code = kWebSocketErrorProtocolError;
1113 *message = 1113 *message =
1114 "Received a broken close frame containing a reserved status code."; 1114 "Received a broken close frame containing a reserved status code.";
1115 return false; 1115 return false;
1116 1116
(...skipping 27 matching lines...) Expand all
1144 } 1144 }
1145 1145
1146 void WebSocketChannel::CloseTimeout() { 1146 void WebSocketChannel::CloseTimeout() {
1147 stream_->Close(); 1147 stream_->Close();
1148 SetState(CLOSED); 1148 SetState(CLOSED);
1149 DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""); 1149 DoDropChannel(false, kWebSocketErrorAbnormalClosure, "");
1150 // |this| has been deleted. 1150 // |this| has been deleted.
1151 } 1151 }
1152 1152
1153 } // namespace net 1153 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_basic_handshake_stream.cc ('k') | net/websockets/websocket_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698