Commit 14ac2486 authored by byungchul's avatar byungchul Committed by Commit bot

Set the internal listen socket only when it opens to socket successfully.

Android devtools tries open socket twice on same UnixDomainServerSocket
instance. Instead of destroying UnixDomainServerSocket instance, not assigning
internal listen socket on socket open error is cheaper and makes more sense.

BUG=408224

Review URL: https://codereview.chromium.org/515653003

Cr-Commit-Position: refs/heads/master@{#292260}
parent c8fa9623
......@@ -63,13 +63,13 @@ int UnixDomainServerSocket::ListenWithAddressAndPort(
return ERR_ADDRESS_INVALID;
}
listen_socket_.reset(new SocketLibevent);
int rv = listen_socket_->Open(AF_UNIX);
scoped_ptr<SocketLibevent> socket(new SocketLibevent);
int rv = socket->Open(AF_UNIX);
DCHECK_NE(ERR_IO_PENDING, rv);
if (rv != OK)
return rv;
rv = listen_socket_->Bind(address);
rv = socket->Bind(address);
DCHECK_NE(ERR_IO_PENDING, rv);
if (rv != OK) {
PLOG(ERROR)
......@@ -78,7 +78,13 @@ int UnixDomainServerSocket::ListenWithAddressAndPort(
return rv;
}
return listen_socket_->Listen(backlog);
rv = socket->Listen(backlog);
DCHECK_NE(ERR_IO_PENDING, rv);
if (rv != OK)
return rv;
listen_socket_.swap(socket);
return rv;
}
int UnixDomainServerSocket::GetLocalAddress(IPEndPoint* address) const {
......
......@@ -71,6 +71,15 @@ TEST_F(UnixDomainServerSocketTest, ListenWithInvalidPathWithAbstractNamespace) {
#endif
}
TEST_F(UnixDomainServerSocketTest, ListenAgainAfterFailureWithInvalidPath) {
const bool kUseAbstractNamespace = false;
UnixDomainServerSocket server_socket(CreateAuthCallback(true),
kUseAbstractNamespace);
EXPECT_EQ(ERR_FILE_NOT_FOUND,
server_socket.ListenWithAddressAndPort(kInvalidSocketPath, 0, 1));
EXPECT_EQ(OK, server_socket.ListenWithAddressAndPort(socket_path_, 0, 1));
}
TEST_F(UnixDomainServerSocketTest, AcceptWithForbiddenUser) {
const bool kUseAbstractNamespace = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment