Skip to content

Commit 58eb339

Browse files
committed
add Pair typedef
1 parent 54ef8f5 commit 58eb339

File tree

8 files changed

+36
-40
lines changed

8 files changed

+36
-40
lines changed

lldb/include/lldb/Host/Socket.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class Socket : public IOObject {
106106
static std::unique_ptr<Socket> Create(const SocketProtocol protocol,
107107
Status &error);
108108

109-
static llvm::Expected<
110-
std::pair<std::unique_ptr<Socket>, std::unique_ptr<Socket>>>
109+
using Pair = std::pair<std::unique_ptr<Socket>, std::unique_ptr<Socket>>;
110+
static llvm::Expected<Pair>
111111
CreatePair(std::optional<SocketProtocol> protocol = std::nullopt);
112112

113113
virtual Status Connect(llvm::StringRef name) = 0;

lldb/include/lldb/Host/common/TCPSocket.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class TCPSocket : public Socket {
2323
TCPSocket(NativeSocket socket, bool should_close);
2424
~TCPSocket() override;
2525

26-
static llvm::Expected<
27-
std::pair<std::unique_ptr<TCPSocket>, std::unique_ptr<TCPSocket>>>
28-
CreatePair();
26+
using Pair =
27+
std::pair<std::unique_ptr<TCPSocket>, std::unique_ptr<TCPSocket>>;
28+
static llvm::Expected<Pair> CreatePair();
2929

3030
// returns port number or 0 if error
3131
uint16_t GetLocalPortNumber() const;

lldb/include/lldb/Host/posix/DomainSocket.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class DomainSocket : public Socket {
1919
DomainSocket(NativeSocket socket, bool should_close);
2020
explicit DomainSocket(bool should_close);
2121

22-
static llvm::Expected<
23-
std::pair<std::unique_ptr<DomainSocket>, std::unique_ptr<DomainSocket>>>
24-
CreatePair();
22+
using Pair =
23+
std::pair<std::unique_ptr<DomainSocket>, std::unique_ptr<DomainSocket>>;
24+
static llvm::Expected<Pair> CreatePair();
2525

2626
Status Connect(llvm::StringRef name) override;
2727
Status Listen(llvm::StringRef name, int backlog) override;

lldb/source/Host/common/Socket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ std::unique_ptr<Socket> Socket::Create(const SocketProtocol protocol,
234234
return socket_up;
235235
}
236236

237-
llvm::Expected<std::pair<std::unique_ptr<Socket>, std::unique_ptr<Socket>>>
237+
llvm::Expected<Socket::Pair>
238238
Socket::CreatePair(std::optional<SocketProtocol> protocol) {
239239
constexpr SocketProtocol kBestProtocol =
240240
LLDB_ENABLE_POSIX ? ProtocolUnixDomain : ProtocolTcp;

lldb/source/Host/common/TCPSocket.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ TCPSocket::TCPSocket(NativeSocket socket, bool should_close)
5252

5353
TCPSocket::~TCPSocket() { CloseListenSockets(); }
5454

55-
llvm::Expected<
56-
std::pair<std::unique_ptr<TCPSocket>, std::unique_ptr<TCPSocket>>>
57-
TCPSocket::CreatePair() {
55+
llvm::Expected<TCPSocket::Pair> TCPSocket::CreatePair() {
5856
auto listen_socket_up = std::make_unique<TCPSocket>(true);
5957
if (Status error = listen_socket_up->Listen("localhost:0", 5); error.Fail())
6058
return error.takeError();
@@ -75,7 +73,7 @@ TCPSocket::CreatePair() {
7573
error.Fail())
7674
return error.takeError();
7775

78-
return std::make_pair(
76+
return Pair(
7977
std::move(connect_socket_up),
8078
std::unique_ptr<TCPSocket>(static_cast<TCPSocket *>(accept_socket)));
8179
}

lldb/source/Host/posix/DomainSocket.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ DomainSocket::DomainSocket(SocketProtocol protocol, NativeSocket socket,
7878
m_socket = socket;
7979
}
8080

81-
llvm::Expected<
82-
std::pair<std::unique_ptr<DomainSocket>, std::unique_ptr<DomainSocket>>>
83-
DomainSocket::CreatePair() {
81+
llvm::Expected<DomainSocket::Pair> DomainSocket::CreatePair() {
8482
int sockets[2];
8583
int type = SOCK_STREAM;
8684
#ifdef SOCK_CLOEXEC
@@ -97,12 +95,12 @@ DomainSocket::CreatePair() {
9795
}
9896
#endif
9997

100-
return std::make_pair(std::unique_ptr<DomainSocket>(
101-
new DomainSocket(ProtocolUnixDomain, sockets[0],
102-
/*should_close=*/true)),
103-
std::unique_ptr<DomainSocket>(
104-
new DomainSocket(ProtocolUnixDomain, sockets[1],
105-
/*should_close=*/true)));
98+
return Pair(std::unique_ptr<DomainSocket>(
99+
new DomainSocket(ProtocolUnixDomain, sockets[0],
100+
/*should_close=*/true)),
101+
std::unique_ptr<DomainSocket>(
102+
new DomainSocket(ProtocolUnixDomain, sockets[1],
103+
/*should_close=*/true)));
106104
}
107105

108106
Status DomainSocket::Connect(llvm::StringRef name) {

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,14 +1141,14 @@ void GDBRemoteCommunication::DumpHistory(Stream &strm) { m_history.Dump(strm); }
11411141
llvm::Error
11421142
GDBRemoteCommunication::ConnectLocally(GDBRemoteCommunication &client,
11431143
GDBRemoteCommunication &server) {
1144-
auto expected_socket_pair = Socket::CreatePair();
1145-
if (!expected_socket_pair)
1146-
return expected_socket_pair.takeError();
1147-
1148-
client.SetConnection(std::make_unique<ConnectionFileDescriptor>(
1149-
expected_socket_pair->first.release()));
1150-
server.SetConnection(std::make_unique<ConnectionFileDescriptor>(
1151-
expected_socket_pair->second.release()));
1144+
llvm::Expected<Socket::Pair> pair = Socket::CreatePair();
1145+
if (!pair)
1146+
return pair.takeError();
1147+
1148+
client.SetConnection(
1149+
std::make_unique<ConnectionFileDescriptor>(pair->first.release()));
1150+
server.SetConnection(
1151+
std::make_unique<ConnectionFileDescriptor>(pair->second.release()));
11521152
return llvm::Error::success();
11531153
}
11541154

lldb/unittests/Core/CommunicationTest.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ class CommunicationTest : public testing::Test {
3131
};
3232

3333
static void CommunicationReadTest(bool use_read_thread) {
34-
auto maybe_socket_pair = Socket::CreatePair();
35-
ASSERT_THAT_EXPECTED(maybe_socket_pair, llvm::Succeeded());
36-
Socket &a = *maybe_socket_pair->first;
34+
llvm::Expected<Socket::Pair> pair = Socket::CreatePair();
35+
ASSERT_THAT_EXPECTED(pair, llvm::Succeeded());
36+
Socket &a = *pair->first;
3737

3838
size_t num_bytes = 4;
3939
ASSERT_THAT_ERROR(a.Write("test", num_bytes).ToError(), llvm::Succeeded());
4040
ASSERT_EQ(num_bytes, 4U);
4141

4242
ThreadedCommunication comm("test");
43-
comm.SetConnection(std::make_unique<ConnectionFileDescriptor>(
44-
maybe_socket_pair->second.release()));
43+
comm.SetConnection(
44+
std::make_unique<ConnectionFileDescriptor>(pair->second.release()));
4545
comm.SetCloseOnEOF(true);
4646

4747
if (use_read_thread) {
@@ -120,13 +120,13 @@ TEST_F(CommunicationTest, ReadThread) {
120120
}
121121

122122
TEST_F(CommunicationTest, SynchronizeWhileClosing) {
123-
auto maybe_socket_pair = Socket::CreatePair();
124-
ASSERT_THAT_EXPECTED(maybe_socket_pair, llvm::Succeeded());
125-
Socket &a = *maybe_socket_pair->first;
123+
llvm::Expected<Socket::Pair> pair = Socket::CreatePair();
124+
ASSERT_THAT_EXPECTED(pair, llvm::Succeeded());
125+
Socket &a = *pair->first;
126126

127127
ThreadedCommunication comm("test");
128-
comm.SetConnection(std::make_unique<ConnectionFileDescriptor>(
129-
maybe_socket_pair->second.release()));
128+
comm.SetConnection(
129+
std::make_unique<ConnectionFileDescriptor>(pair->second.release()));
130130
comm.SetCloseOnEOF(true);
131131
ASSERT_TRUE(comm.StartReadThread());
132132

0 commit comments

Comments
 (0)