| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/devtools_bridge/socket_tunnel_packet_handler.h" | 5 #include "components/devtools_bridge/socket_tunnel_packet_handler.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "components/devtools_bridge/socket_tunnel_connection.h" | 9 #include "components/devtools_bridge/socket_tunnel_connection.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 HandleProtocolError(); | 34 HandleProtocolError(); |
| 35 return; | 35 return; |
| 36 } | 36 } |
| 37 | 37 |
| 38 int connection_index = connection_id - kMinConnectionId; | 38 int connection_index = connection_id - kMinConnectionId; |
| 39 scoped_refptr<net::IOBufferWithSize> packet( | 39 scoped_refptr<net::IOBufferWithSize> packet( |
| 40 new net::IOBufferWithSize(length - 1)); | 40 new net::IOBufferWithSize(length - 1)); |
| 41 memcpy(packet->data(), bytes + 1, length - 1); | 41 memcpy(packet->data(), bytes + 1, length - 1); |
| 42 HandleDataPacket(connection_index, packet); | 42 HandleDataPacket(connection_index, packet); |
| 43 } else if (length >= kControlPacketSizeBytes) { | 43 } else if (length >= kControlPacketSizeBytes) { |
| 44 COMPILE_ASSERT(kControlPacketSizeBytes == 3, | 44 static_assert(kControlPacketSizeBytes == 3, |
| 45 unexpected_control_packet_size); | 45 "kControlPacketSizeBytes should equal 3"); |
| 46 | 46 |
| 47 int op_code = bytes[1]; | 47 int op_code = bytes[1]; |
| 48 connection_id = bytes[2]; | 48 connection_id = bytes[2]; |
| 49 if (connection_id < kMinConnectionId || | 49 if (connection_id < kMinConnectionId || |
| 50 connection_id > kMaxConnectionId) { | 50 connection_id > kMaxConnectionId) { |
| 51 DLOG(ERROR) << "Invalid connection ID: " << connection_id; | 51 DLOG(ERROR) << "Invalid connection ID: " << connection_id; |
| 52 HandleProtocolError(); | 52 HandleProtocolError(); |
| 53 return; | 53 return; |
| 54 } | 54 } |
| 55 int connection_index = connection_id - kMinConnectionId; | 55 int connection_index = connection_id - kMinConnectionId; |
| 56 HandleControlPacket(connection_index, op_code); | 56 HandleControlPacket(connection_index, op_code); |
| 57 } else { | 57 } else { |
| 58 DLOG(ERROR) << "Invalid packet"; | 58 DLOG(ERROR) << "Invalid packet"; |
| 59 HandleProtocolError(); | 59 HandleProtocolError(); |
| 60 return; | 60 return; |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace devtools_bridge | 64 } // namespace devtools_bridge |
| OLD | NEW |