[email protected] | 5fe733de | 2009-02-11 18:59:20 | [diff] [blame] | 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_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 5fe733de | 2009-02-11 18:59:20 | [diff] [blame] | 8 | |
| 9 | namespace base { |
| 10 | |
| 11 | // ----------------------------------------------------------------------------- |
| 12 | // We introduct a special structure for file descriptors in order that we are |
| 13 | // able to use template specialisation to special-case their handling. |
[email protected] | 2749885f | 2009-03-05 21:40:11 | [diff] [blame] | 14 | // |
| 15 | // WARNING: (Chromium only) There are subtleties to consider if serialising |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 16 | // these objects over IPC. See comments in ipc/ipc_message_utils.h |
[email protected] | 82e5ee8 | 2009-04-03 02:29:45 | [diff] [blame] | 17 | // above the template specialisation for this structure. |
[email protected] | 5fe733de | 2009-02-11 18:59:20 | [diff] [blame] | 18 | // ----------------------------------------------------------------------------- |
| 19 | struct FileDescriptor { |
| 20 | FileDescriptor() |
| 21 | : fd(-1), |
| 22 | auto_close(false) { } |
| 23 | |
| 24 | FileDescriptor(int ifd, bool iauto_close) |
| 25 | : fd(ifd), |
| 26 | auto_close(iauto_close) { } |
| 27 | |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 28 | bool operator==(const FileDescriptor& other) const { |
| 29 | return (fd == other.fd && auto_close == other.auto_close); |
| 30 | } |
| 31 | |
| 32 | // A comparison operator so that we can use these as keys in a std::map. |
| 33 | bool operator<(const FileDescriptor& other) const { |
| 34 | return other.fd < fd; |
| 35 | } |
| 36 | |
[email protected] | 5fe733de | 2009-02-11 18:59:20 | [diff] [blame] | 37 | int fd; |
| 38 | // If true, this file descriptor should be closed after it has been used. For |
| 39 | // example an IPC system might interpret this flag as indicating that the |
| 40 | // file descriptor it has been given should be closed after use. |
| 41 | bool auto_close; |
| 42 | }; |
| 43 | |
| 44 | } // namespace base |
| 45 | |
| 46 | #endif // BASE_FILE_DESCRIPTOR_POSIX_H_ |