webclient: Make webclient_get_tunnel returns void

As it does never fail.
This commit is contained in:
YAMAMOTO Takashi 2022-06-17 15:03:46 +09:00 committed by Xiang Xiao
parent 5cfc5cd4f2
commit fca5b186b1
2 changed files with 42 additions and 47 deletions

View File

@ -561,8 +561,8 @@ void webclient_set_static_body(FAR struct webclient_context *ctx,
size_t bodylen); size_t bodylen);
int webclient_get_poll_info(FAR struct webclient_context *ctx, int webclient_get_poll_info(FAR struct webclient_context *ctx,
FAR struct webclient_poll_info *info); FAR struct webclient_poll_info *info);
int webclient_get_tunnel(FAR struct webclient_context *ctx, void webclient_get_tunnel(FAR struct webclient_context *ctx,
FAR struct webclient_conn_s **connp); FAR struct webclient_conn_s **connp);
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1445,54 +1445,51 @@ int webclient_perform(FAR struct webclient_context *ctx)
{ {
FAR struct webclient_conn_s *tunnel_conn; FAR struct webclient_conn_s *tunnel_conn;
ret = webclient_get_tunnel(ws->tunnel, &tunnel_conn); webclient_get_tunnel(ws->tunnel, &tunnel_conn);
if (ret == 0) DEBUGASSERT(tunnel_conn != NULL);
{ DEBUGASSERT(!tunnel_conn->tls);
DEBUGASSERT(tunnel_conn != NULL); free(ws->tunnel);
DEBUGASSERT(!tunnel_conn->tls); ws->tunnel = NULL;
free(ws->tunnel);
ws->tunnel = NULL;
if (conn->tls) if (conn->tls)
{
/* Revisit: tunnel_conn here should have
* timeout configured already.
* Configuring it again here is redundant.
*/
ret = tls_ops->init_connection(tls_ctx,
tunnel_conn,
ws->target.hostname,
ctx->timeout_sec,
&conn->tls_conn);
if (ret == 0)
{ {
/* Revisit: tunnel_conn here should have /* Note: tunnel_conn has been consumed by
* timeout configured already. * tls_ops->init_connection
* Configuring it again here is redundant.
*/ */
ret = tls_ops->init_connection(tls_ctx, ws->need_conn_close = true;
tunnel_conn,
ws->target.hostname,
ctx->timeout_sec,
&conn->tls_conn);
if (ret == 0)
{
/* Note: tunnel_conn has been consumed by
* tls_ops->init_connection
*/
ws->need_conn_close = true;
}
else
{
/* Note: restarting tls_ops->init_connection
* is not implemented
*/
DEBUGASSERT(ret != -EAGAIN &&
ret != -EINPROGRESS &&
ret != -EALREADY);
conn_close(ctx, tunnel_conn);
free(tunnel_conn);
}
} }
else else
{ {
conn->sockfd = tunnel_conn->sockfd; /* Note: restarting tls_ops->init_connection
ws->need_conn_close = true; * is not implemented
*/
DEBUGASSERT(ret != -EAGAIN &&
ret != -EINPROGRESS &&
ret != -EALREADY);
conn_close(ctx, tunnel_conn);
free(tunnel_conn); free(tunnel_conn);
} }
} }
else
{
conn->sockfd = tunnel_conn->sockfd;
ws->need_conn_close = true;
free(tunnel_conn);
}
} }
} }
else if (conn->tls) else if (conn->tls)
@ -2486,16 +2483,16 @@ int webclient_get_poll_info(FAR struct webclient_context *ctx,
* the tunneled connection. * the tunneled connection.
* *
* This function should be used exactly once after a successful * This function should be used exactly once after a successful
* call of webclient_perform with WEBCLIENT_FLAG_TUNNEL. * call of webclient_perform with WEBCLIENT_FLAG_TUNNEL, with
* http_status 2xx.
* *
* This function also disposes the given webclient_context. * This function also disposes the given webclient_context.
* The context will be invalid after the successful call of this * The context will be invalid after a call of this function.
* function.
* *
****************************************************************************/ ****************************************************************************/
int webclient_get_tunnel(FAR struct webclient_context *ctx, void webclient_get_tunnel(FAR struct webclient_context *ctx,
FAR struct webclient_conn_s **connp) FAR struct webclient_conn_s **connp)
{ {
struct wget_s *ws; struct wget_s *ws;
struct webclient_conn_s *conn; struct webclient_conn_s *conn;
@ -2510,6 +2507,4 @@ int webclient_get_tunnel(FAR struct webclient_context *ctx,
ws->conn = NULL; ws->conn = NULL;
free_ws(ws); free_ws(ws);
_SET_STATE(ctx, WEBCLIENT_CONTEXT_STATE_DONE); _SET_STATE(ctx, WEBCLIENT_CONTEXT_STATE_DONE);
return 0;
} }