| 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_POSIX_H_ | 5 #ifndef MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_UTILS_POSIX_H_ |
| 6 #define MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_UTILS_POSIX_H_ | 6 #define MOJO_EDK_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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // |PlatformChannelSendmsgWithHandles()|. | 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 | 32 MOJO_SYSTEM_IMPL_EXPORT ssize_t |
| 33 PlatformChannelWrite(PlatformHandle h, const void* bytes, size_t num_bytes); | 33 PlatformChannelWrite(PlatformHandle h, const void* bytes, size_t num_bytes); |
| 34 MOJO_SYSTEM_IMPL_EXPORT ssize_t | 34 MOJO_SYSTEM_IMPL_EXPORT ssize_t |
| 35 PlatformChannelWritev(PlatformHandle h, struct iovec* iov, size_t num_iov); | 35 PlatformChannelWritev(PlatformHandle h, struct iovec* iov, size_t num_iov); |
| 36 | 36 |
| 37 // Writes data, and the given set of |PlatformHandle|s (i.e., file descriptors) | 37 // Writes data, and the given set of |PlatformHandle|s (i.e., file descriptors) |
| 38 // over the Unix domain socket given by |h| (e.g., created using | 38 // over the Unix domain socket given by |h| (e.g., created using |
| 39 // |PlatformChannelPair()|). All the handles must be valid, and there must be at | 39 // |PlatformChannelPair()|). All the handles must be valid, and there must be at |
| 40 // least one and at most |kPlatformChannelMaxNumHandles| handles. The return | 40 // least one and at most |kPlatformChannelMaxNumHandles| handles. The return |
| 41 // value is as for |sendmsg()|, namely -1 on failure and otherwise the number of | 41 // value is as for |sendmsg()|, namely -1 on failure and otherwise the number of |
| 42 // bytes of data sent on success (note that this may not be all the data | 42 // bytes of data sent on success (note that this may not be all the data |
| 43 // specified by |iov|). (The handles are not closed, regardless of success or | 43 // specified by |iov|). (The handles are not closed, regardless of success or |
| 44 // failure.) | 44 // failure.) |
| 45 MOJO_SYSTEM_IMPL_EXPORT ssize_t | 45 MOJO_SYSTEM_IMPL_EXPORT ssize_t |
| 46 PlatformChannelSendmsgWithHandles(PlatformHandle h, | 46 PlatformChannelSendmsgWithHandles(PlatformHandle h, |
| 47 struct iovec* iov, | 47 struct iovec* iov, |
| 48 size_t num_iov, | 48 size_t num_iov, |
| 49 PlatformHandle* platform_handles, | 49 PlatformHandle* platform_handles, |
| 50 size_t num_platform_handles); | 50 size_t num_platform_handles); |
| 51 | 51 |
| 52 // TODO(vtl): Remove this once I've switched things over to | 52 // TODO(vtl): Remove this once I've switched things over to |
| 53 // |PlatformChannelSendmsgWithHandles()|. | 53 // |PlatformChannelSendmsgWithHandles()|. |
| 54 // Sends |PlatformHandle|s (i.e., file descriptors) over the Unix domain socket | 54 // Sends |PlatformHandle|s (i.e., file descriptors) over the Unix domain socket |
| 55 // (e.g., created using PlatformChannelPair|). (These will be sent in a single | 55 // (e.g., created using PlatformChannelPair|). (These will be sent in a single |
| 56 // message having one null byte of data and one control message header with all | 56 // message having one null byte of data and one control message header with all |
| 57 // the file descriptors.) All of the handles must be valid, and there must be at | 57 // the file descriptors.) All of the handles must be valid, and there must be at |
| 58 // most |kPlatformChannelMaxNumHandles| (and at least one handle). Returns true | 58 // most |kPlatformChannelMaxNumHandles| (and at least one handle). Returns true |
| 59 // on success, in which case it closes all the handles. | 59 // on success, in which case it closes all the handles. |
| 60 MOJO_SYSTEM_IMPL_EXPORT bool PlatformChannelSendHandles(PlatformHandle h, | 60 MOJO_SYSTEM_IMPL_EXPORT bool PlatformChannelSendHandles(PlatformHandle h, |
| 61 PlatformHandle* handles, | 61 PlatformHandle* handles, |
| 62 size_t num_handles); | 62 size_t num_handles); |
| 63 | 63 |
| 64 // Wrapper around |recvmsg()|, which will extract any attached file descriptors | 64 // Wrapper around |recvmsg()|, which will extract any attached file descriptors |
| 65 // (in the control message) to |PlatformHandle|s (and append them to | 65 // (in the control message) to |PlatformHandle|s (and append them to |
| 66 // |platform_handles|). (This also handles |EINTR|.) | 66 // |platform_handles|). (This also handles |EINTR|.) |
| 67 MOJO_SYSTEM_IMPL_EXPORT ssize_t | 67 MOJO_SYSTEM_IMPL_EXPORT ssize_t |
| 68 PlatformChannelRecvmsg(PlatformHandle h, | 68 PlatformChannelRecvmsg(PlatformHandle h, |
| 69 void* buf, | 69 void* buf, |
| 70 size_t num_bytes, | 70 size_t num_bytes, |
| 71 std::deque<PlatformHandle>* platform_handles); | 71 std::deque<PlatformHandle>* platform_handles); |
| 72 | 72 |
| 73 } // namespace embedder | 73 } // namespace embedder |
| 74 } // namespace mojo | 74 } // namespace mojo |
| 75 | 75 |
| 76 #endif // MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_UTILS_POSIX_H_ | 76 #endif // MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_UTILS_POSIX_H_ |
| OLD | NEW |