| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <poll.h> | 7 #include <poll.h> |
| 8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/time.h> | 10 #include <sys/time.h> |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 299 |
| 300 // Send a message from the client to the server. | 300 // Send a message from the client to the server. |
| 301 ssize_t ret = HANDLE_EINTR(send(sock, kMsg, sizeof(kMsg), 0)); | 301 ssize_t ret = HANDLE_EINTR(send(sock, kMsg, sizeof(kMsg), 0)); |
| 302 ASSERT_NE(-1, ret); | 302 ASSERT_NE(-1, ret); |
| 303 ASSERT_EQ(sizeof(kMsg), static_cast<size_t>(ret)); | 303 ASSERT_EQ(sizeof(kMsg), static_cast<size_t>(ret)); |
| 304 event = event_manager_->WaitForEvent(); | 304 event = event_manager_->WaitForEvent(); |
| 305 ASSERT_EQ(EVENT_READ, event); | 305 ASSERT_EQ(EVENT_READ, event); |
| 306 ASSERT_EQ(kMsg, socket_delegate_->ReceivedData()); | 306 ASSERT_EQ(kMsg, socket_delegate_->ReceivedData()); |
| 307 | 307 |
| 308 // Close the client socket. | 308 // Close the client socket. |
| 309 ret = HANDLE_EINTR(close(sock)); | 309 ret = IGNORE_EINTR(close(sock)); |
| 310 event = event_manager_->WaitForEvent(); | 310 event = event_manager_->WaitForEvent(); |
| 311 ASSERT_EQ(EVENT_CLOSE, event); | 311 ASSERT_EQ(EVENT_CLOSE, event); |
| 312 } | 312 } |
| 313 | 313 |
| 314 TEST_F(UnixDomainSocketTestWithForbiddenUser, TestWithForbiddenUser) { | 314 TEST_F(UnixDomainSocketTestWithForbiddenUser, TestWithForbiddenUser) { |
| 315 const scoped_ptr<base::Thread> server_thread = CreateAndRunServerThread(); | 315 const scoped_ptr<base::Thread> server_thread = CreateAndRunServerThread(); |
| 316 EventType event = event_manager_->WaitForEvent(); | 316 EventType event = event_manager_->WaitForEvent(); |
| 317 ASSERT_EQ(EVENT_LISTEN, event); | 317 ASSERT_EQ(EVENT_LISTEN, event); |
| 318 const SocketDescriptor sock = CreateClientSocket(); | 318 const SocketDescriptor sock = CreateClientSocket(); |
| 319 ASSERT_NE(kInvalidSocket, sock); | 319 ASSERT_NE(kInvalidSocket, sock); |
| 320 | 320 |
| 321 event = event_manager_->WaitForEvent(); | 321 event = event_manager_->WaitForEvent(); |
| 322 ASSERT_EQ(EVENT_AUTH_DENIED, event); | 322 ASSERT_EQ(EVENT_AUTH_DENIED, event); |
| 323 | 323 |
| 324 // Wait until the file descriptor is closed by the server. | 324 // Wait until the file descriptor is closed by the server. |
| 325 struct pollfd poll_fd; | 325 struct pollfd poll_fd; |
| 326 poll_fd.fd = sock; | 326 poll_fd.fd = sock; |
| 327 poll_fd.events = POLLIN; | 327 poll_fd.events = POLLIN; |
| 328 poll(&poll_fd, 1, -1 /* rely on GTest for timeout handling */); | 328 poll(&poll_fd, 1, -1 /* rely on GTest for timeout handling */); |
| 329 | 329 |
| 330 // Send() must fail. | 330 // Send() must fail. |
| 331 ssize_t ret = HANDLE_EINTR(send(sock, kMsg, sizeof(kMsg), 0)); | 331 ssize_t ret = HANDLE_EINTR(send(sock, kMsg, sizeof(kMsg), 0)); |
| 332 ASSERT_EQ(-1, ret); | 332 ASSERT_EQ(-1, ret); |
| 333 ASSERT_EQ(EPIPE, errno); | 333 ASSERT_EQ(EPIPE, errno); |
| 334 ASSERT_FALSE(event_manager_->HasPendingEvent()); | 334 ASSERT_FALSE(event_manager_->HasPendingEvent()); |
| 335 } | 335 } |
| 336 | 336 |
| 337 } // namespace | 337 } // namespace |
| 338 } // namespace net | 338 } // namespace net |
| OLD | NEW |