1: # include   "../../ingres.h"
   2: # include   "../../symbol.h"
   3: # include   "../../pipes.h"
   4: # include   "IIglobals.h"
   5: 
   6: /*
   7: **  Buffered Write on Pipe
   8: **
   9: **	The message `msg' of length `n' is buffered and written onto
  10: **	the pipe with UNIX file descriptor `des'.  `Buf' is the addr
  11: **	of the buffer in which buffering is to take place.  If `n' is
  12: **	zero, `msg' is taken to be a null-terminated string of char-
  13: **	acters.  `Mode' gives the operations mode of wrpipe().
  14: **
  15: **	Buffers written with wrpipe() should be read with rdpipe().
  16: **
  17: **	Modes:
  18: **
  19: **	P_PRIME -- Prime the pipe for writing.  This involves clearing
  20: **		out the error field, setting normal status, etc.  In
  21: **		general, it should always be done when you want to
  22: **		start writing.  It need not be done after writing an
  23: **		end-of-pipe (EOP), as this operation automatically
  24: **		resets the pipe.  The "exec_id" field (read by
  25: **		rdpipe(P_EXECID)) is set to `des', and the "func_id"
  26: **		field is set to `n'.
  27: **
  28: **	P_NORM -- Normal mode.  `Msg' is buffered into `buf' and
  29: **		physically written into the pipe as necessary.
  30: **
  31: **	P_END -- Writes an EOP.  Only the first three parameters need
  32: **		be specified.
  33: **
  34: **	P_FLUSH -- Flushes the buffer into the pipe, but does not write
  35: **		an EOP.  In fact, a non-EOP is guaranteed to be
  36: **		written.
  37: **
  38: **	P_WRITE -- Same as P_FLUSH, but the mode is unchanged.  This
  39: **		mode is pretty obscure, and you probably need not use
  40: **		it.
  41: **
  42: **	P_INT -- Writes an interrupt synchronization block into the
  43: **		pipe.  This mode need only be called by resyncpipes()
  44: **		and need not normally concern the user.  It is critical
  45: **		that this mode be called by all processes so that dead-
  46: **		lock or syserrs do not occur.
  47: */
  48: 
  49: IIwrpipe(mode, buf1, des, msg, n)
  50: int     mode;
  51: struct pipfrmt  *buf1;
  52: int     des;
  53: char        *msg;
  54: int     n;
  55: {
  56:     register int        nn;
  57:     register int        msgl;
  58:     register struct pipfrmt *buf;
  59:     int         flushflg;
  60:     int         i;
  61:     char            *proc_name;
  62: 
  63: #	ifdef xATR1
  64:     proc_name = IIproc_name ? IIproc_name : "";
  65: #	endif
  66: 
  67:     buf = buf1;
  68: #	ifdef xATR1
  69:     if (IIdebug > 1)
  70:         printf("\n%s wrpipe md %d buf %u des %d msg %l n %d\n",
  71:             proc_name, mode, buf, des, msg, n);
  72: #	endif
  73:     nn = msgl = 0;
  74:     flushflg = 0;
  75:     switch (mode)
  76:     {
  77:       case P_PRIME:
  78:         buf->buf_len = buf->pbuf_pt = buf->err_id = 0;
  79:         buf->hdrstat = NORM_STAT;
  80:         buf->exec_id = des;
  81:         buf->func_id = n;
  82:         return(0);
  83: 
  84:       case P_NORM:
  85:         msgl = nn = (n == 0) ? IIlength(msg) + 1 : n;
  86:         break;
  87: 
  88:       case P_END:
  89:         buf->hdrstat = LAST_STAT;
  90:         flushflg++;
  91:         break;
  92: 
  93:       case P_FLUSH:
  94:         buf->hdrstat = NORM_STAT;
  95: 
  96:       case P_WRITE:
  97:         flushflg++;
  98:         break;
  99: 
 100:       case P_INT:
 101:         buf->hdrstat = SYNC_STAT;
 102:         flushflg++;
 103:         break;
 104: 
 105:       default:
 106:         IIsyserr("wrpipe: bad mode %d", mode);
 107:     }
 108: 
 109:     while (nn > 0 || flushflg)
 110:     {
 111:         /* BUFFER OUT DATA */
 112:         while (nn > 0 && buf->pbuf_pt < PBUFSIZ)
 113:             buf->pbuf[buf->pbuf_pt++] = msg[msgl - (nn--)];
 114:         /* WRITE PIPE ? */
 115:         if (buf->pbuf_pt >= PBUFSIZ || flushflg)
 116:         {
 117:             buf->buf_len = buf->pbuf_pt;
 118: #			ifdef xATR2
 119:             if (IIdebug > 1)
 120:                 IIprpipe(buf);
 121: #			endif
 122:             if ((i = write(des, buf, HDRSIZ+PBUFSIZ)) < HDRSIZ+PBUFSIZ)
 123:                 IIsyserr("wrpipe: wr err %d %d", i, des);
 124:             buf->pbuf_pt = 0;
 125:             buf->err_id = 0;
 126:             flushflg = 0;
 127:         }
 128:     }
 129: #	ifdef xATR3
 130:     if (IIdebug > 1)
 131:     {
 132:         printf("%s wrpipe ret %d\n", proc_name, msgl);
 133:     }
 134: #	endif
 135:     return (msgl);
 136: }
Last modified: 1980-12-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2124
Valid CSS Valid XHTML 1.0 Strict