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 IPC_FILE_DESCRIPTOR_SET_POSIX_H_ | 5 #ifndef IPC_FILE_DESCRIPTOR_SET_POSIX_H_ |
6 #define IPC_FILE_DESCRIPTOR_SET_POSIX_H_ | 6 #define IPC_FILE_DESCRIPTOR_SET_POSIX_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/file_descriptor_posix.h" | 11 #include "base/file_descriptor_posix.h" |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 | 13 |
14 // ----------------------------------------------------------------------------- | 14 // ----------------------------------------------------------------------------- |
15 // A FileDescriptorSet is an ordered set of POSIX file descriptors. These are | 15 // A FileDescriptorSet is an ordered set of POSIX file descriptors. These are |
16 // associated with IPC messages so that descriptors can be transmitted over a | 16 // associated with IPC messages so that descriptors can be transmitted over a |
17 // UNIX domain socket. | 17 // UNIX domain socket. |
18 // ----------------------------------------------------------------------------- | 18 // ----------------------------------------------------------------------------- |
19 class FileDescriptorSet : public base::RefCountedThreadSafe<FileDescriptorSet> { | 19 class FileDescriptorSet : public base::RefCountedThreadSafe<FileDescriptorSet> { |
20 public: | 20 public: |
21 FileDescriptorSet(); | 21 FileDescriptorSet(); |
22 ~FileDescriptorSet(); | |
23 | 22 |
24 // This is the maximum number of descriptors per message. We need to know this | 23 // This is the maximum number of descriptors per message. We need to know this |
25 // because the control message kernel interface has to be given a buffer which | 24 // because the control message kernel interface has to be given a buffer which |
26 // is large enough to store all the descriptor numbers. Otherwise the kernel | 25 // is large enough to store all the descriptor numbers. Otherwise the kernel |
27 // tells us that it truncated the control data and the extra descriptors are | 26 // tells us that it truncated the control data and the extra descriptors are |
28 // lost. | 27 // lost. |
29 // | 28 // |
30 // In debugging mode, it's a fatal error to try and add more than this number | 29 // In debugging mode, it's a fatal error to try and add more than this number |
31 // of descriptors to a FileDescriptorSet. | 30 // of descriptors to a FileDescriptorSet. |
32 enum { | 31 enum { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // Interfaces for receiving... | 82 // Interfaces for receiving... |
84 | 83 |
85 // Set the contents of the set from the given buffer. This set must be empty | 84 // Set the contents of the set from the given buffer. This set must be empty |
86 // before calling. The auto-close flag is set on all the descriptors so that | 85 // before calling. The auto-close flag is set on all the descriptors so that |
87 // unconsumed descriptors are closed on destruction. | 86 // unconsumed descriptors are closed on destruction. |
88 void SetDescriptors(const int* buffer, unsigned count); | 87 void SetDescriptors(const int* buffer, unsigned count); |
89 | 88 |
90 // --------------------------------------------------------------------------- | 89 // --------------------------------------------------------------------------- |
91 | 90 |
92 private: | 91 private: |
| 92 friend class base::RefCountedThreadSafe<FileDescriptorSet>; |
| 93 |
| 94 ~FileDescriptorSet(); |
| 95 |
93 // A vector of descriptors and close flags. If this message is sent, then | 96 // A vector of descriptors and close flags. If this message is sent, then |
94 // these descriptors are sent as control data. After sending, any descriptors | 97 // these descriptors are sent as control data. After sending, any descriptors |
95 // with a true flag are closed. If this message has been received, then these | 98 // with a true flag are closed. If this message has been received, then these |
96 // are the descriptors which were received and all close flags are true. | 99 // are the descriptors which were received and all close flags are true. |
97 std::vector<base::FileDescriptor> descriptors_; | 100 std::vector<base::FileDescriptor> descriptors_; |
98 | 101 |
99 // This contains the index of the next descriptor which should be consumed. | 102 // This contains the index of the next descriptor which should be consumed. |
100 // It's used in a couple of ways. Firstly, at destruction we can check that | 103 // It's used in a couple of ways. Firstly, at destruction we can check that |
101 // all the descriptors have been read (with GetNthDescriptor). Secondly, we | 104 // all the descriptors have been read (with GetNthDescriptor). Secondly, we |
102 // can check that they are read in order. | 105 // can check that they are read in order. |
103 mutable unsigned consumed_descriptor_highwater_; | 106 mutable unsigned consumed_descriptor_highwater_; |
104 | 107 |
105 DISALLOW_COPY_AND_ASSIGN(FileDescriptorSet); | 108 DISALLOW_COPY_AND_ASSIGN(FileDescriptorSet); |
106 }; | 109 }; |
107 | 110 |
108 #endif // IPC_FILE_DESCRIPTOR_SET_POSIX_H_ | 111 #endif // IPC_FILE_DESCRIPTOR_SET_POSIX_H_ |
OLD | NEW |