OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ipc/file_descriptor_set_posix.h" | 5 #include "ipc/file_descriptor_set_posix.h" |
6 | 6 |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 for (std::vector<base::FileDescriptor>::iterator | 119 for (std::vector<base::FileDescriptor>::iterator |
120 i = descriptors_.begin(); i != descriptors_.end(); ++i) { | 120 i = descriptors_.begin(); i != descriptors_.end(); ++i) { |
121 if (i->auto_close) | 121 if (i->auto_close) |
122 if (HANDLE_EINTR(close(i->fd)) < 0) | 122 if (HANDLE_EINTR(close(i->fd)) < 0) |
123 PLOG(ERROR) << "close"; | 123 PLOG(ERROR) << "close"; |
124 } | 124 } |
125 descriptors_.clear(); | 125 descriptors_.clear(); |
126 consumed_descriptor_highwater_ = 0; | 126 consumed_descriptor_highwater_ = 0; |
127 } | 127 } |
128 | 128 |
| 129 void FileDescriptorSet::ReleaseFDsToClose(std::vector<int>* fds) { |
| 130 for (std::vector<base::FileDescriptor>::iterator |
| 131 i = descriptors_.begin(); i != descriptors_.end(); ++i) { |
| 132 if (i->auto_close) |
| 133 fds->push_back(i->fd); |
| 134 } |
| 135 descriptors_.clear(); |
| 136 consumed_descriptor_highwater_ = 0; |
| 137 } |
| 138 |
129 void FileDescriptorSet::SetDescriptors(const int* buffer, unsigned count) { | 139 void FileDescriptorSet::SetDescriptors(const int* buffer, unsigned count) { |
130 DCHECK(count <= kMaxDescriptorsPerMessage); | 140 DCHECK(count <= kMaxDescriptorsPerMessage); |
131 DCHECK_EQ(descriptors_.size(), 0u); | 141 DCHECK_EQ(descriptors_.size(), 0u); |
132 DCHECK_EQ(consumed_descriptor_highwater_, 0u); | 142 DCHECK_EQ(consumed_descriptor_highwater_, 0u); |
133 | 143 |
134 descriptors_.reserve(count); | 144 descriptors_.reserve(count); |
135 for (unsigned i = 0; i < count; ++i) { | 145 for (unsigned i = 0; i < count; ++i) { |
136 struct base::FileDescriptor sd; | 146 struct base::FileDescriptor sd; |
137 sd.fd = buffer[i]; | 147 sd.fd = buffer[i]; |
138 sd.auto_close = true; | 148 sd.auto_close = true; |
139 descriptors_.push_back(sd); | 149 descriptors_.push_back(sd); |
140 } | 150 } |
141 } | 151 } |
OLD | NEW |