OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 //! or to run in a loop. | 92 //! or to run in a loop. |
93 enum Persistent { | 93 enum Persistent { |
94 //! \brief Handle a single request-reply transaction and then return. | 94 //! \brief Handle a single request-reply transaction and then return. |
95 kOneShot = false, | 95 kOneShot = false, |
96 | 96 |
97 //! \brief Run in a loop, potentially handling multiple request-reply | 97 //! \brief Run in a loop, potentially handling multiple request-reply |
98 //! transactions. | 98 //! transactions. |
99 kPersistent, | 99 kPersistent, |
100 }; | 100 }; |
101 | 101 |
102 //! \brief Informs Run() whether or not to block while waiting for requests. | |
103 enum Nonblocking { | |
104 //! \brief Wait for a request message if none is queued. | |
105 kBlocking = false, | |
106 | |
107 //! \brief Return as soon as there no request messages queued. This may | |
108 //! result in an immediate return without handling any requests. | |
109 kNonblocking, | |
110 }; | |
111 | |
112 //! \brief Determines how to handle the reception of messages larger than the | 102 //! \brief Determines how to handle the reception of messages larger than the |
113 //! size of the buffer allocated to store them. | 103 //! size of the buffer allocated to store them. |
114 enum ReceiveLarge { | 104 enum ReceiveLarge { |
115 //! \brief Return `MACH_RCV_TOO_LARGE` upon receipt of a large message. | 105 //! \brief Return `MACH_RCV_TOO_LARGE` upon receipt of a large message. |
116 //! | 106 //! |
117 //! This mimics the default behavior of `mach_msg_server()` when `options` | 107 //! This mimics the default behavior of `mach_msg_server()` when `options` |
118 //! does not contain `MACH_RCV_LARGE`. | 108 //! does not contain `MACH_RCV_LARGE`. |
119 kReceiveLargeError = 0, | 109 kReceiveLargeError = 0, |
120 | 110 |
121 //! \brief Ignore large messages, and attempt to receive the next queued | 111 //! \brief Ignore large messages, and attempt to receive the next queued |
(...skipping 30 matching lines...) Expand all Loading... |
152 //! maximum size of the reply message. If \a options contains | 142 //! maximum size of the reply message. If \a options contains |
153 //! `MACH_RCV_LARGE`, this function will retry a receive operation that | 143 //! `MACH_RCV_LARGE`, this function will retry a receive operation that |
154 //! returns `MACH_RCV_TOO_LARGE` with an appropriately-sized buffer. | 144 //! returns `MACH_RCV_TOO_LARGE` with an appropriately-sized buffer. |
155 //! MachMessageServerInterface::MachMessageServerFunction() is called to | 145 //! MachMessageServerInterface::MachMessageServerFunction() is called to |
156 //! handle the request and populate the reply. | 146 //! handle the request and populate the reply. |
157 //! \param[in] receive_port The port on which to receive the request message. | 147 //! \param[in] receive_port The port on which to receive the request message. |
158 //! \param[in] options Options suitable for mach_msg. For the defaults, use | 148 //! \param[in] options Options suitable for mach_msg. For the defaults, use |
159 //! `MACH_MSG_OPTION_NONE`. `MACH_RCV_LARGE` when specified here is | 149 //! `MACH_MSG_OPTION_NONE`. `MACH_RCV_LARGE` when specified here is |
160 //! ignored. Set \a receive_large to #kReceiveLargeResize instead. | 150 //! ignored. Set \a receive_large to #kReceiveLargeResize instead. |
161 //! \param[in] persistent Chooses between one-shot and persistent operation. | 151 //! \param[in] persistent Chooses between one-shot and persistent operation. |
162 //! \param[in] nonblocking Chooses between blocking and nonblocking operation. | |
163 //! \param[in] receive_large Determines the behavior upon encountering a | 152 //! \param[in] receive_large Determines the behavior upon encountering a |
164 //! message larger than the receive buffer’s size. | 153 //! message larger than the receive buffer’s size. |
165 //! \param[in] timeout_ms When \a nonblocking is `false`, the the maximum | 154 //! \param[in] timeout_ms The maximum duration that this entire function will |
166 //! duration that this entire function will run, in milliseconds, or | 155 //! run, in milliseconds. This may be #kMachMessageTimeoutNonblocking or |
167 //! `MACH_MSG_TIMEOUT_NONE` to specify no timeout (infinite waiting). When | 156 //! #kMachMessageTimeoutWaitIndefinitely. When \a persistent is `true`, |
168 //! \a nonblocking is `true`, this parameter has no effect. When \a | 157 //! the timeout applies to the overall duration of this function, not to |
169 //! persistent is `true`, the timeout applies to the overall duration of | 158 //! any individual `mach_msg()` call. |
170 //! this function, not to any individual `mach_msg()` call. | |
171 //! | 159 //! |
172 //! \return On success, `KERN_SUCCESS` (when \a persistent is `false`) or | 160 //! \return On success, `KERN_SUCCESS` (when \a persistent is `false`) or |
173 //! `MACH_RCV_TIMED_OUT` (when \a persistent and \a nonblocking are both | 161 //! `MACH_RCV_TIMED_OUT` (when \a persistent is `true` and \a timeout_ms |
174 //! `true`, or when \a persistent is `true`, \a nonblocking is `false`, | 162 //! is not #kMachMessageTimeoutWaitIndefinitely). This function has no |
175 //! and \a timeout is not `MACH_MSG_TIMEOUT_NONE`. This function has no | 163 //! successful return value when \a persistent is `true` and \a timeout_ms |
176 //! successful return value when \a persistent is `true`, \a nonblocking | 164 //! is #kMachMessageTimeoutWaitIndefinitely. On failure, returns a value |
177 //! is `false`, and \a timeout is `MACH_MSG_TIMEOUT_NONE`. On failure, | 165 //! identifying the nature of the error. |
178 //! returns a value identifying the nature of the error. | |
179 static mach_msg_return_t Run(Interface* interface, | 166 static mach_msg_return_t Run(Interface* interface, |
180 mach_port_t receive_port, | 167 mach_port_t receive_port, |
181 mach_msg_options_t options, | 168 mach_msg_options_t options, |
182 Persistent persistent, | 169 Persistent persistent, |
183 Nonblocking nonblocking, | |
184 ReceiveLarge receive_large, | 170 ReceiveLarge receive_large, |
185 mach_msg_timeout_t timeout_ms); | 171 mach_msg_timeout_t timeout_ms); |
186 | 172 |
187 private: | 173 private: |
188 DISALLOW_IMPLICIT_CONSTRUCTORS(MachMessageServer); | 174 DISALLOW_IMPLICIT_CONSTRUCTORS(MachMessageServer); |
189 }; | 175 }; |
190 | 176 |
191 } // namespace crashpad | 177 } // namespace crashpad |
192 | 178 |
193 #endif // CRASHPAD_UTIL_MACH_MACH_MESSAGE_SERVER_H_ | 179 #endif // CRASHPAD_UTIL_MACH_MACH_MESSAGE_SERVER_H_ |
OLD | NEW |