summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar John Kohl <jtkohl@mit.edu>1988-06-30 14:19:07 +0000
committerGravatar John Kohl <jtkohl@mit.edu>1988-06-30 14:19:07 +0000
commit198f9bfc7491a847c549b30d119dab4a21029111 (patch)
treeece6d18afa424130ea6ca1103c990df22025c9f6 /lib
parent075a1dd9cc55b16f1a0eb19a8a88ede818d1155b (diff)
add code to time out and/or detect old servers
Diffstat (limited to 'lib')
-rw-r--r--lib/ZLocateU.c35
-rw-r--r--lib/ZRetSubs.c39
2 files changed, 63 insertions, 11 deletions
diff --git a/lib/ZLocateU.c b/lib/ZLocateU.c
index 4475ca2..3959eda 100644
--- a/lib/ZLocateU.c
+++ b/lib/ZLocateU.c
@@ -28,6 +28,10 @@ Code_t ZLocateUser(user, nlocs)
ZNotice_t notice, retnotice;
char *ptr, *end;
int nrecv, ack;
+ fd_set read, write, except;
+ int gotone;
+ struct timeval tv;
+
retval = ZFlushLocations();
if (retval != ZERR_NONE && retval != ZERR_NOLOCATIONS)
@@ -54,15 +58,38 @@ Code_t ZLocateUser(user, nlocs)
nrecv = ack = 0;
while (!nrecv || !ack) {
- if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *) 0,
- ZCompareMultiUIDPred,
- (char *)&notice.z_multiuid)) != ZERR_NONE)
- return (retval);
+ tv.tv_sec = 0;
+ tv.tv_usec = 500000;
+ for (i=0;i<HM_TIMEOUT*2;i++) { /* 30 secs in 1/2 sec
+ intervals */
+ gotone = 0;
+ if (select(0, &read, &write, &except, &tv) < 0)
+ return (errno);
+ retval = ZCheckIfNotice(&retnotice,
+ (struct sockaddr_in *)0,
+ ZCompareMultiUIDPred,
+ (char *)&notice.z_multiuid);
+ if (retval == ZERR_NONE) {
+ gotone = 1;
+ break;
+ }
+ if (retval != ZERR_NONOTICE)
+ return(retval);
+ }
+
+ if (!gotone)
+ return(ETIMEDOUT);
if (retnotice.z_kind == SERVNAK) {
ZFreeNotice(&retnotice);
return (ZERR_SERVNAK);
}
+ /* non-matching protocol version numbers means the
+ server is probably an older version--must punt */
+ if (strcmp(notice.z_version,retnotice.z_version)) {
+ ZFreeNotice(&retnotice);
+ return(ZERR_VERS);
+ }
if (retnotice.z_kind == SERVACK &&
!strcmp(retnotice.z_opcode,LOCATE_LOCATE)) {
ack = 1;
diff --git a/lib/ZRetSubs.c b/lib/ZRetSubs.c
index 3dc4cad..dabf9b9 100644
--- a/lib/ZRetSubs.c
+++ b/lib/ZRetSubs.c
@@ -60,9 +60,13 @@ static Code_t Z_RetSubs(notice, nsubs)
register ZNotice_t *notice;
int *nsubs;
{
- int i,retval,nrecv,gimmeack;
+ int retval,nrecv,gimmeack;
+ register int i;
ZNotice_t retnotice;
char *ptr,*end,*ptr2;
+ fd_set read, write, except;
+ struct timeval tv;
+ int gotone;
retval = ZFlushSubscriptions();
@@ -89,17 +93,38 @@ static Code_t Z_RetSubs(notice, nsubs)
__subscriptions_list = (ZSubscription_t *) 0;
while (!nrecv || !gimmeack) {
- if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *) 0,
- ZCompareMultiUIDPred,
- (char *)&notice->z_multiuid))
- != ZERR_NONE)
- return (retval);
+ tv.tv_sec = 0;
+ tv.tv_usec = 500000;
+ for (i=0;i<HM_TIMEOUT*2;i++) { /* 30 secs in 1/2 sec
+ intervals */
+ gotone = 0;
+ if (select(0, &read, &write, &except, &tv) < 0)
+ return (errno);
+ retval = ZCheckIfNotice(&retnotice,
+ (struct sockaddr_in *)0,
+ ZCompareMultiUIDPred,
+ (char *)&notice->z_multiuid);
+ if (retval == ZERR_NONE) {
+ gotone = 1;
+ break;
+ }
+ if (retval != ZERR_NONOTICE)
+ return(retval);
+ }
+
+ if (!gotone)
+ return(ETIMEDOUT);
if (retnotice.z_kind == SERVNAK) {
ZFreeNotice(&retnotice);
return (ZERR_SERVNAK);
}
-
+ /* non-matching protocol version numbers means the
+ server is probably an older version--must punt */
+ if (strcmp(notice->z_version,retnotice.z_version)) {
+ ZFreeNotice(&retnotice);
+ return(ZERR_VERS);
+ }
if (retnotice.z_kind == SERVACK &&
!strcmp(retnotice.z_opcode,notice->z_opcode)) {
ZFreeNotice(&retnotice);