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/process/process_handle.h" | |
13 | 14 |
14 class Pickle; | 15 class Pickle; |
15 | 16 |
16 class BASE_EXPORT UnixDomainSocket { | 17 class BASE_EXPORT UnixDomainSocket { |
17 public: | 18 public: |
18 // Maximum number of file descriptors that can be read by RecvMsg(). | 19 // Maximum number of file descriptors that can be read by RecvMsg(). |
19 static const size_t kMaxFileDescriptors; | 20 static const size_t kMaxFileDescriptors; |
20 | 21 |
22 // Use to enable receiving pids in RecvMsg. Returns true if successful. | |
23 static bool EnableReceiveProcessId(int fd); | |
jln (very slow on Chromium)
2014/04/24 18:32:58
Perhaps make it clear that this should be used on
mdempsky
2014/04/24 19:00:34
Done.
| |
24 | |
21 // Use sendmsg to write the given msg and include a vector of file | 25 // Use sendmsg to write the given msg and include a vector of file |
22 // descriptors. Returns true if successful. | 26 // descriptors. Returns true if successful. |
23 static bool SendMsg(int fd, | 27 static bool SendMsg(int fd, |
24 const void* msg, | 28 const void* msg, |
25 size_t length, | 29 size_t length, |
26 const std::vector<int>& fds); | 30 const std::vector<int>& fds); |
27 | 31 |
28 // Use recvmsg to read a message and an array of file descriptors. Returns | 32 // Use recvmsg to read a message and an array of file descriptors. Returns |
29 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors. | 33 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors. |
30 static ssize_t RecvMsg(int fd, | 34 static ssize_t RecvMsg(int fd, |
31 void* msg, | 35 void* msg, |
32 size_t length, | 36 size_t length, |
33 std::vector<int>* fds); | 37 std::vector<int>* fds); |
34 | 38 |
39 // Same as RecvMsg above, but also returns the sender's PID (as seen from | |
40 // the caller's namespace). However, before using this function to receive | |
41 // PIDs, EnableReceiveProcessId() should be called on the socket. | |
42 static ssize_t RecvMsgWithPid(int fd, | |
43 void* msg, | |
44 size_t length, | |
45 std::vector<int>* fds, | |
46 base::ProcessId* pid); | |
47 | |
35 // Perform a sendmsg/recvmsg pair. | 48 // Perform a sendmsg/recvmsg pair. |
36 // 1. This process creates a UNIX SEQPACKET socketpair. Using | 49 // 1. This process creates a UNIX SEQPACKET socketpair. Using |
37 // connection-oriented sockets (SEQPACKET or STREAM) is critical here, | 50 // connection-oriented sockets (SEQPACKET or STREAM) is critical here, |
38 // because if one of the ends closes the other one must be notified. | 51 // because if one of the ends closes the other one must be notified. |
39 // 2. This process writes a request to |fd| with an SCM_RIGHTS control | 52 // 2. This process writes a request to |fd| with an SCM_RIGHTS control |
40 // message containing on end of the fresh socket pair. | 53 // message containing on end of the fresh socket pair. |
41 // 3. This process blocks reading from the other end of the fresh | 54 // 3. This process blocks reading from the other end of the fresh |
42 // socketpair. | 55 // socketpair. |
43 // 4. The target process receives the request, processes it and writes the | 56 // 4. The target process receives the request, processes it and writes the |
44 // reply to the end of the socketpair contained in the request. | 57 // reply to the end of the socketpair contained in the request. |
(...skipping 18 matching lines...) Expand all Loading... | |
63 unsigned reply_len, | 76 unsigned reply_len, |
64 int recvmsg_flags, | 77 int recvmsg_flags, |
65 int* result_fd, | 78 int* result_fd, |
66 const Pickle& request); | 79 const Pickle& request); |
67 private: | 80 private: |
68 // Similar to RecvMsg, but allows to specify |flags| for recvmsg(2). | 81 // Similar to RecvMsg, but allows to specify |flags| for recvmsg(2). |
69 static ssize_t RecvMsgWithFlags(int fd, | 82 static ssize_t RecvMsgWithFlags(int fd, |
70 void* msg, | 83 void* msg, |
71 size_t length, | 84 size_t length, |
72 int flags, | 85 int flags, |
73 std::vector<int>* fds); | 86 std::vector<int>* fds, |
87 base::ProcessId* pid); | |
jln (very slow on Chromium)
2014/04/24 18:32:58
You didn't have to modify any caller? I was pretty
mdempsky
2014/04/24 19:00:34
It has 'private' visibility, so it's only used wit
| |
74 }; | 88 }; |
75 | 89 |
76 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ | 90 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ |
OLD | NEW |