MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetOpenFileDescriptors

Function GetOpenFileDescriptors

src/leveldb/util/env_posix_test.cc:88–104  ·  view source on GitHub ↗

Iterates through all possible FDs and returns the currently open ones. Returns void so the implementation can use ASSERT_EQ.

Source from the content-addressed store, hash-verified

86//
87// Returns void so the implementation can use ASSERT_EQ.
88void GetOpenFileDescriptors(std::unordered_set<int>* open_fds) {
89 int max_fd = 0;
90 GetMaxFileDescriptor(&max_fd);
91
92 for (int fd = 0; fd < max_fd; ++fd) {
93 if (::dup2(fd, fd) != fd) {
94 // When given the same file descriptor twice, dup2() returns -1 if the
95 // file descriptor is closed, or the given file descriptor if it is open.
96 //
97 // Double-check that dup2() is saying the fd is closed.
98 ASSERT_EQ(EBADF, errno)
99 << "dup2() should set errno to EBADF on closed file descriptors";
100 continue;
101 }
102 open_fds->insert(fd);
103 }
104}
105
106// Finds an FD open since a previous call to GetOpenFileDescriptors().
107//

Callers 2

TESTFunction · 0.85

Calls 2

GetMaxFileDescriptorFunction · 0.85
insertMethod · 0.45

Tested by

no test coverage detected