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_EDK_EMBEDDER_PLATFORM_CHANNEL_UTILS_H_ | 5 #ifndef MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_UTILS_H_ |
6 #define MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_UTILS_H_ | 6 #define MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_UTILS_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 "mojo/edk/embedder/platform_handle.h" | 13 #include "mojo/edk/platform/platform_handle.h" |
14 #include "mojo/edk/embedder/scoped_platform_handle.h" | 14 #include "mojo/edk/platform/scoped_platform_handle.h" |
15 | 15 |
16 struct iovec; // Declared in <sys/uio.h>. | 16 struct iovec; // Declared in <sys/uio.h>. |
17 | 17 |
18 namespace mojo { | 18 namespace mojo { |
19 namespace embedder { | 19 namespace embedder { |
20 | 20 |
21 // The maximum number of handles that can be sent "at once" using | 21 // The maximum number of handles that can be sent "at once" using |
22 // |PlatformChannelSendmsgWithHandles()|. | 22 // |PlatformChannelSendmsgWithHandles()|. |
23 // TODO(vtl): This number is taken from ipc/ipc_message_attachment_set.h: | 23 // TODO(vtl): This number is taken from ipc/ipc_message_attachment_set.h: |
24 // |IPC::MessageAttachmentSet::kMaxDescriptorsPerMessage|. | 24 // |IPC::MessageAttachmentSet::kMaxDescriptorsPerMessage|. |
25 const size_t kPlatformChannelMaxNumHandles = 128; | 25 const size_t kPlatformChannelMaxNumHandles = 128; |
26 | 26 |
27 // Use these to write to a socket created using |PlatformChannelPair| (or | 27 // Use these to write to a socket created using |PlatformChannelPair| (or |
28 // equivalent). These are like |write()| and |writev()|, but handle |EINTR| and | 28 // equivalent). These are like |write()| and |writev()|, but handle |EINTR| and |
29 // never raise |SIGPIPE|. (Note: On Mac, the suppression of |SIGPIPE| is set up | 29 // never raise |SIGPIPE|. (Note: On Mac, the suppression of |SIGPIPE| is set up |
30 // by |PlatformChannelPair|.) | 30 // by |PlatformChannelPair|.) |
31 ssize_t PlatformChannelWrite(PlatformHandle h, | 31 ssize_t PlatformChannelWrite(platform::PlatformHandle h, |
32 const void* bytes, | 32 const void* bytes, |
33 size_t num_bytes); | 33 size_t num_bytes); |
34 ssize_t PlatformChannelWritev(PlatformHandle h, | 34 ssize_t PlatformChannelWritev(platform::PlatformHandle h, |
35 struct iovec* iov, | 35 struct iovec* iov, |
36 size_t num_iov); | 36 size_t num_iov); |
37 | 37 |
38 // Writes data, and the given set of |PlatformHandle|s (i.e., file descriptors) | 38 // Writes data, and the given set of |PlatformHandle|s (i.e., file descriptors) |
39 // over the Unix domain socket given by |h| (e.g., created using | 39 // over the Unix domain socket given by |h| (e.g., created using |
40 // |PlatformChannelPair()|). All the handles must be valid, and there must be at | 40 // |PlatformChannelPair()|). All the handles must be valid, and there must be at |
41 // least one and at most |kPlatformChannelMaxNumHandles| handles. The return | 41 // least one and at most |kPlatformChannelMaxNumHandles| handles. The return |
42 // value is as for |sendmsg()|, namely -1 on failure and otherwise the number of | 42 // value is as for |sendmsg()|, namely -1 on failure and otherwise the number of |
43 // bytes of data sent on success (note that this may not be all the data | 43 // bytes of data sent on success (note that this may not be all the data |
44 // specified by |iov|). (The handles are not closed, regardless of success or | 44 // specified by |iov|). (The handles are not closed, regardless of success or |
45 // failure.) | 45 // failure.) |
46 ssize_t PlatformChannelSendmsgWithHandles(PlatformHandle h, | 46 ssize_t PlatformChannelSendmsgWithHandles( |
47 struct iovec* iov, | 47 platform::PlatformHandle h, |
48 size_t num_iov, | 48 struct iovec* iov, |
49 PlatformHandle* platform_handles, | 49 size_t num_iov, |
50 size_t num_platform_handles); | 50 platform::PlatformHandle* platform_handles, |
| 51 size_t num_platform_handles); |
51 | 52 |
52 // Wrapper around |recvmsg()|, which will extract any attached file descriptors | 53 // Wrapper around |recvmsg()|, which will extract any attached file descriptors |
53 // (in the control message) to |ScopedPlatformHandle|s (and append them to | 54 // (in the control message) to |ScopedPlatformHandle|s (and append them to |
54 // |platform_handles|). (This also handles |EINTR|.) | 55 // |platform_handles|). (This also handles |EINTR|.) |
55 ssize_t PlatformChannelRecvmsg( | 56 ssize_t PlatformChannelRecvmsg( |
56 PlatformHandle h, | 57 platform::PlatformHandle h, |
57 void* buf, | 58 void* buf, |
58 size_t num_bytes, | 59 size_t num_bytes, |
59 std::deque<ScopedPlatformHandle>* platform_handles); | 60 std::deque<platform::ScopedPlatformHandle>* platform_handles); |
60 | 61 |
61 } // namespace embedder | 62 } // namespace embedder |
62 } // namespace mojo | 63 } // namespace mojo |
63 | 64 |
64 #endif // MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_UTILS_H_ | 65 #endif // MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_UTILS_H_ |
OLD | NEW |