Skip to content

Commit afd38b4

Browse files
committed
Revert iterations change
Signed-off-by: Gaurav Aggarwal <[email protected]>
1 parent db45df7 commit afd38b4

File tree

1 file changed

+44
-69
lines changed

1 file changed

+44
-69
lines changed

demos/http/http_demo_mutual_auth/http_demo_mutual_auth.c

Lines changed: 44 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@
5858
#error "Please define a POST_PATH."
5959
#endif
6060

61-
/**
62-
* @brief Delay in seconds between each iteration of the demo.
63-
*/
64-
#define DEMO_LOOP_DELAY_SECONDS ( 5U )
65-
6661
/* Check that a path for Root CA certificate is defined. */
6762
#ifndef ROOT_CA_CERT_PATH
6863
#error "Please define a ROOT_CA_CERT_PATH."
@@ -113,11 +108,6 @@
113108
*/
114109
#define REQUEST_BODY_LENGTH ( sizeof( REQUEST_BODY ) - 1 )
115110

116-
/**
117-
* @brief Number of HTTP paths to request.
118-
*/
119-
#define NUMBER_HTTP_PATHS ( 4 )
120-
121111
/**
122112
* @brief A buffer used in the demo for storing HTTP request headers and
123113
* HTTP response headers and body.
@@ -362,76 +352,61 @@ int main( int argc,
362352
/* Set the pParams member of the network context with desired transport. */
363353
networkContext.pParams = &opensslParams;
364354

365-
for( ; ; )
355+
/**************************** Connect. ******************************/
356+
357+
/* Establish TLS connection on top of TCP connection using OpenSSL. */
358+
if( returnStatus == EXIT_SUCCESS )
366359
{
367-
int i = 0;
360+
LogInfo( ( "Performing TLS handshake on top of the TCP connection." ) );
368361

369-
/**************************** Connect. ******************************/
362+
/* Attempt to connect to the HTTP server. If connection fails, retry after
363+
* a timeout. Timeout value will be exponentially increased till the maximum
364+
* attempts are reached or maximum timeout value is reached. The function
365+
* returns EXIT_FAILURE if the TCP connection cannot be established to
366+
* broker after configured number of attempts. */
367+
returnStatus = connectToServerWithBackoffRetries( connectToServer,
368+
&networkContext );
370369

371-
/* Establish TLS connection on top of TCP connection using OpenSSL. */
372-
if( returnStatus == EXIT_SUCCESS )
370+
if( returnStatus == EXIT_FAILURE )
373371
{
374-
LogInfo( ( "Performing TLS handshake on top of the TCP connection." ) );
375-
376-
/* Attempt to connect to the HTTP server. If connection fails, retry after
377-
* a timeout. Timeout value will be exponentially increased till the maximum
378-
* attempts are reached or maximum timeout value is reached. The function
379-
* returns EXIT_FAILURE if the TCP connection cannot be established to
380-
* broker after configured number of attempts. */
381-
returnStatus = connectToServerWithBackoffRetries( connectToServer,
382-
&networkContext );
383-
384-
if( returnStatus == EXIT_FAILURE )
385-
{
386-
/* Log error to indicate connection failure after all
387-
* reconnect attempts are over. */
388-
LogError( ( "Failed to connect to HTTP server %.*s.",
389-
( int32_t ) AWS_IOT_ENDPOINT_LENGTH,
390-
AWS_IOT_ENDPOINT ) );
391-
}
392-
}
393-
394-
/* Define the transport interface. */
395-
if( returnStatus == EXIT_SUCCESS )
396-
{
397-
( void ) memset( &transportInterface, 0, sizeof( transportInterface ) );
398-
transportInterface.recv = Openssl_Recv;
399-
transportInterface.send = Openssl_Send;
400-
transportInterface.pNetworkContext = &networkContext;
372+
/* Log error to indicate connection failure after all
373+
* reconnect attempts are over. */
374+
LogError( ( "Failed to connect to HTTP server %.*s.",
375+
( int32_t ) AWS_IOT_ENDPOINT_LENGTH,
376+
AWS_IOT_ENDPOINT ) );
401377
}
378+
}
402379

403-
/*********************** Send HTTPS requests. ************************/
380+
/* Define the transport interface. */
381+
if( returnStatus == EXIT_SUCCESS )
382+
{
383+
( void ) memset( &transportInterface, 0, sizeof( transportInterface ) );
384+
transportInterface.recv = Openssl_Recv;
385+
transportInterface.send = Openssl_Send;
386+
transportInterface.pNetworkContext = &networkContext;
387+
}
404388

405-
for( i = 0; i < NUMBER_HTTP_PATHS; i++ )
406-
{
407-
if( returnStatus == EXIT_SUCCESS )
408-
{
409-
returnStatus = sendHttpRequest( &transportInterface,
410-
HTTP_METHOD_POST,
411-
HTTP_METHOD_POST_LENGTH,
412-
POST_PATH,
413-
POST_PATH_LENGTH );
414-
}
415-
else
416-
{
417-
break;
418-
}
419-
}
389+
/*********************** Send HTTPS request. ************************/
420390

421-
if( returnStatus == EXIT_SUCCESS )
422-
{
423-
/* Log message indicating an iteration completed successfully. */
424-
LogInfo( ( "Demo completed successfully." ) );
425-
}
391+
if( returnStatus == EXIT_SUCCESS )
392+
{
393+
returnStatus = sendHttpRequest( &transportInterface,
394+
HTTP_METHOD_POST,
395+
HTTP_METHOD_POST_LENGTH,
396+
POST_PATH,
397+
POST_PATH_LENGTH );
398+
}
426399

427-
/************************** Disconnect. *****************************/
400+
if( returnStatus == EXIT_SUCCESS )
401+
{
402+
/* Log message indicating an iteration completed successfully. */
403+
LogInfo( ( "Demo completed successfully." ) );
404+
}
428405

429-
/* End TLS session, then close TCP connection. */
430-
( void ) Openssl_Disconnect( &networkContext );
406+
/************************** Disconnect. *****************************/
431407

432-
LogInfo( ( "Short delay before starting the next iteration....\n" ) );
433-
sleep( DEMO_LOOP_DELAY_SECONDS );
434-
}
408+
/* End TLS session, then close TCP connection. */
409+
( void ) Openssl_Disconnect( &networkContext );
435410

436411
return returnStatus;
437412
}

0 commit comments

Comments
 (0)