tcptls.c: refactor client connection to be more robust

The current TCP client connect code, blocks and does not handle EINTR
error case.

This patch makes the client socket non-blocking while connecting,
ensures a connect does not immediately fail due to EINTR "errors",
and adds a connect timeout option.

The original client start call sets the new timeout option to
"infinite", thus making sure old, orginal behavior is retained.

ASTERISK-29746 #close

Change-Id: I907571843a83e43c0742b95a64785f4411f02671
This commit is contained in:
Kevin Harwell
2021-11-15 16:13:19 -06:00
committed by George Joseph
parent f7c4a3800c
commit 1ddaedeaf5
2 changed files with 100 additions and 14 deletions

View File

@@ -164,8 +164,30 @@ struct ast_tcptls_session_instance {
};
/*!
* \brief attempts to connect and start tcptls session, on error the tcptls_session's
* ref count is decremented, fd and file are closed, and NULL is returned.
* \brief Attempt to connect and start a tcptls session within the given timeout
*
* \note On error the tcptls_session's ref count is decremented, fd and file
* are closed, and NULL is returned.
*
* \param tcptls_session The session instance to connect and start
* \param timeout How long (in milliseconds) to attempt to connect (-1 equals infinite)
*
* \return The tcptls_session, or NULL on error
*/
struct ast_tcptls_session_instance *ast_tcptls_client_start_timeout(
struct ast_tcptls_session_instance *tcptls_session, int timeout);
/*!
* \brief Attempt to connect and start a tcptls session
*
* Blocks until a connection is established, or an error occurs.
*
* \note On error the tcptls_session's ref count is decremented, fd and file
* are closed, and NULL is returned.
*
* \param tcptls_session The session instance to connect and start
*
* \return The tcptls_session, or NULL on error
*/
struct ast_tcptls_session_instance *ast_tcptls_client_start(struct ast_tcptls_session_instance *tcptls_session);