OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "files/public/c/lib/fd_table.h" | 5 #include "files/c/lib/fd_table.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "files/public/c/lib/errno_impl.h" | 12 #include "files/c/lib/errno_impl.h" |
13 #include "mojo/public/cpp/environment/logging.h" | 13 #include "mojo/public/cpp/environment/logging.h" |
14 | 14 |
15 namespace mojio { | 15 namespace mojio { |
16 | 16 |
17 FDTable::FDTable(ErrnoImpl* errno_impl, size_t max_num_fds) | 17 FDTable::FDTable(ErrnoImpl* errno_impl, size_t max_num_fds) |
18 : errno_impl_(errno_impl), table_(max_num_fds) { | 18 : errno_impl_(errno_impl), table_(max_num_fds) { |
19 MOJO_DCHECK(max_num_fds > 0); | 19 MOJO_DCHECK(max_num_fds > 0); |
20 // The index of the last FD has to fit into an |int|. | 20 // The index of the last FD has to fit into an |int|. |
21 MOJO_DCHECK(max_num_fds - 1 <= | 21 MOJO_DCHECK(max_num_fds - 1 <= |
22 static_cast<size_t>(std::numeric_limits<int>::max())); | 22 static_cast<size_t>(std::numeric_limits<int>::max())); |
(...skipping 29 matching lines...) Expand all Loading... |
52 std::unique_ptr<FDImpl> FDTable::Remove(int fd) { | 52 std::unique_ptr<FDImpl> FDTable::Remove(int fd) { |
53 ErrnoImpl::Setter errno_setter(errno_impl_); | 53 ErrnoImpl::Setter errno_setter(errno_impl_); |
54 if (fd < 0 || static_cast<size_t>(fd) >= table_.size() || !table_[fd]) { | 54 if (fd < 0 || static_cast<size_t>(fd) >= table_.size() || !table_[fd]) { |
55 errno_setter.Set(EBADF); | 55 errno_setter.Set(EBADF); |
56 return nullptr; | 56 return nullptr; |
57 } | 57 } |
58 return std::move(table_[fd]); | 58 return std::move(table_[fd]); |
59 } | 59 } |
60 | 60 |
61 } // namespace mojio | 61 } // namespace mojio |
OLD | NEW |