Skip to content

Commit

Permalink
Merge "DO NOT MERGE ANYWHERE: (nyc-dr1-dev) Adding retry logic within…
Browse files Browse the repository at this point in the history
… loc_sync_send_req() API" into nyc-dr1-dev
  • Loading branch information
Adam Seaton authored and Android (Google) Code Review committed Aug 22, 2016
2 parents 66652cf + 6fcee60 commit e6297fc
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions location/loc_api/loc_api_v02/loc_api_sync_req.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,45 +497,56 @@ locClientStatusEnumType loc_sync_send_req
locClientStatusEnumType status = eLOC_CLIENT_SUCCESS ;
int select_id;
int rc = 0;
int sendReqRetryRem = 5; // Number of retries remaining

// Select the callback we are waiting for
select_id = loc_sync_select_ind(client_handle, ind_id, req_id,
ind_payload_ptr);

if (select_id >= 0)
{
status = locClientSendReq (client_handle, req_id, req_payload);
LOC_LOGV("%s:%d]: select_id = %d,locClientSendReq returned %d\n",
__func__, __LINE__, select_id, status);
// Loop to retry few times in case of failures
do
{
status = locClientSendReq (client_handle, req_id, req_payload);
LOC_LOGV("%s:%d]: select_id = %d,locClientSendReq returned %d\n",
__func__, __LINE__, select_id, status);

if (status == eLOC_CLIENT_SUCCESS )
{
// Wait for the indication callback
if (( rc = loc_sync_wait_for_ind( select_id,
timeout_msec / 1000,
ind_id) ) < 0)
{
if ( rc == -ETIMEDOUT)
status = eLOC_CLIENT_FAILURE_TIMEOUT;
else
status = eLOC_CLIENT_FAILURE_INTERNAL;

// Callback waiting failed
LOC_LOGE("%s:%d]: loc_api_wait_for_ind failed, err %d, "
"select id %d, status %s", __func__, __LINE__, rc ,
select_id, loc_get_v02_client_status_name(status));
}
else
{
status = eLOC_CLIENT_SUCCESS;
LOC_LOGV("%s:%d]: success (select id %d)\n",
__func__, __LINE__, select_id);
}
}

} while(( status == eLOC_CLIENT_FAILURE_ENGINE_BUSY ||
status == eLOC_CLIENT_FAILURE_PHONE_OFFLINE ||
status == eLOC_CLIENT_FAILURE_INTERNAL ) &&
sendReqRetryRem-- > 0);

if (status != eLOC_CLIENT_SUCCESS )
{
loc_free_slot(select_id);
}
else
{
// Wait for the indication callback
if (( rc = loc_sync_wait_for_ind( select_id,
timeout_msec / 1000,
ind_id) ) < 0)
{
if ( rc == -ETIMEDOUT)
status = eLOC_CLIENT_FAILURE_TIMEOUT;
else
status = eLOC_CLIENT_FAILURE_INTERNAL;

// Callback waiting failed
LOC_LOGE("%s:%d]: loc_api_wait_for_ind failed, err %d, "
"select id %d, status %s", __func__, __LINE__, rc ,
select_id, loc_get_v02_client_status_name(status));
}
else
{
status = eLOC_CLIENT_SUCCESS;
LOC_LOGV("%s:%d]: success (select id %d)\n",
__func__, __LINE__, select_id);
}
}
} /* select id */

return status;
Expand Down

0 comments on commit e6297fc

Please sign in to comment.