| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ | 5 #ifndef BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ |
| 6 #define BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ | 6 #define BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
| 13 #include "base/files/scoped_file.h" | 13 #include "base/files/scoped_file.h" |
| 14 #include "base/memory/scoped_vector.h" | |
| 15 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
| 16 | 15 |
| 17 namespace base { | 16 namespace base { |
| 18 | 17 |
| 19 class Pickle; | 18 class Pickle; |
| 20 | 19 |
| 21 class BASE_EXPORT UnixDomainSocket { | 20 class BASE_EXPORT UnixDomainSocket { |
| 22 public: | 21 public: |
| 23 // Maximum number of file descriptors that can be read by RecvMsg(). | 22 // Maximum number of file descriptors that can be read by RecvMsg(). |
| 24 static const size_t kMaxFileDescriptors; | 23 static const size_t kMaxFileDescriptors; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 static bool SendMsg(int fd, | 34 static bool SendMsg(int fd, |
| 36 const void* msg, | 35 const void* msg, |
| 37 size_t length, | 36 size_t length, |
| 38 const std::vector<int>& fds); | 37 const std::vector<int>& fds); |
| 39 | 38 |
| 40 // Use recvmsg to read a message and an array of file descriptors. Returns | 39 // Use recvmsg to read a message and an array of file descriptors. Returns |
| 41 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors. | 40 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors. |
| 42 static ssize_t RecvMsg(int fd, | 41 static ssize_t RecvMsg(int fd, |
| 43 void* msg, | 42 void* msg, |
| 44 size_t length, | 43 size_t length, |
| 45 ScopedVector<ScopedFD>* fds); | 44 std::vector<ScopedFD>* fds); |
| 46 | 45 |
| 47 // Same as RecvMsg above, but also returns the sender's process ID (as seen | 46 // Same as RecvMsg above, but also returns the sender's process ID (as seen |
| 48 // from the caller's namespace). However, before using this function to | 47 // from the caller's namespace). However, before using this function to |
| 49 // receive process IDs, EnableReceiveProcessId() should be called on the | 48 // receive process IDs, EnableReceiveProcessId() should be called on the |
| 50 // receiving socket. | 49 // receiving socket. |
| 51 static ssize_t RecvMsgWithPid(int fd, | 50 static ssize_t RecvMsgWithPid(int fd, |
| 52 void* msg, | 51 void* msg, |
| 53 size_t length, | 52 size_t length, |
| 54 ScopedVector<ScopedFD>* fds, | 53 std::vector<ScopedFD>* fds, |
| 55 ProcessId* pid); | 54 ProcessId* pid); |
| 56 | 55 |
| 57 #if !defined(OS_NACL_NONSFI) | 56 #if !defined(OS_NACL_NONSFI) |
| 58 // Perform a sendmsg/recvmsg pair. | 57 // Perform a sendmsg/recvmsg pair. |
| 59 // 1. This process creates a UNIX SEQPACKET socketpair. Using | 58 // 1. This process creates a UNIX SEQPACKET socketpair. Using |
| 60 // connection-oriented sockets (SEQPACKET or STREAM) is critical here, | 59 // connection-oriented sockets (SEQPACKET or STREAM) is critical here, |
| 61 // because if one of the ends closes the other one must be notified. | 60 // because if one of the ends closes the other one must be notified. |
| 62 // 2. This process writes a request to |fd| with an SCM_RIGHTS control | 61 // 2. This process writes a request to |fd| with an SCM_RIGHTS control |
| 63 // message containing on end of the fresh socket pair. | 62 // message containing on end of the fresh socket pair. |
| 64 // 3. This process blocks reading from the other end of the fresh | 63 // 3. This process blocks reading from the other end of the fresh |
| (...skipping 22 matching lines...) Expand all Loading... |
| 87 int recvmsg_flags, | 86 int recvmsg_flags, |
| 88 int* result_fd, | 87 int* result_fd, |
| 89 const Pickle& request); | 88 const Pickle& request); |
| 90 #endif // !defined(OS_NACL_NONSFI) | 89 #endif // !defined(OS_NACL_NONSFI) |
| 91 private: | 90 private: |
| 92 // Similar to RecvMsg, but allows to specify |flags| for recvmsg(2). | 91 // Similar to RecvMsg, but allows to specify |flags| for recvmsg(2). |
| 93 static ssize_t RecvMsgWithFlags(int fd, | 92 static ssize_t RecvMsgWithFlags(int fd, |
| 94 void* msg, | 93 void* msg, |
| 95 size_t length, | 94 size_t length, |
| 96 int flags, | 95 int flags, |
| 97 ScopedVector<ScopedFD>* fds, | 96 std::vector<ScopedFD>* fds, |
| 98 ProcessId* pid); | 97 ProcessId* pid); |
| 99 }; | 98 }; |
| 100 | 99 |
| 101 } // namespace base | 100 } // namespace base |
| 102 | 101 |
| 103 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ | 102 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ |
| OLD | NEW |