OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |