| 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 "tools/android/forwarder2/command.h" | 5 #include "tools/android/forwarder2/command.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/safe_strerror_posix.h" | 13 #include "base/posix/safe_strerror.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 16 #include "tools/android/forwarder2/socket.h" | 16 #include "tools/android/forwarder2/socket.h" |
| 17 | 17 |
| 18 using base::StringPiece; | 18 using base::StringPiece; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 | 22 |
| 23 // Command format: | 23 // Command format: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 bool ReadCommand(Socket* socket, | 43 bool ReadCommand(Socket* socket, |
| 44 int* port_out, | 44 int* port_out, |
| 45 command::Type* command_type_out) { | 45 command::Type* command_type_out) { |
| 46 char command_buffer[kCommandStringSize + 1]; | 46 char command_buffer[kCommandStringSize + 1]; |
| 47 // To make logging easier. | 47 // To make logging easier. |
| 48 command_buffer[kCommandStringSize] = '\0'; | 48 command_buffer[kCommandStringSize] = '\0'; |
| 49 | 49 |
| 50 int bytes_read = socket->ReadNumBytes(command_buffer, kCommandStringSize); | 50 int bytes_read = socket->ReadNumBytes(command_buffer, kCommandStringSize); |
| 51 if (bytes_read != kCommandStringSize) { | 51 if (bytes_read != kCommandStringSize) { |
| 52 if (bytes_read < 0) | 52 if (bytes_read < 0) |
| 53 LOG(ERROR) << "Read() error: " << safe_strerror(errno); | 53 LOG(ERROR) << "Read() error: " << base::safe_strerror(errno); |
| 54 else if (!bytes_read) | 54 else if (!bytes_read) |
| 55 LOG(ERROR) << "Read() error, endpoint was unexpectedly closed."; | 55 LOG(ERROR) << "Read() error, endpoint was unexpectedly closed."; |
| 56 else | 56 else |
| 57 LOG(ERROR) << "Read() error, not enough data received from the socket."; | 57 LOG(ERROR) << "Read() error, not enough data received from the socket."; |
| 58 return false; | 58 return false; |
| 59 } | 59 } |
| 60 | 60 |
| 61 StringPiece port_str(command_buffer, kPortStringSize); | 61 StringPiece port_str(command_buffer, kPortStringSize); |
| 62 if (!StringToInt(port_str, port_out)) { | 62 if (!StringToInt(port_str, port_out)) { |
| 63 LOG(ERROR) << "Could not parse the command port string: " | 63 LOG(ERROR) << "Could not parse the command port string: " |
| (...skipping 23 matching lines...) Expand all Loading... |
| 87 | 87 |
| 88 bool ReceivedCommand(command::Type command, Socket* socket) { | 88 bool ReceivedCommand(command::Type command, Socket* socket) { |
| 89 int port; | 89 int port; |
| 90 command::Type received_command; | 90 command::Type received_command; |
| 91 if (!ReadCommand(socket, &port, &received_command)) | 91 if (!ReadCommand(socket, &port, &received_command)) |
| 92 return false; | 92 return false; |
| 93 return received_command == command; | 93 return received_command == command; |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace forwarder | 96 } // namespace forwarder |
| OLD | NEW |