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
3 // found in the LICENSE file.
5 #ifndef BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_
6 #define BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_
12 #include "base/base_export.h"
16 class BASE_EXPORT UnixDomainSocket
{
18 // Maximum number of file descriptors that can be read by RecvMsg().
19 static const size_t kMaxFileDescriptors
;
21 // Use sendmsg to write the given msg and include a vector of file
22 // descriptors. Returns true if successful.
23 static bool SendMsg(int fd
,
26 const std::vector
<int>& fds
);
28 // Use recvmsg to read a message and an array of file descriptors. Returns
29 // -1 on failure. Note: will read, at most, |kMaxFileDescriptors| descriptors.
30 static ssize_t
RecvMsg(int fd
,
33 std::vector
<int>* fds
);
35 // Perform a sendmsg/recvmsg pair.
36 // 1. This process creates a UNIX SEQPACKET socketpair. Using
37 // connection-oriented sockets (SEQPACKET or STREAM) is critical here,
38 // 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
40 // message containing on end of the fresh socket pair.
41 // 3. This process blocks reading from the other end of the fresh
43 // 4. The target process receives the request, processes it and writes the
44 // reply to the end of the socketpair contained in the request.
45 // 5. This process wakes up and continues.
47 // fd: descriptor to send the request on
48 // reply: buffer for the reply
49 // reply_len: size of |reply|
50 // result_fd: (may be NULL) the file descriptor returned in the reply
52 // request: the bytes to send in the request
53 static ssize_t
SendRecvMsg(int fd
,
57 const Pickle
& request
);
60 #endif // BASE_POSIX_UNIX_DOMAIN_SOCKET_LINUX_H_