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" | |
jln (very slow on Chromium)
2014/04/24 19:24:38
You could forward declare base::ProcessId.
mdempsky
2014/04/24 20:23:30
As discussed at lunch, base::ProcessId can't be fo
willchan no longer on Chromium
2014/04/24 20:44:04
I'm fine with including and not forward declaring,
mdempsky
2014/04/24 20:59:14
I think it would be technically okay to use pid_t
willchan no longer on Chromium
2014/04/24 21:09:56
I generally encourage using the cross-platform typ
| |
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 process IDs in RecvMsgWithPid. Should be called on | |
23 // the receiving socket (i.e., the socket passed to RecvMsgWithPid). Returns | |
24 // true if successful. | |
25 static bool EnableReceiveProcessId(int fd); | |
26 | |
21 // Use sendmsg to write the given msg and include a vector of file | 27 // Use sendmsg to write the given msg and include a vector of file |
22 // descriptors. Returns true if successful. | 28 // descriptors. Returns true if successful. |
23 static bool SendMsg(int fd, | 29 static bool SendMsg(int fd, |
24 const void* msg, | 30 const void* msg, |
25 size_t length, | 31 size_t length, |
26 const std::vector<int>& fds); | 32 const std::vector<int>& fds); |
27 | 33 |
28 // Use recvmsg to read a message and an array of file descriptors. Returns | 34 // Use recvmsg to read a message and an array of file descriptors. Returns |
29 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors. | 35 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors. |
30 static ssize_t RecvMsg(int fd, | 36 static ssize_t RecvMsg(int fd, |
31 void* msg, | 37 void* msg, |
32 size_t length, | 38 size_t length, |
33 std::vector<int>* fds); | 39 std::vector<int>* fds); |
34 | 40 |
41 // Same as RecvMsg above, but also returns the sender's process ID (as seen | |
42 // from the caller's namespace). However, before using this function to | |
43 // receive process IDs, EnableReceiveProcessId() should be called on the | |
44 // receiving socket. | |
45 static ssize_t RecvMsgWithPid(int fd, | |
46 void* msg, | |
47 size_t length, | |
48 std::vector<int>* fds, | |
49 base::ProcessId* pid); | |
50 | |
35 // Perform a sendmsg/recvmsg pair. | 51 // Perform a sendmsg/recvmsg pair. |
36 // 1. This process creates a UNIX SEQPACKET socketpair. Using | 52 // 1. This process creates a UNIX SEQPACKET socketpair. Using |
37 // connection-oriented sockets (SEQPACKET or STREAM) is critical here, | 53 // connection-oriented sockets (SEQPACKET or STREAM) is critical here, |
38 // because if one of the ends closes the other one must be notified. | 54 // 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 | 55 // 2. This process writes a request to |fd| with an SCM_RIGHTS control |
40 // message containing on end of the fresh socket pair. | 56 // message containing on end of the fresh socket pair. |
41 // 3. This process blocks reading from the other end of the fresh | 57 // 3. This process blocks reading from the other end of the fresh |
42 // socketpair. | 58 // socketpair. |
43 // 4. The target process receives the request, processes it and writes the | 59 // 4. The target process receives the request, processes it and writes the |
44 // reply to the end of the socketpair contained in the request. | 60 // reply to the end of the socketpair contained in the request. |
(...skipping 18 matching lines...) Expand all Loading... | |
63 unsigned reply_len, | 79 unsigned reply_len, |
64 int recvmsg_flags, | 80 int recvmsg_flags, |
65 int* result_fd, | 81 int* result_fd, |
66 const Pickle& request); | 82 const Pickle& request); |
67 private: | 83 private: |
68 // Similar to RecvMsg, but allows to specify |flags| for recvmsg(2). | 84 // Similar to RecvMsg, but allows to specify |flags| for recvmsg(2). |
69 static ssize_t RecvMsgWithFlags(int fd, | 85 static ssize_t RecvMsgWithFlags(int fd, |
70 void* msg, | 86 void* msg, |
71 size_t length, | 87 size_t length, |
72 int flags, | 88 int flags, |
73 std::vector<int>* fds); | 89 std::vector<int>* fds, |
90 base::ProcessId* pid); | |
74 }; | 91 }; |
75 | 92 |
76 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ | 93 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ |
OLD | NEW |