<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8888">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">iostreams: Add some documentation for the ast_iostream_* functions<br><br>Change-Id: Id71b87637f0a484eb5a1cd26c3d1c7c15c7dcf26<br>---<br>M include/asterisk/iostream.h<br>1 file changed, 150 insertions(+), 17 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/88/8888/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/iostream.h b/include/asterisk/iostream.h<br>index e9816ac..1b07cde 100644<br>--- a/include/asterisk/iostream.h<br>+++ b/include/asterisk/iostream.h<br>@@ -44,7 +44,7 @@<br> /*!<br>  * \brief Disable the iostream timeout timer.<br>  *<br>- * \param stream iostream control data.<br>+ * \param stream A pointer to an iostream<br>  *<br>  * \return Nothing<br>  */<br>@@ -53,7 +53,7 @@<br> /*!<br>  * \brief Set the iostream inactivity timeout timer.<br>  *<br>- * \param stream iostream control data.<br>+ * \param stream A pointer to an iostream<br>  * \param timeout Number of milliseconds to wait for data transfer with the peer.<br>  *<br>  * \details This is basically how much time we are willing to spend<br>@@ -61,17 +61,31 @@<br>  *<br>  * \note Setting timeout to -1 disables the timeout.<br>  * \note Setting this timeout replaces the I/O sequence timeout timer.<br>- *<br>- * \return Nothing<br>  */<br> void ast_iostream_set_timeout_inactivity(struct ast_iostream *stream, int timeout);<br> <br>+/*!<br>+ * \brief Set the iostream inactivity & idle timeout timers.<br>+ *<br>+ * \param stream A pointer to an iostream<br>+ * \param timeout Number of milliseconds to wait for initial data transfer with<br>+ *                the peer.<br>+ * \param timeout_reset Number of milliseconds to wait for subsequent data<br>+ *                      transfer with the peer.<br>+ *<br>+ * \details As an example, if you want to timeout a peer if they do not send an<br>+ *          initial message within 5 seconds or if they do not send a message at<br>+ *          least every 30 seconds, you would set \c timeout to \c 5000 and<br>+ *          \c timeout_reset to \c 30000.<br>+ *<br>+ * \note Setting either of these timeouts to -1 will disable them.<br>+ */<br> void ast_iostream_set_timeout_idle_inactivity(struct ast_iostream *stream, int timeout, int timeout_reset);<br> <br> /*!<br>  * \brief Set the iostream I/O sequence timeout timer.<br>  *<br>- * \param stream iostream control data.<br>+ * \param stream A pointer to an iostream<br>  * \param start Time the I/O sequence timer starts.<br>  * \param timeout Number of milliseconds from the start time before timeout.<br>  *<br>@@ -81,39 +95,158 @@<br>  *<br>  * \note Setting timeout to -1 disables the timeout.<br>  * \note Setting this timeout replaces the inactivity timeout timer.<br>- *<br>- * \return Nothing<br>  */<br> void ast_iostream_set_timeout_sequence(struct ast_iostream *stream, struct timeval start, int timeout);<br> <br> /*!<br>  * \brief Set the iostream if it can exclusively depend upon the set timeouts.<br>  *<br>- * \param stream iostream control data.<br>+ * \param stream A pointer to an iostream<br>  * \param exclusive_input TRUE if stream can exclusively wait for fd input.<br>  * Otherwise, the stream will not wait for fd input.  It will wait while<br>  * trying to send data.<br>  *<br>  * \note The stream timeouts still need to be set.<br>- *<br>- * \return Nothing<br>  */<br> void ast_iostream_set_exclusive_input(struct ast_iostream *stream, int exclusive_input);<br> <br>+/*!<br>+ * \brief Get an iostream's file descriptor.<br>+ *<br>+ * \param stream A pointer to an iostream<br>+ *<br>+ * \return The file descriptor for the given iostream, or -1 if the iostream has no open<br>+ *         file descriptor.<br>+ */<br> int ast_iostream_get_fd(struct ast_iostream *stream);<br>+<br>+/*!<br>+ * \brief Make an iostream non-blocking.<br>+ *<br>+ * \param stream A pointer to an iostream<br>+ */<br> void ast_iostream_nonblock(struct ast_iostream *stream);<br> <br>-SSL* ast_iostream_get_ssl(struct ast_iostream *stream);<br>+/*!<br>+ * \brief Get a pointer to an iostream's OpenSSL \c SSL structure<br>+ *<br>+ * \param stream A pointer to an iostream<br>+ *<br>+ * \return A pointer to the OpenSSL \c SSL structure for the given iostream, or<br>+ *         \c NULL if TLS has not been initiated.<br>+ *<br>+ * \note If OpenSSL support is not included in the build, this will always return<br>+ *       \c NULL.<br>+ */<br>+SSL *ast_iostream_get_ssl(struct ast_iostream *stream);<br> <br>-ssize_t ast_iostream_read(struct ast_iostream *stream, void *buf, size_t count);<br>-ssize_t ast_iostream_gets(struct ast_iostream *stream, char *buf, size_t count);<br>+/*!<br>+ * \brief Read data from an iostream.<br>+ *<br>+ * \param stream A pointer to an iostream<br>+ * \param buf Pointer to a buffer to store the read bytes.<br>+ * \param count The number of bytes to read.<br>+ *<br>+ * \return Upon successful completion, returns a non-negative integer indicating<br>+ *         the number of bytes actually read. Otherwise, returns -1 and may set<br>+ *         errno to indicate the error.<br>+ */<br>+ssize_t ast_iostream_read(struct ast_iostream *stream, void *buffer, size_t count);<br>+<br>+/*!<br>+ * \brief Read a LF-terminated string from an iostream.<br>+ *<br>+ * \param stream A pointer to an iostream<br>+ * \param buf Pointer to a buffer to store the read bytes.<br>+ * \param size The total size of \c buf in bytes.<br>+ *<br>+ * \return The number of bytes stored in \c buf, excluding the null byte used to<br>+ *         terminate the string. If the size of \c buf (indicated by the caller<br>+ *         with the \c count argument) is not sufficient to store the entire line<br>+ *         it will be truncated to fit the available space. The contents of \c buf<br>+ *         will always be terminated with a null byte. In the case of an error,<br>+ *         \c -1 will be returned and \c errno may be set indicating the error.<br>+ */<br>+ssize_t ast_iostream_gets(struct ast_iostream *stream, char *buffer, size_t size);<br>+<br>+/*!<br>+ * \brief Discard the specified number of bytes from an iostream.<br>+ *<br>+ * \param stream A pointer to an iostream<br>+ * \param count The number of bytes to discard.<br>+ *<br>+ * \return Upon successful completion, returns the number of bytes discarded.<br>+ *         Otherwise, \c -1 is returned and \c errno may be set indicating the<br>+ *         error.<br>+ */<br> ssize_t ast_iostream_discard(struct ast_iostream *stream, size_t count);<br>-ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buf, size_t count);<br>-ssize_t __attribute__((format(printf, 2, 3))) ast_iostream_printf(<br>-    struct ast_iostream *stream, const char *fmt, ...);<br> <br>-struct ast_iostream* ast_iostream_from_fd(int *fd);<br>+/*!<br>+ * \brief Write data to an iostream.<br>+ *<br>+ * \param stream A pointer to an iostream<br>+ * \param buf Pointer to a buffer from which to read bytes.<br>+ * \param count The number of bytes from \c buf to write.<br>+ *<br>+ * \return Upon successful completion, returns the number of bytes actually<br>+ *         written to the iostream. This number shall never be greater than<br>+ *         \c count. Otherwise, returns -1 and may set \c errno to indicate<br>+ *         the error.<br>+ */<br>+ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buf, size_t count);<br>+<br>+/*!<br>+ * \brief Write a formatted string to an iostream.<br>+ *<br>+ * \param stream A pointer to an iostream<br>+ * \param format A format string, as documented by printf(3)<br>+ * \param ... Arguments for the provided \c format string<br>+ *<br>+ * \return The number of bytes written, or \c -1 if an error occurs. Note that if<br>+ *         \c -1 is returned, the number of bytes written to the iostream is<br>+ *         unspecified.<br>+ */<br>+ssize_t __attribute__((format(printf, 2, 3))) ast_iostream_printf(<br>+   struct ast_iostream *stream, const char *format, ...);<br>+<br>+/*!<br>+ * \brief Create an iostream from a file descriptor.<br>+ *<br>+ * \param fd A pointer to an open file descriptor<br>+ *<br>+ * \return A newly allocated iostream or \c NULL if allocation fails.<br>+ */<br>+struct ast_iostream *ast_iostream_from_fd(int *fd);<br>+<br>+/*!<br>+ * \brief Begin TLS on an iostream.<br>+ *<br>+ * \param stream A pointer to an iostream pointer<br>+ * \param ctx A pointer to an \c SSL_CTX which will be passed to \c SSL_new()<br>+ * \param client Non-zero to indicate that we are the client, zero to indicate<br>+ *               that we are the server.<br>+ *<br>+ * \retval 0 success<br>+ * \retval -1 failure<br>+ *<br>+ * \note The \c iostream that is passed in \c stream may be replaced with a different one<br>+ *       before this function returns.<br>+ * \note On failure, \c errno may be set providing additional information on why<br>+ *       the failure occurred.<br>+ */<br> int ast_iostream_start_tls(struct ast_iostream **stream, SSL_CTX *ctx, int client);<br>+<br>+/*!<br>+ * \brief Close an iostream.<br>+ *<br>+ * \param stream A pointer to an iostream<br>+ *<br>+ * \retval 0 success<br>+ * \retval -1 failure<br>+ *<br>+ * \note On failure, \c errno may be set providing additional information on why<br>+ *       the failure occurred.<br>+ */<br> int ast_iostream_close(struct ast_iostream *stream);<br> <br> #endif /* _ASTERISK_IOSTREAM_H */<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8888">change 8888</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8888"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Id71b87637f0a484eb5a1cd26c3d1c7c15c7dcf26 </div>
<div style="display:none"> Gerrit-Change-Number: 8888 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>