1: # include   "ctlmod.h"
   2: # include   "pipes.h"
   3: # include   <sccs.h>
   4: 
   5: SCCSID(@(#)pb_read.c	8.1	12/31/84)
   6: 
   7: /*
   8: **  PB_READ -- read a pipe block
   9: **
  10: **	This routine reads a pipe block into *ppb.  It also handles
  11: **	all the low level protocol: RESET blocks, SYNC blocks, META
  12: **	blocks, blocks intended for another process, etc.
  13: **
  14: **	When this routine returns, it returns with a block intended
  15: **	for this process, which must be a REGULAR block, a RESPONSE
  16: **	block, or an ERROR block.
  17: **
  18: **	Parameters:
  19: **		ppb -- a pointer to the area which wants the block.
  20: **
  21: **	Returns:
  22: **		none
  23: **
  24: **	Side Effects:
  25: **		ppb is set to the named block.
  26: **		Virtually any amount of stuff can happen, depending
  27: **			on what is coming through the pipe.
  28: **
  29: **	Trace Flags:
  30: **		12.4 - 12.9
  31: */
  32: 
  33: 
  34: pb_read(ppb)
  35: register pb_t   *ppb;
  36: {
  37:     register int    type;
  38:     register int    from;
  39:     extern int  (*ExitFn)();
  40: 
  41:     /*
  42: 	**  Top Loop.
  43: 	**	Hang waiting for a normal block.  Other blocks are
  44: 	**		handled inside the loop.
  45: 	**	We multiplex 'from' in here temporarily.
  46: 	*/
  47: 
  48:     for (;;)
  49:     {
  50: # ifdef xCTR1
  51:         if (tTf(12, 4))
  52:             lprintf("pb_read: fd=%d:\n", Cm.cm_input);
  53: # endif
  54:         from = pb_rphys(ppb, Cm.cm_input);
  55:         if (from == 0)
  56:         {
  57: # ifdef xCTR1
  58:             if (tTf(12, 4))
  59:                 lprintf("EOF\n");
  60: # endif
  61:             (*ExitFn)(0);
  62:         }
  63:         else if (from != PB_IOSIZE)
  64:             syserr("pb_read: read error (%d)", from);
  65: # ifdef xCTR1
  66:         if (tTf(12, 4))
  67:             pb_dump(ppb, TRUE);
  68: # endif
  69: 
  70:         /* set up buffer pointers, etc. */
  71:         ppb->pb_xptr = ppb->pb_data;
  72:         ppb->pb_nleft = ppb->pb_nused;
  73:         type = ppb->pb_type;
  74:         from = ppb->pb_from;
  75: # ifdef xCM_DEBUG
  76:         if (from > CM_MAXPROC || from < 0)
  77:             syserr("pb_read: from %d", from);
  78: # endif
  79: 
  80:         /* mark this block if possibly from the front */
  81:         if (Cm.cm_input == Cm.cm_proc[0].pr_ninput &&
  82:             bitset(PR_RADJCT, Cm.cm_proc[0].pr_stat))
  83:             setbit(PB_FRFR, ppb->pb_stat);
  84: 
  85:         /* handle RESET blocks before anything else */
  86:         if (type == PB_RESET)
  87:         {
  88:             cm_reset();
  89:             continue;
  90:         }
  91: 
  92:         /* do sync block processing */
  93:         if (type == PB_SYNC)
  94:         {
  95: /*
  96: 			if (Syncs[from] <= 0)
  97: 				lprintf("pb_read: bad SYNC block from %d", from);
  98: 			else
  99: */
 100:                 Syncs[from]--;
 101:             continue;
 102:         }
 103: 
 104:         /* see if we are ignoring from this process */
 105:         if (Syncs[from] > 0)
 106:             continue;
 107: 
 108:         /* check for re-routing */
 109:         if (ppb->pb_proc != Cm.cm_myproc)
 110:         {
 111:             pb_write(ppb);
 112:             if (ppb->pb_proc != PB_WILD)
 113:                 continue;
 114:         }
 115: 
 116:         /*
 117: 		**  Block type dispatching.
 118: 		**	Regular, response, and error blocks return.
 119: 		**	Meta blocks are handled by calling other
 120: 		**		routines.
 121: 		*/
 122: 
 123:         switch (type)
 124:         {
 125:           case PB_REG:
 126:           case PB_RESP:
 127:           case PB_ERR:
 128:             /* handled by readinput() */
 129:             return;
 130: 
 131:           case PB_TRACE:
 132:             pb_trace(ppb);
 133:             break;
 134: 
 135:           /* insert more meta handling before this line */
 136: 
 137:           default:
 138:             syserr("pb_read: type %d", type);
 139:         }
 140:     }
 141: }
 142: /*
 143: **  PB_TRACE -- handle dynamic trace information
 144: **
 145: **	Parameters:
 146: **		ppb -- a pipe block from which to get information.
 147: **
 148: **	Returns:
 149: **		none.
 150: **
 151: **	Side Effects:
 152: **		trace vectors will be changed.
 153: */
 154: 
 155: pb_trace(ppb)
 156: pb_t    *ppb;
 157: {
 158:     register int        i;
 159:     register struct fn_def  *f;
 160: 
 161:     for (i = 0; i < NumFunc; i++)
 162:     {
 163:         f = FuncVect[i];
 164:         if (f->fn_tflag != '\0')
 165:             tTamper(ppb->pb_data, f->fn_tflag, f->fn_tvect, f->fn_tsize);
 166:     }
 167: }

Defined functions

pb_trace defined in line 155; used 1 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1156
Valid CSS Valid XHTML 1.0 Strict