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

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

Issue 258543006: Change UnixDomainSocket::RecvMsg to return ScopedVector<base::ScopedFD> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove fds->{empty,reserve}() per brettw@ feedback Created 6 years, 7 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 | Annotate | Revision Log
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"
14 #include "base/memory/scoped_vector.h"
13 #include "base/process/process_handle.h" 15 #include "base/process/process_handle.h"
14 16
15 class Pickle; 17 class Pickle;
16 18
17 class BASE_EXPORT UnixDomainSocket { 19 class BASE_EXPORT UnixDomainSocket {
18 public: 20 public:
19 // Maximum number of file descriptors that can be read by RecvMsg(). 21 // Maximum number of file descriptors that can be read by RecvMsg().
20 static const size_t kMaxFileDescriptors; 22 static const size_t kMaxFileDescriptors;
21 23
22 // Use to enable receiving process IDs in RecvMsgWithPid. Should be called on 24 // Use to enable receiving process IDs in RecvMsgWithPid. Should be called on
23 // the receiving socket (i.e., the socket passed to RecvMsgWithPid). Returns 25 // the receiving socket (i.e., the socket passed to RecvMsgWithPid). Returns
24 // true if successful. 26 // true if successful.
25 static bool EnableReceiveProcessId(int fd); 27 static bool EnableReceiveProcessId(int fd);
26 28
27 // Use sendmsg to write the given msg and include a vector of file 29 // Use sendmsg to write the given msg and include a vector of file
28 // descriptors. Returns true if successful. 30 // descriptors. Returns true if successful.
29 static bool SendMsg(int fd, 31 static bool SendMsg(int fd,
30 const void* msg, 32 const void* msg,
31 size_t length, 33 size_t length,
32 const std::vector<int>& fds); 34 const std::vector<int>& fds);
33 35
34 // Use recvmsg to read a message and an array of file descriptors. Returns 36 // Use recvmsg to read a message and an array of file descriptors. Returns
35 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors. 37 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors.
36 static ssize_t RecvMsg(int fd, 38 static ssize_t RecvMsg(int fd,
37 void* msg, 39 void* msg,
38 size_t length, 40 size_t length,
39 std::vector<int>* fds); 41 ScopedVector<base::ScopedFD>* fds);
40 42
41 // Same as RecvMsg above, but also returns the sender's process ID (as seen 43 // 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 44 // from the caller's namespace). However, before using this function to
43 // receive process IDs, EnableReceiveProcessId() should be called on the 45 // receive process IDs, EnableReceiveProcessId() should be called on the
44 // receiving socket. 46 // receiving socket.
45 static ssize_t RecvMsgWithPid(int fd, 47 static ssize_t RecvMsgWithPid(int fd,
46 void* msg, 48 void* msg,
47 size_t length, 49 size_t length,
48 std::vector<int>* fds, 50 ScopedVector<base::ScopedFD>* fds,
49 base::ProcessId* pid); 51 base::ProcessId* pid);
50 52
51 // Perform a sendmsg/recvmsg pair. 53 // Perform a sendmsg/recvmsg pair.
52 // 1. This process creates a UNIX SEQPACKET socketpair. Using 54 // 1. This process creates a UNIX SEQPACKET socketpair. Using
53 // connection-oriented sockets (SEQPACKET or STREAM) is critical here, 55 // connection-oriented sockets (SEQPACKET or STREAM) is critical here,
54 // because if one of the ends closes the other one must be notified. 56 // because if one of the ends closes the other one must be notified.
55 // 2. This process writes a request to |fd| with an SCM_RIGHTS control 57 // 2. This process writes a request to |fd| with an SCM_RIGHTS control
56 // message containing on end of the fresh socket pair. 58 // message containing on end of the fresh socket pair.
57 // 3. This process blocks reading from the other end of the fresh 59 // 3. This process blocks reading from the other end of the fresh
58 // socketpair. 60 // socketpair.
(...skipping 20 matching lines...) Expand all
79 unsigned reply_len, 81 unsigned reply_len,
80 int recvmsg_flags, 82 int recvmsg_flags,
81 int* result_fd, 83 int* result_fd,
82 const Pickle& request); 84 const Pickle& request);
83 private: 85 private:
84 // Similar to RecvMsg, but allows to specify |flags| for recvmsg(2). 86 // Similar to RecvMsg, but allows to specify |flags| for recvmsg(2).
85 static ssize_t RecvMsgWithFlags(int fd, 87 static ssize_t RecvMsgWithFlags(int fd,
86 void* msg, 88 void* msg,
87 size_t length, 89 size_t length,
88 int flags, 90 int flags,
89 std::vector<int>* fds, 91 ScopedVector<base::ScopedFD>* fds,
90 base::ProcessId* pid); 92 base::ProcessId* pid);
91 }; 93 };
92 94
93 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_ 95 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_
OLDNEW
« no previous file with comments | « no previous file | base/posix/unix_domain_socket_linux.cc » ('j') | components/nacl/loader/nacl_helper_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698