Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: base/posix/unix_domain_socket_linux_unittest.cc

Issue 276593008: Fix RecvMsgWithPid on broken socket pair (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use DCHECK_GE Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/posix/unix_domain_socket_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <sys/socket.h> 5 #include <sys/socket.h>
6 #include <sys/types.h> 6 #include <sys/types.h>
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 ScopedVector<base::ScopedFD> recv_fds; 127 ScopedVector<base::ScopedFD> recv_fds;
128 const ssize_t nread = UnixDomainSocket::RecvMsgWithPid( 128 const ssize_t nread = UnixDomainSocket::RecvMsgWithPid(
129 recv_sock.get(), buf, sizeof(buf), &recv_fds, &sender_pid); 129 recv_sock.get(), buf, sizeof(buf), &recv_fds, &sender_pid);
130 ASSERT_EQ(sizeof(kHello), static_cast<size_t>(nread)); 130 ASSERT_EQ(sizeof(kHello), static_cast<size_t>(nread));
131 ASSERT_EQ(0, memcmp(buf, kHello, sizeof(kHello))); 131 ASSERT_EQ(0, memcmp(buf, kHello, sizeof(kHello)));
132 ASSERT_EQ(UnixDomainSocket::kMaxFileDescriptors, recv_fds.size()); 132 ASSERT_EQ(UnixDomainSocket::kMaxFileDescriptors, recv_fds.size());
133 133
134 ASSERT_EQ(getpid(), sender_pid); 134 ASSERT_EQ(getpid(), sender_pid);
135 } 135 }
136 136
137 // Check that RecvMsgWithPid doesn't DCHECK fail when reading EOF from a
138 // disconnected socket.
139 TEST(UnixDomianSocketTest, RecvPidDisconnectedSocket) {
140 int fds[2];
141 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds));
142 base::ScopedFD recv_sock(fds[0]);
143 base::ScopedFD send_sock(fds[1]);
144
145 ASSERT_TRUE(UnixDomainSocket::EnableReceiveProcessId(recv_sock.get()));
146
147 send_sock.reset();
148
149 char ch;
150 base::ProcessId sender_pid;
151 ScopedVector<base::ScopedFD> recv_fds;
152 const ssize_t nread = UnixDomainSocket::RecvMsgWithPid(
153 recv_sock.get(), &ch, sizeof(ch), &recv_fds, &sender_pid);
154 ASSERT_EQ(0, nread);
155 ASSERT_EQ(-1, sender_pid);
156 ASSERT_EQ(0U, recv_fds.size());
157 }
158
137 } // namespace 159 } // namespace
138 160
139 } // namespace base 161 } // namespace base
OLDNEW
« no previous file with comments | « base/posix/unix_domain_socket_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698