summaryrefslogtreecommitdiff
path: root/lib/ZPeekIfNot.c
diff options
context:
space:
mode:
authorGravatar Robert S. French <rfrench@mit.edu>1988-05-17 17:21:01 +0000
committerGravatar Robert S. French <rfrench@mit.edu>1988-05-17 17:21:01 +0000
commit031ec0f258f152c1e20905b381aa7f5974db1f3d (patch)
tree1c15619ec8a5192e2d5095c6efde5e9a47ddc7ce /lib/ZPeekIfNot.c
parent4d21b4b5da809cdf4499190a1e27bff679a90422 (diff)
All sorts of changes for ver 0.2
Diffstat (limited to 'lib/ZPeekIfNot.c')
-rw-r--r--lib/ZPeekIfNot.c84
1 files changed, 39 insertions, 45 deletions
diff --git a/lib/ZPeekIfNot.c b/lib/ZPeekIfNot.c
index b376002..fab3c2b 100644
--- a/lib/ZPeekIfNot.c
+++ b/lib/ZPeekIfNot.c
@@ -20,54 +20,48 @@ static char rcsid_ZPeekIfNotice_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZPeekIfNotice(buffer,buffer_len,notice,from,predicate,args)
- ZPacket_t buffer;
- int buffer_len;
- ZNotice_t *notice;
- struct sockaddr_in *from;
- int (*predicate)();
- char *args;
+Code_t ZPeekIfNotice(notice, from, predicate, args)
+ ZNotice_t *notice;
+ struct sockaddr_in *from;
+ int (*predicate)();
+ char *args;
{
- ZNotice_t tmpnotice;
- int qcount,retval;
- struct _Z_InputQ *qptr;
+ ZNotice_t tmpnotice;
+ Code_t retval;
+ char *buffer;
+ struct _Z_InputQ *qptr;
- if (__Q_Length)
- retval = Z_ReadEnqueue();
- else
- retval = Z_ReadWait();
+ if (ZQLength())
+ retval = Z_ReadEnqueue();
+ else
+ retval = Z_ReadWait();
- if (retval != ZERR_NONE)
- return (retval);
+ if (retval != ZERR_NONE)
+ return (retval);
- qptr = __Q_Head;
- qcount = __Q_Length;
-
- for (;;qcount--) {
- if ((retval = ZParseNotice(qptr->packet,qptr->packet_len,
- &tmpnotice))
- != ZERR_NONE)
- return (retval);
- if ((predicate)(&tmpnotice,args)) {
- if (qptr->packet_len > buffer_len)
- return (ZERR_PKTLEN);
- bcopy(qptr->packet,buffer,qptr->packet_len);
- if (from)
- *from = qptr->from;
- if ((retval = ZParseNotice(buffer,qptr->packet_len,
- notice))
- != ZERR_NONE)
- return (retval);
- return (ZERR_NONE);
- }
- /* Grunch! */
- if (qcount == 1) {
- if ((retval = Z_ReadWait()) != ZERR_NONE)
- return (retval);
- qcount++;
- qptr = __Q_Tail;
- }
- else
- qptr = qptr->next;
+ qptr = (struct _Z_InputQ *) Z_GetFirstComplete();
+
+ for (;;) {
+ while (qptr) {
+ if ((retval = ZParseNotice(qptr->packet, qptr->packet_len,
+ &tmpnotice)) != ZERR_NONE)
+ return (retval);
+ if ((predicate)(&tmpnotice, args)) {
+ if (!(buffer = malloc(qptr->packet_len)))
+ return (ENOMEM);
+ bcopy(qptr->packet, buffer, qptr->packet_len);
+ if (from)
+ *from = qptr->from;
+ if ((retval = ZParseNotice(buffer, qptr->packet_len,
+ notice)) != ZERR_NONE) {
+ free(buffer);
+ return (retval);
+ }
+ return (ZERR_NONE);
+ }
+ qptr = Z_GetNextComplete(qptr);
}
+ if ((retval = Z_ReadWait()) != ZERR_NONE)
+ return (retval);
+ }
}