| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #ifndef BASE_FILE_DESCRIPTOR_POSIX_H_ | 5 #ifndef BASE_FILE_DESCRIPTOR_POSIX_H_ |
| 6 #define BASE_FILE_DESCRIPTOR_POSIX_H_ | 6 #define BASE_FILE_DESCRIPTOR_POSIX_H_ |
| 7 | 7 |
| 8 #include "base/files/file.h" |
| 9 |
| 8 namespace base { | 10 namespace base { |
| 9 | 11 |
| 10 // ----------------------------------------------------------------------------- | 12 // ----------------------------------------------------------------------------- |
| 11 // We introduct a special structure for file descriptors in order that we are | 13 // We introduct a special structure for file descriptors in order that we are |
| 12 // able to use template specialisation to special-case their handling. | 14 // able to use template specialisation to special-case their handling. |
| 13 // | 15 // |
| 14 // WARNING: (Chromium only) There are subtleties to consider if serialising | 16 // WARNING: (Chromium only) There are subtleties to consider if serialising |
| 15 // these objects over IPC. See comments in ipc/ipc_message_utils.h | 17 // these objects over IPC. See comments in ipc/ipc_message_utils.h |
| 16 // above the template specialisation for this structure. | 18 // above the template specialisation for this structure. |
| 17 // ----------------------------------------------------------------------------- | 19 // ----------------------------------------------------------------------------- |
| 18 struct FileDescriptor { | 20 struct FileDescriptor { |
| 19 FileDescriptor() | 21 FileDescriptor() : fd(-1), auto_close(false) {} |
| 20 : fd(-1), | |
| 21 auto_close(false) { } | |
| 22 | 22 |
| 23 FileDescriptor(int ifd, bool iauto_close) | 23 FileDescriptor(int ifd, bool iauto_close) : fd(ifd), auto_close(iauto_close) { |
| 24 : fd(ifd), | 24 } |
| 25 auto_close(iauto_close) { } | 25 |
| 26 FileDescriptor(File file) : fd(file.TakePlatformFile()), auto_close(true) {} |
| 26 | 27 |
| 27 bool operator==(const FileDescriptor& other) const { | 28 bool operator==(const FileDescriptor& other) const { |
| 28 return (fd == other.fd && auto_close == other.auto_close); | 29 return (fd == other.fd && auto_close == other.auto_close); |
| 29 } | 30 } |
| 30 | 31 |
| 31 // A comparison operator so that we can use these as keys in a std::map. | 32 // A comparison operator so that we can use these as keys in a std::map. |
| 32 bool operator<(const FileDescriptor& other) const { | 33 bool operator<(const FileDescriptor& other) const { |
| 33 return other.fd < fd; | 34 return other.fd < fd; |
| 34 } | 35 } |
| 35 | 36 |
| 36 int fd; | 37 int fd; |
| 37 // If true, this file descriptor should be closed after it has been used. For | 38 // If true, this file descriptor should be closed after it has been used. For |
| 38 // example an IPC system might interpret this flag as indicating that the | 39 // example an IPC system might interpret this flag as indicating that the |
| 39 // file descriptor it has been given should be closed after use. | 40 // file descriptor it has been given should be closed after use. |
| 40 bool auto_close; | 41 bool auto_close; |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 } // namespace base | 44 } // namespace base |
| 44 | 45 |
| 45 #endif // BASE_FILE_DESCRIPTOR_POSIX_H_ | 46 #endif // BASE_FILE_DESCRIPTOR_POSIX_H_ |
| OLD | NEW |