ntfsend is blocked in case TRY_AGAIN error. It should do the retry in
limit time.
---
src/ntf/tools/ntfclient.c | 75 ++++++++-------
src/ntf/tools/ntfsend.c | 240 +++++++++++++++-------------------------------
2 files changed, 120 insertions(+), 195 deletions(-)
diff --git a/src/ntf/tools/ntfclient.c b/src/ntf/tools/ntfclient.c
index 472be4bc3..ce93bb164 100644
--- a/src/ntf/tools/ntfclient.c
+++ b/src/ntf/tools/ntfclient.c
@@ -21,10 +21,13 @@
#include <saAmf.h>
#include <saClm.h>
#include <saNtf.h>
+#include "base/osaf_time.h"
#include "ntf/tools/ntfclient.h"
#include "ntf/tools/ntfconsumer.h"
#include <limits.h>
+const uint64_t kWaitTime = 10*1000; // Wait for timeout is 10 seconds
+
/* help functions for printouts */
void ntfsvtools_exitIfFalse(const char *file, unsigned int line, int
expression)
{
@@ -1097,18 +1100,19 @@ SaAisErrorT ntftool_saNtfInitialize(SaNtfHandleT
*ntfHandle,
const SaNtfCallbacksT *ntfCallbacks,
SaVersionT *version)
{
- int curRetryTime = 0;
SaAisErrorT rc;
+ struct timespec timeout_time;
SaVersionT ntf_version = *version;
+
+ osaf_set_millis_timeout(kWaitTime, &timeout_time);
do {
rc = saNtfInitialize(ntfHandle, ntfCallbacks, &ntf_version);
if (rc == SA_AIS_ERR_TRY_AGAIN) {
- sleep(gl_apiRetry);
- curRetryTime += gl_apiRetry;
+ osaf_nanosleep(&kHundredMilliseconds);
ntf_version = *version;
} else
break;
- } while (curRetryTime < gl_apiTolerance);
+ } while (!osaf_is_timeout(&timeout_time));
return rc;
}
@@ -1119,16 +1123,17 @@ SaAisErrorT ntftool_saNtfInitialize(SaNtfHandleT
*ntfHandle,
SaAisErrorT ntftool_saNtfDispatch(SaNtfHandleT ntfHandle,
SaDispatchFlagsT dispatchFlags)
{
- int curRetryTime = 0;
SaAisErrorT rc;
+ struct timespec timeout_time;
+
+ osaf_set_millis_timeout(kWaitTime, &timeout_time);
do {
rc = saNtfDispatch(ntfHandle, dispatchFlags);
if (rc == SA_AIS_ERR_TRY_AGAIN) {
- sleep(gl_apiRetry);
- curRetryTime += gl_apiRetry;
+ osaf_nanosleep(&kHundredMilliseconds);
} else
break;
- } while (curRetryTime < gl_apiTolerance);
+ } while (!osaf_is_timeout(&timeout_time));
return rc;
}
@@ -1139,16 +1144,17 @@ SaAisErrorT ntftool_saNtfDispatch(SaNtfHandleT
ntfHandle,
SaAisErrorT
ntftool_saNtfNotificationSend(SaNtfNotificationHandleT notificationHandle)
{
- int curRetryTime = 0;
SaAisErrorT rc;
+ struct timespec timeout_time;
+
+ osaf_set_millis_timeout(kWaitTime, &timeout_time);
do {
rc = saNtfNotificationSend(notificationHandle);
if (rc == SA_AIS_ERR_TRY_AGAIN) {
- sleep(gl_apiRetry);
- curRetryTime += gl_apiRetry;
+ osaf_nanosleep(&kHundredMilliseconds);
} else
break;
- } while (curRetryTime < gl_apiTolerance);
+ } while (!osaf_is_timeout(&timeout_time));
return rc;
}
@@ -1160,17 +1166,18 @@ SaAisErrorT ntftool_saNtfNotificationSubscribe(
const SaNtfNotificationTypeFilterHandlesT *notificationFilterHandles,
SaNtfSubscriptionIdT subscriptionId)
{
- int curRetryTime = 0;
SaAisErrorT rc;
+ struct timespec timeout_time;
+
+ osaf_set_millis_timeout(kWaitTime, &timeout_time);
do {
rc = saNtfNotificationSubscribe(notificationFilterHandles,
subscriptionId);
if (rc == SA_AIS_ERR_TRY_AGAIN) {
- sleep(gl_apiRetry);
- curRetryTime += gl_apiRetry;
+ osaf_nanosleep(&kHundredMilliseconds);
} else
break;
- } while (curRetryTime < gl_apiTolerance);
+ } while (!osaf_is_timeout(&timeout_time));
return rc;
}
@@ -1181,16 +1188,17 @@ SaAisErrorT ntftool_saNtfNotificationSubscribe(
SaAisErrorT
ntftool_saNtfNotificationUnsubscribe(SaNtfSubscriptionIdT subscriptionId)
{
- int curRetryTime = 0;
SaAisErrorT rc;
+ struct timespec timeout_time;
+
+ osaf_set_millis_timeout(kWaitTime, &timeout_time);
do {
rc = saNtfNotificationUnsubscribe(subscriptionId);
if (rc == SA_AIS_ERR_TRY_AGAIN) {
- sleep(gl_apiRetry);
- curRetryTime += gl_apiRetry;
+ osaf_nanosleep(&kHundredMilliseconds);
} else
break;
- } while (curRetryTime < gl_apiTolerance);
+ } while (!osaf_is_timeout(&timeout_time));
return rc;
}
@@ -1203,17 +1211,18 @@ SaAisErrorT ntftool_saNtfNotificationReadInitialize(
const SaNtfNotificationTypeFilterHandlesT *notificationFilterHandles,
SaNtfReadHandleT *readHandle)
{
- int curRetryTime = 0;
SaAisErrorT rc;
+ struct timespec timeout_time;
+
+ osaf_set_millis_timeout(kWaitTime, &timeout_time);
do {
rc = saNtfNotificationReadInitialize(
searchCriteria, notificationFilterHandles, readHandle);
if (rc == SA_AIS_ERR_TRY_AGAIN) {
- sleep(gl_apiRetry);
- curRetryTime += gl_apiRetry;
+ osaf_nanosleep(&kHundredMilliseconds);
} else
break;
- } while (curRetryTime < gl_apiTolerance);
+ } while (!osaf_is_timeout(&timeout_time));
return rc;
}
@@ -1226,17 +1235,18 @@ ntftool_saNtfNotificationReadNext(SaNtfReadHandleT
readHandle,
SaNtfSearchDirectionT searchDirection,
SaNtfNotificationsT *notification)
{
- int curRetryTime = 0;
SaAisErrorT rc;
+ struct timespec timeout_time;
+
+ osaf_set_millis_timeout(kWaitTime, &timeout_time);
do {
rc = saNtfNotificationReadNext(readHandle, searchDirection,
notification);
if (rc == SA_AIS_ERR_TRY_AGAIN) {
- sleep(gl_apiRetry);
- curRetryTime += gl_apiRetry;
+ osaf_nanosleep(&kHundredMilliseconds);
} else
break;
- } while (curRetryTime < gl_apiTolerance);
+ } while (!osaf_is_timeout(&timeout_time));
return rc;
}
@@ -1246,16 +1256,17 @@ ntftool_saNtfNotificationReadNext(SaNtfReadHandleT
readHandle,
*/
SaAisErrorT ntftool_saNtfNotificationReadFinalize(SaNtfReadHandleT readhandle)
{
- int curRetryTime = 0;
SaAisErrorT rc;
+ struct timespec timeout_time;
+
+ osaf_set_millis_timeout(kWaitTime, &timeout_time);
do {
rc = saNtfNotificationReadFinalize(readhandle);
if (rc == SA_AIS_ERR_TRY_AGAIN) {
- sleep(gl_apiRetry);
- curRetryTime += gl_apiRetry;
+ osaf_nanosleep(&kHundredMilliseconds);
} else
break;
- } while (curRetryTime < gl_apiTolerance);
+ } while (!osaf_is_timeout(&timeout_time));
return rc;
}
diff --git a/src/ntf/tools/ntfsend.c b/src/ntf/tools/ntfsend.c
index 4c59fe83c..43c8f3138 100644
--- a/src/ntf/tools/ntfsend.c
+++ b/src/ntf/tools/ntfsend.c
@@ -405,18 +405,12 @@ static SaAisErrorT sendNotification(
unsigned int repeat = notificationParams->repeateSends;
- do {
- errorCode = ntftool_saNtfInitialize(&ntfHandle, NULL, &version);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf("ntftool_saNtfInitialize %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = ntftool_saNtfInitialize(&ntfHandle, NULL, &version);
+ if (errorCode != SA_AIS_OK) {
+ (void)printf("ntftool_saNtfInitialize %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
switch (notificationParams->notificationType) {
case SA_NTF_TYPE_ALARM:
@@ -854,21 +848,13 @@ repeatedSend:
case SA_NTF_TYPE_ALARM:
/* Send the alarm notification */
- do {
-
- errorCode = ntftool_saNtfNotificationSend(
- myAlarmNotification.notificationHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf(
- "ntftool_saNtfNotificationSend %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = ntftool_saNtfNotificationSend(
+ myAlarmNotification.notificationHandle);
+ if (SA_AIS_OK != errorCode) {
+ (void)printf("ntftool_saNtfNotificationSend %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
ntfId =
*(myAlarmNotification.notificationHeader.notificationId);
@@ -884,38 +870,25 @@ repeatedSend:
goto repeatedSend;
}
- do {
- errorCode = saNtfNotificationFree(
- myAlarmNotification.notificationHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf("saNtfNotificationFree %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = saNtfNotificationFree(
+ myAlarmNotification.notificationHandle);
+ if (SA_AIS_OK != errorCode) {
+ (void)printf("saNtfNotificationFree %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
break;
case SA_NTF_TYPE_STATE_CHANGE:
/* Send the state change notification */
- do {
- errorCode = ntftool_saNtfNotificationSend(
- myStateChangeNotification.notificationHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf(
- "ntftool_saNtfNotificationSend %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = ntftool_saNtfNotificationSend(
+ myStateChangeNotification.notificationHandle);
+ if (SA_AIS_OK != errorCode) {
+ (void)printf("ntftool_saNtfNotificationSend %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
ntfId = *(myStateChangeNotification.notificationHeader
.notificationId);
@@ -931,39 +904,26 @@ repeatedSend:
goto repeatedSend;
}
- do {
- errorCode = saNtfNotificationFree(
- myStateChangeNotification.notificationHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf("saNtfNotificationFree %s\n",
- error_output(errorCode));
- return errorCode;
- }
- usleep(100000);
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = saNtfNotificationFree(
+ myStateChangeNotification.notificationHandle);
+ if (SA_AIS_OK != errorCode) {
+ (void)printf("saNtfNotificationFree %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
break;
case SA_NTF_TYPE_OBJECT_CREATE_DELETE:
/* Send the object create/delete notification */
- do {
-
- errorCode = ntftool_saNtfNotificationSend(
- myObjectCreateDeleteNotification
- .notificationHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf(
- "ntftool_saNtfNotificationSend %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = ntftool_saNtfNotificationSend(
+ myObjectCreateDeleteNotification.notificationHandle);
+ if (SA_AIS_OK != errorCode) {
+ (void)printf("ntftool_saNtfNotificationSend %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
ntfId = *(myObjectCreateDeleteNotification.notificationHeader
.notificationId);
@@ -979,40 +939,25 @@ repeatedSend:
goto repeatedSend;
}
- do {
-
- errorCode = saNtfNotificationFree(
- myObjectCreateDeleteNotification
- .notificationHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf("saNtfNotificationFree %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = saNtfNotificationFree(
+ myObjectCreateDeleteNotification.notificationHandle);
+ if (SA_AIS_OK != errorCode) {
+ (void)printf("saNtfNotificationFree %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
break;
case SA_NTF_TYPE_ATTRIBUTE_CHANGE:
/* Send the attribute change notification */
- do {
- errorCode = ntftool_saNtfNotificationSend(
- myAttributeChangeNotification.notificationHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf(
- "ntftool_saNtfNotificationSend %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = ntftool_saNtfNotificationSend(
+ myAttributeChangeNotification.notificationHandle);
+ if (SA_AIS_OK != errorCode) {
+ (void)printf("ntftool_saNtfNotificationSend %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
ntfId = *(myAttributeChangeNotification.notificationHeader
.notificationId);
@@ -1027,40 +972,26 @@ repeatedSend:
goto repeatedSend;
}
- do {
-
- errorCode = saNtfNotificationFree(
- myAttributeChangeNotification.notificationHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf("saNtfNotificationFree %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = saNtfNotificationFree(
+ myAttributeChangeNotification.notificationHandle);
+ if (SA_AIS_OK != errorCode) {
+ (void)printf("saNtfNotificationFree %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
break;
case SA_NTF_TYPE_SECURITY_ALARM: /* Send the state change notification
*/
- do {
- errorCode = ntftool_saNtfNotificationSend(
- mySecurityAlarmNotification.notificationHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf(
- "ntftool_saNtfNotificationSend %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = ntftool_saNtfNotificationSend(
+ mySecurityAlarmNotification.notificationHandle);
+ if (SA_AIS_OK != errorCode) {
+ (void)printf("ntftool_saNtfNotificationSend %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
ntfId = *(mySecurityAlarmNotification.notificationHeader
.notificationId);
@@ -1075,19 +1006,13 @@ repeatedSend:
goto repeatedSend;
}
- do {
- errorCode = saNtfNotificationFree(
- mySecurityAlarmNotification.notificationHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf("saNtfNotificationFree %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ errorCode = saNtfNotificationFree(
+ mySecurityAlarmNotification.notificationHandle);
+ if (SA_AIS_OK != errorCode) {
+ (void)printf("saNtfNotificationFree %s\n",
+ error_output(errorCode));
+ return errorCode;
+ }
break;
@@ -1096,18 +1021,7 @@ repeatedSend:
break;
}
- do {
- errorCode = saNtfFinalize(ntfHandle);
- if (SA_AIS_OK != errorCode &&
- SA_AIS_ERR_TRY_AGAIN != errorCode) {
- (void)printf("saNtfFinalize %s\n",
- error_output(errorCode));
- return errorCode;
- }
- if (SA_AIS_ERR_TRY_AGAIN == errorCode) {
- usleep(100000);
- }
- } while (SA_AIS_ERR_TRY_AGAIN == errorCode);
+ saNtfFinalize(ntfHandle);
return SA_AIS_OK;