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

Side by Side Diff: base/posix/unix_domain_socket_linux.h

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 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
« no previous file with comments | « base/posix/safe_strerror.cc ('k') | base/posix/unix_domain_socket_linux.cc » ('j') | 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) 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" 14 #include "base/memory/scoped_vector.h"
15 #include "base/process/process_handle.h" 15 #include "base/process/process_handle.h"
16 16
17 namespace base {
18
17 class Pickle; 19 class Pickle;
18 20
19 class BASE_EXPORT UnixDomainSocket { 21 class BASE_EXPORT UnixDomainSocket {
20 public: 22 public:
21 // Maximum number of file descriptors that can be read by RecvMsg(). 23 // Maximum number of file descriptors that can be read by RecvMsg().
22 static const size_t kMaxFileDescriptors; 24 static const size_t kMaxFileDescriptors;
23 25
24 #if !defined(OS_NACL_NONSFI) 26 #if !defined(OS_NACL_NONSFI)
25 // Use to enable receiving process IDs in RecvMsgWithPid. Should be called on 27 // Use to enable receiving process IDs in RecvMsgWithPid. Should be called on
26 // the receiving socket (i.e., the socket passed to RecvMsgWithPid). Returns 28 // the receiving socket (i.e., the socket passed to RecvMsgWithPid). Returns
27 // true if successful. 29 // true if successful.
28 static bool EnableReceiveProcessId(int fd); 30 static bool EnableReceiveProcessId(int fd);
29 #endif // !defined(OS_NACL_NONSFI) 31 #endif // !defined(OS_NACL_NONSFI)
30 32
31 // Use sendmsg to write the given msg and include a vector of file 33 // Use sendmsg to write the given msg and include a vector of file
32 // descriptors. Returns true if successful. 34 // descriptors. Returns true if successful.
33 static bool SendMsg(int fd, 35 static bool SendMsg(int fd,
34 const void* msg, 36 const void* msg,
35 size_t length, 37 size_t length,
36 const std::vector<int>& fds); 38 const std::vector<int>& fds);
37 39
38 // Use recvmsg to read a message and an array of file descriptors. Returns 40 // Use recvmsg to read a message and an array of file descriptors. Returns
39 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors. 41 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors.
40 static ssize_t RecvMsg(int fd, 42 static ssize_t RecvMsg(int fd,
41 void* msg, 43 void* msg,
42 size_t length, 44 size_t length,
43 ScopedVector<base::ScopedFD>* fds); 45 ScopedVector<ScopedFD>* fds);
44 46
45 // Same as RecvMsg above, but also returns the sender's process ID (as seen 47 // Same as RecvMsg above, but also returns the sender's process ID (as seen
46 // from the caller's namespace). However, before using this function to 48 // from the caller's namespace). However, before using this function to
47 // receive process IDs, EnableReceiveProcessId() should be called on the 49 // receive process IDs, EnableReceiveProcessId() should be called on the
48 // receiving socket. 50 // receiving socket.
49 static ssize_t RecvMsgWithPid(int fd, 51 static ssize_t RecvMsgWithPid(int fd,
50 void* msg, 52 void* msg,
51 size_t length, 53 size_t length,
52 ScopedVector<base::ScopedFD>* fds, 54 ScopedVector<ScopedFD>* fds,
53 base::ProcessId* pid); 55 ProcessId* pid);
54 56
55 #if !defined(OS_NACL_NONSFI) 57 #if !defined(OS_NACL_NONSFI)
56 // Perform a sendmsg/recvmsg pair. 58 // Perform a sendmsg/recvmsg pair.
57 // 1. This process creates a UNIX SEQPACKET socketpair. Using 59 // 1. This process creates a UNIX SEQPACKET socketpair. Using
58 // connection-oriented sockets (SEQPACKET or STREAM) is critical here, 60 // connection-oriented sockets (SEQPACKET or STREAM) is critical here,
59 // because if one of the ends closes the other one must be notified. 61 // because if one of the ends closes the other one must be notified.
60 // 2. This process writes a request to |fd| with an SCM_RIGHTS control 62 // 2. This process writes a request to |fd| with an SCM_RIGHTS control
61 // message containing on end of the fresh socket pair. 63 // message containing on end of the fresh socket pair.
62 // 3. This process blocks reading from the other end of the fresh 64 // 3. This process blocks reading from the other end of the fresh
63 // socketpair. 65 // socketpair.
(...skipping 21 matching lines...) Expand all
85 int recvmsg_flags, 87 int recvmsg_flags,
86 int* result_fd, 88 int* result_fd,
87 const Pickle& request); 89 const Pickle& request);
88 #endif // !defined(OS_NACL_NONSFI) 90 #endif // !defined(OS_NACL_NONSFI)
89 private: 91 private:
90 // Similar to RecvMsg, but allows to specify |flags| for recvmsg(2). 92 // Similar to RecvMsg, but allows to specify |flags| for recvmsg(2).
91 static ssize_t RecvMsgWithFlags(int fd, 93 static ssize_t RecvMsgWithFlags(int fd,
92 void* msg, 94 void* msg,
93 size_t length, 95 size_t length,
94 int flags, 96 int flags,
95 ScopedVector<base::ScopedFD>* fds, 97 ScopedVector<ScopedFD>* fds,
96 base::ProcessId* pid); 98 ProcessId* pid);
97 }; 99 };
98 100
101 } // namespace base
102
99 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ 103 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_
OLDNEW
« no previous file with comments | « base/posix/safe_strerror.cc ('k') | base/posix/unix_domain_socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698