Skip to content

Commit a7d186c

Browse files
committedSep 23, 2019
[Host] File::GetWaitableHandle() should call fileno()
If the file has m_stream, it may not have a m_descriptor. GetWaitableHandle() should call GetDescriptor(), which will call fileno(), so it will get waitable descriptor whenever one is available. Patch by: Lawrence D'Anna Differential revision: https://reviews.llvm.org/D67789 llvm-svn: 372644
1 parent 869ef0a commit a7d186c

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed
 

‎lldb/source/Host/common/File.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int File::GetDescriptor() const {
9191
return kInvalidDescriptor;
9292
}
9393

94-
IOObject::WaitableHandle File::GetWaitableHandle() { return m_descriptor; }
94+
IOObject::WaitableHandle File::GetWaitableHandle() { return GetDescriptor(); }
9595

9696
void File::SetDescriptor(int fd, bool transfer_ownership) {
9797
if (IsValid())

‎lldb/unittests/Host/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set (FILES
22
ConnectionFileDescriptorTest.cpp
33
FileActionTest.cpp
44
FileSystemTest.cpp
5+
FileTest.cpp
56
HostInfoTest.cpp
67
HostTest.cpp
78
MainLoopTest.cpp

‎lldb/unittests/Host/FileTest.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- FileTest.cpp --------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "lldb/Host/File.h"
10+
#include "llvm/ADT/SmallString.h"
11+
#include "llvm/Support/FileSystem.h"
12+
#include "llvm/Support/FileUtilities.h"
13+
#include "llvm/Support/Path.h"
14+
#include "llvm/Support/Program.h"
15+
#include "gtest/gtest.h"
16+
17+
using namespace lldb;
18+
using namespace lldb_private;
19+
20+
TEST(File, GetWaitableHandleFileno) {
21+
const auto *Info = testing::UnitTest::GetInstance()->current_test_info();
22+
23+
llvm::SmallString<128> name;
24+
int fd;
25+
llvm::sys::fs::createTemporaryFile(llvm::Twine(Info->test_case_name()) + "-" +
26+
Info->name(),
27+
"test", fd, name);
28+
llvm::FileRemover remover(name);
29+
ASSERT_GE(fd, 0);
30+
31+
FILE *stream = fdopen(fd, "r");
32+
ASSERT_TRUE(stream);
33+
34+
File file(stream, true);
35+
EXPECT_EQ(file.GetWaitableHandle(), fd);
36+
}

0 commit comments

Comments
 (0)
Please sign in to comment.