summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar David Benjamin <davidben@mit.edu>2013-04-26 14:44:14 -0400
committerGravatar Karl Ramm <kcr@1ts.org>2013-08-08 00:24:58 -0400
commit380d198f6fe5b205f22d056f85fd8c1e63fd8890 (patch)
treef72b237b5e12fcdcc57f1a32495319ebf4dbbda8
parentece582b74f82b82209d795ce96db9ba7008c453f (diff)
Expose Z_Subscriptions as ZSubscriptions
With a custom send_routine that mirrors ZSrvSendList. This allows for an asynchronous version that replaces send_routine with non-blocking versions (and waits for ACKs out-of-band).
-rw-r--r--h/zephyr/zephyr.h4
-rw-r--r--lib/ZSubs.c51
2 files changed, 32 insertions, 23 deletions
diff --git a/h/zephyr/zephyr.h b/h/zephyr/zephyr.h
index 207624b..28baa7f 100644
--- a/h/zephyr/zephyr.h
+++ b/h/zephyr/zephyr.h
@@ -236,6 +236,10 @@ Code_t ZIfNotice(ZNotice_t *notice, struct sockaddr_in *from,
int (*predicate)(ZNotice_t *, void *), void *args);
Code_t ZPeekIfNotice(ZNotice_t *notice, struct sockaddr_in *from,
int (*predicate)(ZNotice_t *, char *), char *args);
+Code_t ZSubscriptions(ZSubscription_t *sublist, int nitems,
+ unsigned int port,
+ char *opcode,
+ Code_t (*send_routine)(ZNotice_t *, char *, int, int));
Code_t ZPunt(ZSubscription_t *sublist, int nitems, unsigned int port);
Code_t ZSubscribeTo(ZSubscription_t *sublist, int nitems,
unsigned int port);
diff --git a/lib/ZSubs.c b/lib/ZSubs.c
index bd09987..a3d0b78 100644
--- a/lib/ZSubs.c
+++ b/lib/ZSubs.c
@@ -17,10 +17,8 @@
static const char rcsid_ZSubscriptions_c[] = "$Id$";
#endif
-static Code_t Z_Subscriptions(register ZSubscription_t *sublist,
- int nitems, unsigned int port,
- char *opcode);
-static Code_t subscr_sendoff(ZNotice_t *notice, char **lyst, int num);
+static Code_t Z_SendAndWaitForServer(ZNotice_t *notice, char *buf, int len,
+ int waitforack);
#ifdef CMU_ZCTL_PUNT
Code_t
@@ -28,7 +26,8 @@ ZPunt(ZSubscription_t *sublist,
int nitems,
unsigned int port)
{
- return (Z_Subscriptions(sublist, nitems, port, "SUPPRESS"));
+ return (ZSubscriptions(sublist, nitems, port, "SUPPRESS",
+ Z_SendAndWaitForServer));
}
#endif
@@ -37,7 +36,8 @@ ZSubscribeTo(ZSubscription_t *sublist,
int nitems,
unsigned int port)
{
- return (Z_Subscriptions(sublist, nitems, port, CLIENT_SUBSCRIBE));
+ return (ZSubscriptions(sublist, nitems, port, CLIENT_SUBSCRIBE,
+ Z_SendAndWaitForServer));
}
Code_t
@@ -45,7 +45,8 @@ ZSubscribeToSansDefaults(ZSubscription_t *sublist,
int nitems,
unsigned int port)
{
- return (Z_Subscriptions(sublist, nitems, port, CLIENT_SUBSCRIBE_NODEFS));
+ return (ZSubscriptions(sublist, nitems, port, CLIENT_SUBSCRIBE_NODEFS,
+ Z_SendAndWaitForServer));
}
Code_t
@@ -53,14 +54,15 @@ ZUnsubscribeTo(ZSubscription_t *sublist,
int nitems,
unsigned int port)
{
- return (Z_Subscriptions(sublist, nitems, port, CLIENT_UNSUBSCRIBE));
+ return (ZSubscriptions(sublist, nitems, port, CLIENT_UNSUBSCRIBE,
+ Z_SendAndWaitForServer));
}
Code_t
ZCancelSubscriptions(unsigned int port)
{
- return (Z_Subscriptions((ZSubscription_t *)0, 0, port,
- CLIENT_CANCELSUB));
+ return (ZSubscriptions((ZSubscription_t *)0, 0, port, CLIENT_CANCELSUB,
+ Z_SendAndWaitForServer));
}
/*
@@ -69,11 +71,12 @@ ZCancelSubscriptions(unsigned int port)
* mis-interpret them.
*/
-static Code_t
-Z_Subscriptions(register ZSubscription_t *sublist,
- int nitems,
- unsigned int port,
- char *opcode)
+Code_t
+ZSubscriptions(register ZSubscription_t *sublist,
+ int nitems,
+ unsigned int port,
+ char *opcode,
+ Code_t (*send_routine)(ZNotice_t *, char *, int, int))
{
register int i, j;
int retval;
@@ -132,7 +135,7 @@ Z_Subscriptions(register ZSubscription_t *sublist,
numok = 0;
if (!nitems) {
/* there aren't really any, but we need to xmit anyway */
- retval = subscr_sendoff(&notice, list, 0);
+ retval = ZSrvSendList(&notice, list, 0, ZAUTH, send_routine);
free((char *)list);
return(retval);
}
@@ -156,7 +159,8 @@ Z_Subscriptions(register ZSubscription_t *sublist,
free((char *)list);
return(ZERR_FIELDLEN);
}
- retval = subscr_sendoff(&notice, &list[start*3], numok);
+ retval = ZSrvSendList(&notice, &list[start*3], numok * 3,
+ ZAUTH, send_routine);
if (retval) {
free((char *)list);
return(retval);
@@ -164,20 +168,21 @@ Z_Subscriptions(register ZSubscription_t *sublist,
start = -1;
}
if (numok)
- retval = subscr_sendoff(&notice, &list[start*3], numok);
+ retval = ZSrvSendList(&notice, &list[start*3], numok * 3,
+ ZAUTH, send_routine);
free((char *)list);
return(retval);
}
static Code_t
-subscr_sendoff(ZNotice_t *notice,
- char **lyst,
- int num)
+Z_SendAndWaitForServer(ZNotice_t *notice,
+ char *buf, int len,
+ int waitforack)
{
- register Code_t retval;
+ Code_t retval;
ZNotice_t retnotice;
- retval = ZSendList(notice, lyst, num*3, ZAUTH);
+ retval = ZSendPacket(buf, len, waitforack);
if (retval != ZERR_NONE)
return (retval);
if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *)0,