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