Annotation of 43BSDReno/contrib/isode-beta/psap/fdx2ps.c, revision 1.1

1.1     ! root        1: /* fdx2ps.c - full-duplex abstraction for PStreams */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/psap/RCS/fdx2ps.c,v 7.0 89/11/23 22:12:35 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/psap/RCS/fdx2ps.c,v 7.0 89/11/23 22:12:35 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       fdx2ps.c,v $
        !            12:  * Revision 7.0  89/11/23  22:12:35  mrose
        !            13:  * Release 6.0
        !            14:  * 
        !            15:  */
        !            16: 
        !            17: /*
        !            18:  *                               NOTICE
        !            19:  *
        !            20:  *    Acquisition, use, and distribution of this module and related
        !            21:  *    materials are subject to the restrictions of a license agreement.
        !            22:  *    Consult the Preface in the User's Manual for the full terms of
        !            23:  *    this agreement.
        !            24:  *
        !            25:  */
        !            26: 
        !            27: 
        !            28: /* LINTLIBRARY */
        !            29: 
        !            30: #include <stdio.h>
        !            31: #include "psap.h"
        !            32: 
        !            33: /*    DATA */
        !            34: 
        !            35: struct ps_fdx {
        !            36:     int            ps_fd;
        !            37: 
        !            38:     struct ps_inout {
        !            39:        char   *pio_base;
        !            40:        int     pio_bufsiz;
        !            41: 
        !            42:        char   *pio_ptr;
        !            43:        int     pio_cnt;
        !            44:     }      ps_input,
        !            45:            ps_output;
        !            46: };
        !            47: 
        !            48: /* */
        !            49: 
        !            50: static int  fdx_prime (ps, waiting)
        !            51: register PS    ps;
        !            52: int    waiting;
        !            53: {
        !            54:     register struct ps_fdx *pt = (struct ps_fdx *) ps -> ps_addr;
        !            55:     register struct ps_inout *pi = &pt -> ps_input;
        !            56: 
        !            57:     return (waiting && pi -> pio_cnt > 0 ? DONE : OK);
        !            58: }
        !            59: 
        !            60: /*  */
        !            61: 
        !            62: /* ARGSUSED */
        !            63:     
        !            64: static int  fdx_read (ps, data, n, in_line)
        !            65: register PS    ps;
        !            66: PElementData data;
        !            67: PElementLen n;
        !            68: int    in_line;
        !            69: {
        !            70:     int            cc;
        !            71:     register struct ps_fdx *pt = (struct ps_fdx *) ps -> ps_addr;
        !            72:     register struct ps_inout *pi = &pt -> ps_input;
        !            73: 
        !            74:     if ((cc = pi -> pio_cnt) <= 0) {
        !            75:        if (n > pi -> pio_bufsiz) {
        !            76:            if ((cc = read (pt -> ps_fd, (char *) data, n)) == NOTOK)
        !            77:                return ps_seterr (ps, PS_ERR_IO, NOTOK);
        !            78: 
        !            79:            return cc;
        !            80:        }
        !            81: 
        !            82:        if ((cc = read (pt -> ps_fd, pi -> pio_base, pi -> pio_bufsiz))
        !            83:                == NOTOK)
        !            84:            return ps_seterr (ps, PS_ERR_IO, NOTOK);
        !            85:        pi -> pio_ptr = pi -> pio_base, pi -> pio_cnt = cc;
        !            86:     }
        !            87: 
        !            88:     if (cc > n)
        !            89:        cc = n;
        !            90: 
        !            91:     bcopy (pi -> pio_ptr, (char *) data, cc);
        !            92:     pi -> pio_ptr += cc, pi -> pio_cnt -= cc;
        !            93: 
        !            94:     return cc;
        !            95: }
        !            96: 
        !            97: 
        !            98: /* ARGSUSED */
        !            99: 
        !           100: static int  fdx_write (ps, data, n, in_line)
        !           101: register PS    ps;
        !           102: PElementData data;
        !           103: PElementLen n;
        !           104: int    in_line;
        !           105: {
        !           106:     int            cc;
        !           107:     register struct ps_fdx *pt = (struct ps_fdx *) ps -> ps_addr;
        !           108:     register struct ps_inout *po = &pt -> ps_output;
        !           109: 
        !           110: #ifdef oldef
        !           111:     if (n > po -> pio_bufsiz) {
        !           112:        if (fdx_flush (ps) == NOTOK
        !           113:                || (cc = write (pt -> ps_fd, (char *) data, n)) != n)
        !           114: #else
        !           115:     if (n > po -> pio_bufsiz && po -> pio_ptr <= po -> pio_base) {
        !           116:        if ((cc = write (pt -> ps_fd, (char *) data, n)) != n)
        !           117: #endif
        !           118:            return ps_seterr (ps, PS_ERR_IO, NOTOK);
        !           119: 
        !           120:        return cc;
        !           121:     }
        !           122: 
        !           123:     if (n > po -> pio_cnt)
        !           124:        n = po -> pio_cnt;
        !           125: 
        !           126:     bcopy ((char *) data, po -> pio_ptr, n);
        !           127:     po -> pio_ptr += n, po -> pio_cnt -= n;
        !           128: 
        !           129:     if (po -> pio_cnt <= 0 && fdx_flush (ps) == NOTOK)
        !           130:        return ps_seterr (ps, PS_ERR_IO, NOTOK);
        !           131: 
        !           132:     return n;
        !           133: }
        !           134: 
        !           135: 
        !           136: static int  fdx_flush (ps)
        !           137: register PS    ps;
        !           138: {
        !           139:     int            cc;
        !           140:     register struct ps_fdx *pt = (struct ps_fdx *) ps -> ps_addr;
        !           141:     register struct ps_inout *po = &pt -> ps_output;
        !           142: 
        !           143:     if ((cc = po -> pio_ptr - po -> pio_base) <= 0)
        !           144:        return OK;
        !           145: 
        !           146:     if (write (pt -> ps_fd, po -> pio_base, cc) != cc)
        !           147:        return ps_seterr (ps, PS_ERR_IO, NOTOK);
        !           148:     po -> pio_ptr = po -> pio_base, po -> pio_cnt = po -> pio_bufsiz;
        !           149: 
        !           150:     return OK;
        !           151: }
        !           152: 
        !           153: 
        !           154: static int  fdx_close (ps)
        !           155: register PS    ps;
        !           156: {
        !           157:     register struct ps_fdx *pt = (struct ps_fdx *) ps -> ps_addr;
        !           158: 
        !           159:     if (pt == NULL)
        !           160:        return OK;
        !           161: 
        !           162:     if (pt -> ps_input.pio_base)
        !           163:        free (pt -> ps_input.pio_base);
        !           164:     if (pt -> ps_output.pio_base)
        !           165:        free (pt -> ps_output.pio_base);
        !           166: 
        !           167:     free ((char *) pt);
        !           168: 
        !           169:     return OK;
        !           170: }
        !           171: 
        !           172: /*  */
        !           173: 
        !           174: int    fdx_open (ps)
        !           175: register PS    ps;
        !           176: {
        !           177:     ps -> ps_primeP = fdx_prime;
        !           178:     ps -> ps_readP = fdx_read;
        !           179:     ps -> ps_writeP = fdx_write;
        !           180:     ps -> ps_flushP = fdx_flush;
        !           181:     ps -> ps_closeP = fdx_close;
        !           182: 
        !           183:     return OK;
        !           184: }
        !           185: 
        !           186: 
        !           187: int    fdx_setup (ps, fd)
        !           188: register PS    ps;
        !           189: int    fd;
        !           190: {
        !           191:     int            pz;
        !           192:     register struct ps_fdx *pt;
        !           193: 
        !           194:     if ((pt = (struct ps_fdx *) calloc (1, sizeof *pt)) == NULL)
        !           195:        return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
        !           196:     ps -> ps_addr = (caddr_t) pt;
        !           197: 
        !           198:     pt -> ps_fd = fd;
        !           199: 
        !           200: #ifdef BSD42
        !           201:     if ((pz = getpagesize ()) <= 0)
        !           202: #endif
        !           203:        pz = BUFSIZ;
        !           204: 
        !           205:     if ((pt -> ps_input.pio_base = malloc ((unsigned) pz)) == NULL
        !           206:            || (pt -> ps_output.pio_base = malloc ((unsigned) pz)) == NULL)
        !           207:        return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
        !           208:     pt -> ps_input.pio_bufsiz = pz, pt -> ps_output.pio_cnt = 0;
        !           209:     pt -> ps_input.pio_ptr = pt -> ps_input.pio_base;
        !           210: 
        !           211:     pt -> ps_output.pio_bufsiz = pt -> ps_output.pio_cnt = pz;
        !           212:     pt -> ps_output.pio_ptr = pt -> ps_output.pio_base;
        !           213: 
        !           214:     return OK;
        !           215: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.