Mtce: Improve efficiency of mtcAgent's end-of-batch message handling

The mtcAgent's message inbox batch handling was needlessly zeroing a
buffer that it would never use after it reached the last received
message.

This update refactors the mtc_service_inbox entry code so that the
message buffer zeroing operation only occurs on the unused part of
fully received messages. To facilitate this change, a new utility for
zeroing a bounded part of a mtce message buf was introduced to common
utils.

Two additional enhancements were also made to the same procedure:
 - variable scoping change.
 - hostaddr and hostname lookup scoping change.

Change-Id: Ia2ef97dad611507b824927ed1652c8df8b54eee5
Signed-off-by: Eric MacDonald <eric.macdonald@windriver.com>
This commit is contained in:
Eric MacDonald 2018-06-06 14:24:29 -04:00
parent c90cddb408
commit 85a30b56e6
3 changed files with 30 additions and 14 deletions

View File

@ -705,3 +705,15 @@ bool is_host_services_cmd ( unsigned int cmd )
}
return (false);
}
/* Used to fill the mtce message buffer starting after supplied 'bytes' count */
void zero_unused_msg_buf ( mtc_message_type & msg, int bytes)
{
if ( bytes < (int)sizeof(msg) )
{
char * ptr = (char *)&msg ;
ptr += (bytes) ;
memset ( ptr, 0, sizeof(msg)-bytes);
}
}

View File

@ -1226,6 +1226,8 @@ int daemon_log_message ( const char * hostname,
bool is_host_services_cmd ( unsigned int cmd );
void zero_unused_msg_buf ( mtc_message_type & msg, int bytes);
/** Runtime Trace Log Utilities */
void daemon_dump_membuf ( void );
void daemon_dump_membuf_banner ( void );

View File

@ -125,17 +125,8 @@ int mtc_service_inbox ( nodeLinkClass * obj_ptr,
int iface)
{
mtc_message_type msg ;
std::list<string>::iterator iter ;
int bytes = 0 ;
int rc = PASS ;
string ip = "0.0.0.0" ;
MEMSET_ZERO (msg);
string hostaddr = "" ;
string hostname = "" ;
if ( iface == INFRA_INTERFACE )
{
if ( ( obj_ptr ) &&
@ -143,20 +134,15 @@ int mtc_service_inbox ( nodeLinkClass * obj_ptr,
( sock_ptr->mtc_agent_infra_rx_socket ))
{
bytes = sock_ptr->mtc_agent_infra_rx_socket->read((char*)&msg, sizeof(msg));
hostaddr = sock_ptr->mtc_agent_infra_rx_socket->get_src_str();
hostname = obj_ptr->get_hostname ( hostaddr ) ;
}
else
{
ilog ("cannot receive from unprovisioned Infra socket\n");
return ( FAIL_NO_INFRA_PROV );
}
}
else
{
bytes = sock_ptr->mtc_agent_rx_socket->read((char*)&msg, sizeof(msg));
hostaddr = sock_ptr->mtc_agent_rx_socket->get_src_str();
hostname = obj_ptr->get_hostname ( hostaddr ) ;
}
if ( bytes <= 0 )
@ -173,8 +159,23 @@ int mtc_service_inbox ( nodeLinkClass * obj_ptr,
rx_error_count = 0 ;
}
zero_unused_msg_buf (msg, bytes);
string hostaddr = "" ;
string hostname = "" ;
if ( iface == INFRA_INTERFACE )
{
hostaddr = sock_ptr->mtc_agent_infra_rx_socket->get_src_str();
hostname = obj_ptr->get_hostname ( hostaddr ) ;
}
else
{
hostaddr = sock_ptr->mtc_agent_rx_socket->get_src_str();
hostname = obj_ptr->get_hostname ( hostaddr ) ;
}
if ( hostname.empty() )
{
std::list<string>::iterator iter ;
iter = std::find (unknown_ip_list.begin(), unknown_ip_list.end(), hostaddr );
if ( iter == unknown_ip_list.end() )
{
@ -541,6 +542,7 @@ int mtc_service_inbox ( nodeLinkClass * obj_ptr,
if ( daemon_get_cfg_ptr()->debug_msg )
{
int count = 0 ;
std::list<string>::iterator iter ;
for ( iter = unknown_ip_list.begin () ;
iter != unknown_ip_list.end () ;
iter++ )