OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 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. | |
4 | |
5 #ifndef CHROME_COMMON_UNIX_DOMAIN_SOCKET_POSIX_H_ | |
6 #define CHROME_COMMON_UNIX_DOMAIN_SOCKET_POSIX_H_ | |
7 #pragma once | |
8 | |
9 #include <stdint.h> | |
10 #include <sys/types.h> | |
11 #include <vector> | |
12 | |
13 class Pickle; | |
14 | |
15 class UnixDomainSocket { | |
16 public: | |
17 // Use sendmsg to write the given msg and include a vector of file | |
18 // descriptors. Returns true if successful. | |
19 static bool SendMsg(int fd, | |
20 const void* msg, | |
21 size_t length, | |
22 const std::vector<int>& fds); | |
23 | |
24 // Use recvmsg to read a message and an array of file descriptors. Returns | |
25 // -1 on failure. Note: will read, at most, 16 descriptors. | |
26 static ssize_t RecvMsg(int fd, | |
27 void* msg, | |
28 size_t length, | |
29 std::vector<int>* fds); | |
30 | |
31 // Perform a sendmsg/recvmsg pair. | |
32 // 1. This process creates a UNIX DGRAM socketpair. | |
33 // 2. This proces writes a request to |fd| with an SCM_RIGHTS control | |
34 // message containing on end of the fresh socket pair. | |
35 // 3. This process blocks reading from the other end of the fresh | |
36 // socketpair. | |
37 // 4. The target process receives the request, processes it and writes the | |
38 // reply to the end of the socketpair contained in the request. | |
39 // 5. This process wakes up and continues. | |
40 // | |
41 // fd: descriptor to send the request on | |
42 // reply: buffer for the reply | |
43 // reply_len: size of |reply| | |
44 // result_fd: (may be NULL) the file descriptor returned in the reply | |
45 // (if any) | |
46 // request: the bytes to send in the request | |
47 static ssize_t SendRecvMsg(int fd, | |
48 uint8_t* reply, | |
49 unsigned reply_len, | |
50 int* result_fd, | |
51 const Pickle& request); | |
52 }; | |
53 | |
54 #endif // CHROME_COMMON_UNIX_DOMAIN_SOCKET_POSIX_H_ | |
OLD | NEW |