OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_EMBEDDER_PLATFORM_CHANNEL_UTILS_POSIX_H_ | 5 #ifndef MOJO_EMBEDDER_PLATFORM_CHANNEL_UTILS_POSIX_H_ |
6 #define MOJO_EMBEDDER_PLATFORM_CHANNEL_UTILS_POSIX_H_ | 6 #define MOJO_EMBEDDER_PLATFORM_CHANNEL_UTILS_POSIX_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <sys/types.h> // For |ssize_t|. | 9 #include <sys/types.h> // For |ssize_t|. |
10 | 10 |
11 #include <deque> | 11 #include <deque> |
12 | 12 |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "mojo/embedder/platform_handle.h" | 14 #include "mojo/embedder/platform_handle.h" |
15 #include "mojo/system/system_impl_export.h" | 15 #include "mojo/system/system_impl_export.h" |
16 | 16 |
17 struct iovec; // Declared in <sys/uio.h>. | 17 struct iovec; // Declared in <sys/uio.h>. |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 namespace embedder { | 20 namespace embedder { |
21 | 21 |
22 // The maximum number of handles that can be sent "at once" using | 22 // The maximum number of handles that can be sent "at once" using |
23 // |PlatformChannelSendHandles()|. | 23 // |PlatformChannelSendmsgWithHandles()|. |
24 // TODO(vtl): This number is taken from ipc/file_descriptor_set_posix.h: | 24 // TODO(vtl): This number is taken from ipc/file_descriptor_set_posix.h: |
25 // |FileDescriptorSet::kMaxDescriptorsPerMessage|. Where does it come from? | 25 // |FileDescriptorSet::kMaxDescriptorsPerMessage|. Where does it come from? |
26 const size_t kPlatformChannelMaxNumHandles = 7; | 26 const size_t kPlatformChannelMaxNumHandles = 7; |
27 | 27 |
28 // Use these to write to a socket created using |PlatformChannelPair| (or | 28 // Use these to write to a socket created using |PlatformChannelPair| (or |
29 // equivalent). These are like |write()| and |writev()|, but handle |EINTR| and | 29 // equivalent). These are like |write()| and |writev()|, but handle |EINTR| and |
30 // never raise |SIGPIPE|. (Note: On Mac, the suppression of |SIGPIPE| is set up | 30 // never raise |SIGPIPE|. (Note: On Mac, the suppression of |SIGPIPE| is set up |
31 // by |PlatformChannelPair|.) | 31 // by |PlatformChannelPair|.) |
32 MOJO_SYSTEM_IMPL_EXPORT ssize_t PlatformChannelWrite(PlatformHandle h, | 32 MOJO_SYSTEM_IMPL_EXPORT ssize_t PlatformChannelWrite(PlatformHandle h, |
33 const void* bytes, | 33 const void* bytes, |
34 size_t num_bytes); | 34 size_t num_bytes); |
35 MOJO_SYSTEM_IMPL_EXPORT ssize_t PlatformChannelWritev(PlatformHandle h, | 35 MOJO_SYSTEM_IMPL_EXPORT ssize_t PlatformChannelWritev(PlatformHandle h, |
36 struct iovec* iov, | 36 struct iovec* iov, |
37 size_t num_iov); | 37 size_t num_iov); |
38 | 38 |
| 39 // Writes data, and the given set of |PlatformHandle|s (i.e., file descriptors) |
| 40 // over the Unix domain socket given by |h| (e.g., created using |
| 41 // |PlatformChannelPair()|). All the handles must be valid, and there must be at |
| 42 // least one and at most |kPlatformChannelMaxNumHandles| handles. The return |
| 43 // value is as for |sendmsg()|, namely -1 on failure and otherwise the number of |
| 44 // bytes of data sent on success (note that this may not be all the data |
| 45 // specified by |iov|). (The handles are not closed, regardless of success or |
| 46 // failure.) |
| 47 MOJO_SYSTEM_IMPL_EXPORT ssize_t PlatformChannelSendmsgWithHandles( |
| 48 PlatformHandle h, |
| 49 struct iovec* iov, |
| 50 size_t num_iov, |
| 51 PlatformHandle* platform_handles, |
| 52 size_t num_platform_handles); |
| 53 |
| 54 // TODO(vtl): Remove this once I've switched things over to |
| 55 // |PlatformChannelSendmsgWithHandles()|. |
39 // Sends |PlatformHandle|s (i.e., file descriptors) over the Unix domain socket | 56 // Sends |PlatformHandle|s (i.e., file descriptors) over the Unix domain socket |
40 // (e.g., created using PlatformChannelPair|). (These will be sent in a single | 57 // (e.g., created using PlatformChannelPair|). (These will be sent in a single |
41 // message having one null byte of data and one control message header with all | 58 // message having one null byte of data and one control message header with all |
42 // the file descriptors.) All of the handles must be valid, and there must be at | 59 // the file descriptors.) All of the handles must be valid, and there must be at |
43 // most |kPlatformChannelMaxNumHandles| (and at least one handle). Returns true | 60 // most |kPlatformChannelMaxNumHandles| (and at least one handle). Returns true |
44 // on success, in which case it closes all the handles. | 61 // on success, in which case it closes all the handles. |
45 MOJO_SYSTEM_IMPL_EXPORT bool PlatformChannelSendHandles(PlatformHandle h, | 62 MOJO_SYSTEM_IMPL_EXPORT bool PlatformChannelSendHandles(PlatformHandle h, |
46 PlatformHandle* handles, | 63 PlatformHandle* handles, |
47 size_t num_handles); | 64 size_t num_handles); |
48 | 65 |
49 // Wrapper around |recvmsg()|, which will extract any attached file descriptors | 66 // Wrapper around |recvmsg()|, which will extract any attached file descriptors |
50 // (in the control message) to |PlatformHandle|s (and append them to | 67 // (in the control message) to |PlatformHandle|s (and append them to |
51 // |platform_handles|). (This also handles |EINTR|.) | 68 // |platform_handles|). (This also handles |EINTR|.) |
52 MOJO_SYSTEM_IMPL_EXPORT ssize_t PlatformChannelRecvmsg( | 69 MOJO_SYSTEM_IMPL_EXPORT ssize_t PlatformChannelRecvmsg( |
53 PlatformHandle h, | 70 PlatformHandle h, |
54 void* buf, | 71 void* buf, |
55 size_t num_bytes, | 72 size_t num_bytes, |
56 std::deque<PlatformHandle>* platform_handles); | 73 std::deque<PlatformHandle>* platform_handles); |
57 | 74 |
58 } // namespace embedder | 75 } // namespace embedder |
59 } // namespace mojo | 76 } // namespace mojo |
60 | 77 |
61 #endif // MOJO_EMBEDDER_PLATFORM_CHANNEL_UTILS_POSIX_H_ | 78 #endif // MOJO_EMBEDDER_PLATFORM_CHANNEL_UTILS_POSIX_H_ |
OLD | NEW |