refactor TimedReconnect and AQ_Reconnect to make more the same

This commit is contained in:
Douglas Clowes
2013-06-14 15:33:11 +10:00
parent aaeaff692e
commit 784372503c

View File

@@ -182,46 +182,46 @@ static int TimedReconnect(void *cntx, int mode)
* 0: The request is still in progress
* +1: The request succeeded
*/
if (iRet < 0) {
snprintf(line, 132, "Failed reconnect on AsyncQueue '%s'",
self->queue_name);
SICSLogWrite(line, eStatus);
NetWatchSetMode(self->nw_ctx, 0);
/* implement an exponential backoff within limits */
self->retryTimer = 2 * self->retryTimer;
if (self->retryTimer < 125)
self->retryTimer = 125;
if (self->retryTimer > 16000)
self->retryTimer = 16000;
NetWatchRegisterTimer(&self->nw_tmr, self->retryTimer, TimedReconnect,
self);
SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncWaiting\n",
self->queue_name, __func__, state_name(self->state));
self->state = eAsyncWaiting;
} else if (iRet == 0) {
snprintf(line, 132, "Inprogress reconnect on AsyncQueue '%s'",
self->queue_name);
NetWatchSetMode(self->nw_ctx, nwatch_write);
SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncConnecting\n",
self->queue_name, __func__, state_name(self->state));
self->state = eAsyncConnecting;
} else {
NetWatchSetMode(self->nw_ctx, nwatch_read);
SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncConnected\n",
self->queue_name, __func__, state_name(self->state));
self->state = eAsyncConnected;
snprintf(line, 132, "Reconnect on AsyncQueue '%s'", self->queue_name);
SICSLogWrite(line, eStatus);
AQ_Notify(self, AQU_RECONNECT);
if (iRet <= 0) {
if (iRet < 0) {
snprintf(line, 132, "Failed reconnect on AsyncQueue '%s'",
self->queue_name);
SICSLogWrite(line, eStatus);
/* Timer for retry */
NetWatchSetMode(self->nw_ctx, 0);
/* implement an exponential backoff within limits */
self->retryTimer = 2 * self->retryTimer;
if (self->retryTimer < 125)
self->retryTimer = 125;
if (self->retryTimer > 16000)
self->retryTimer = 16000;
NetWatchRegisterTimer(&self->nw_tmr, self->retryTimer,
TimedReconnect, self);
SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncWaiting\n",
self->queue_name, __func__, state_name(self->state));
self->state = eAsyncWaiting;
} else {
NetWatchSetMode(self->nw_ctx, nwatch_write);
SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncConnecting\n",
self->queue_name, __func__, state_name(self->state));
self->state = eAsyncConnecting;
/* await reconnect result in MyCallback */
}
return 1;
}
NetWatchSetMode(self->nw_ctx, nwatch_read);
SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncConnected\n",
self->queue_name, __func__, state_name(self->state));
self->state = eAsyncConnected;
snprintf(line, 132, "Reconnect on AsyncQueue '%s'", self->queue_name);
SICSLogWrite(line, eStatus);
AQ_Notify(self, AQU_RECONNECT);
return 1;
}
static int AQ_Reconnect(pAsyncQueue self)
{
int iRet;
int sock;
int flag = 1;
char line[132];
if (self->state != eAsyncConnected)
@@ -251,6 +251,7 @@ static int AQ_Reconnect(pAsyncQueue self)
if (iRet < 0) {
/* Timer for retry */
NetWatchSetMode(self->nw_ctx, 0);
/* implement an exponential backoff within limits */
self->retryTimer = 125; /* initial delay */
NetWatchRegisterTimer(&self->nw_tmr, self->retryTimer,
TimedReconnect, self);
@@ -262,7 +263,7 @@ static int AQ_Reconnect(pAsyncQueue self)
SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncConnecting\n",
self->queue_name, __func__, state_name(self->state));
self->state = eAsyncConnecting;
/* TODO await reconnect result */
/* await reconnect result in MyCallback */
}
return iRet;
}