| 1 |
/* |
| 2 |
* ccmversion.c: routines that handle information while in the version |
| 3 |
* request state |
| 4 |
* |
| 5 |
* Copyright (c) International Business Machines Corp., 2002 |
| 6 |
* Author: Ram Pai ([email protected]) |
| 7 |
* |
| 8 |
* This program is free software; you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation; either version 2 of the License, or |
| 11 |
* (at your option) any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program; if not, write to the Free Software |
| 20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 |
* |
| 22 |
*/ |
| 23 |
#include <lha_internal.h> |
| 24 |
#include <ccm.h> |
| 25 |
|
| 26 |
#define MAXTRIES 3 |
| 27 |
|
| 28 |
#define VERSION_GET_TIMER(ver) (ver->time) |
| 29 |
#define VERSION_SET_TIMER(ver, t) ver->time = t |
| 30 |
#define VERSION_GET_TRIES(ver) ver->numtries |
| 31 |
#define VERSION_RESET_TRIES(ver) ver->numtries = 0 |
| 32 |
#define VERSION_INC_TRIES(ver) (ver->numtries)++ |
| 33 |
#define VERSION_INC_NRESP(ver) (ver->n_resp)++ |
| 34 |
#define VERSION_SET_NRESP(ver,val) ver->n_resp = val |
| 35 |
#define VERSION_GET_NRESP(ver) ver->n_resp |
| 36 |
|
| 37 |
|
| 38 |
/* */ |
| 39 |
/* return true if we have waited long enough for a response */ |
| 40 |
/* for our version request. */ |
| 41 |
/* */ |
| 42 |
static int |
| 43 |
version_timeout_expired(ccm_version_t *ver, longclock_t timeout) |
| 44 |
{ |
| 45 |
return(ccm_timeout(VERSION_GET_TIMER(ver), ccm_get_time(), |
| 46 |
timeout)); |
| 47 |
} |
| 48 |
|
| 49 |
/* */ |
| 50 |
/* reset all the data structures used to track the version request */ |
| 51 |
/* state. */ |
| 52 |
/* */ |
| 53 |
void |
| 54 |
version_reset(ccm_version_t *ver) |
| 55 |
{ |
| 56 |
VERSION_SET_TIMER(ver,ccm_get_time()); |
| 57 |
VERSION_RESET_TRIES(ver); |
| 58 |
VERSION_SET_NRESP(ver,0); |
| 59 |
} |
| 60 |
|
| 61 |
/* */ |
| 62 |
/* return true if version request has message has to be resent. */ |
| 63 |
/* else return false. */ |
| 64 |
/* */ |
| 65 |
int |
| 66 |
version_retry(ccm_version_t *ver, longclock_t timeout) |
| 67 |
{ |
| 68 |
if(version_timeout_expired(ver, timeout)) { |
| 69 |
ccm_debug2(LOG_DEBUG, "version_retry:%d tries left" |
| 70 |
, 3-VERSION_GET_TRIES(ver)); |
| 71 |
if(VERSION_GET_TRIES(ver) == MAXTRIES) { |
| 72 |
return VER_TRY_END; |
| 73 |
} else { |
| 74 |
VERSION_INC_TRIES(ver); |
| 75 |
VERSION_SET_TIMER(ver,ccm_get_time()); |
| 76 |
return VER_TRY_AGAIN; |
| 77 |
} |
| 78 |
} |
| 79 |
return VER_NO_CHANGE; |
| 80 |
} |
| 81 |
|
| 82 |
/* */ |
| 83 |
/* The caller informs us: */ |
| 84 |
/* "please note that there is some activity going on in the cluster. */ |
| 85 |
/* Probably you may want to try for some more time" */ |
| 86 |
/* */ |
| 87 |
void |
| 88 |
version_some_activity(ccm_version_t *ver) |
| 89 |
{ |
| 90 |
VERSION_RESET_TRIES(ver); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
void |
| 95 |
version_inc_nresp(ccm_version_t *ver) |
| 96 |
{ |
| 97 |
VERSION_INC_NRESP(ver); |
| 98 |
} |
| 99 |
|
| 100 |
void |
| 101 |
version_set_nresp(ccm_version_t *ver, int val) |
| 102 |
{ |
| 103 |
VERSION_SET_NRESP(ver, val); |
| 104 |
} |
| 105 |
|
| 106 |
unsigned int |
| 107 |
version_get_nresp(ccm_version_t *ver) |
| 108 |
{ |
| 109 |
return VERSION_GET_NRESP(ver); |
| 110 |
} |