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

1.1     ! root        1: /* dg2ps.c - datagram-backed abstraction for PStreams */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/psap/RCS/dg2ps.c,v 7.0 89/11/23 22:12:34 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/psap/RCS/dg2ps.c,v 7.0 89/11/23 22:12:34 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       dg2ps.c,v $
        !            12:  * Revision 7.0  89/11/23  22:12:34  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: 
        !            34: struct ps_dg {
        !            35:     int            ps_fd;
        !            36:     int            ps_maxsize;
        !            37: 
        !            38:     struct ps_inout {
        !            39:        struct qbuf *pio_qb;
        !            40:        char   *pio_ptr;
        !            41:        int     pio_cnt;
        !            42: 
        !            43:        IFP     pio_fnx;
        !            44:     }      ps_input,
        !            45:            ps_output;
        !            46: };
        !            47: 
        !            48: /*  */
        !            49: 
        !            50: static int  dg_prime (ps, waiting)
        !            51: register PS    ps;
        !            52: int    waiting;
        !            53: {
        !            54:     struct qbuf *qb;
        !            55:     register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr;
        !            56:     register struct ps_inout *pi = &pt -> ps_input;
        !            57: 
        !            58:     if (waiting)
        !            59:        return (pi -> pio_qb ? DONE : OK);
        !            60: 
        !            61:     if (pi -> pio_qb != NULL) {
        !            62:        qb_free (pi -> pio_qb);
        !            63:        pi -> pio_qb = NULL;
        !            64:     }
        !            65: 
        !            66:     if ((*pi -> pio_fnx) (pt -> ps_fd, &qb) == NOTOK)
        !            67:        return ps_seterr (ps, PS_ERR_IO, NOTOK);
        !            68: 
        !            69:     if (pi -> pio_qb = qb)
        !            70:        pi -> pio_ptr = qb -> qb_data, pi -> pio_cnt = qb -> qb_len;
        !            71:     else
        !            72:        pi -> pio_ptr = NULL, pi -> pio_cnt = 0;
        !            73: 
        !            74:     return OK;
        !            75: }
        !            76: 
        !            77: 
        !            78: /* ARGSUSED */
        !            79:     
        !            80: static int  dg_read (ps, data, n, in_line)
        !            81: register PS    ps;
        !            82: PElementData data;
        !            83: PElementLen n;
        !            84: int    in_line;
        !            85: {
        !            86:     int            cc;
        !            87:     register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr;
        !            88:     register struct ps_inout *pi = &pt -> ps_input;
        !            89: 
        !            90:     if ((cc = pi -> pio_cnt) <= 0)
        !            91:        return 0;
        !            92:     if (cc > n)
        !            93:        cc = n;
        !            94: 
        !            95:     bcopy (pi -> pio_ptr, (char *) data, cc);
        !            96:     pi -> pio_ptr += cc, pi -> pio_cnt -= cc;
        !            97: 
        !            98:     return cc;
        !            99: }
        !           100: 
        !           101: 
        !           102: /* ARGSUSED */
        !           103: 
        !           104: static int  dg_write (ps, data, n, in_line)
        !           105: register PS    ps;
        !           106: PElementData data;
        !           107: PElementLen n;
        !           108: int    in_line;
        !           109: {
        !           110:     register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr;
        !           111:     register struct ps_inout *po = &pt -> ps_output;
        !           112: 
        !           113:     if (po -> pio_cnt < n)
        !           114:        return 0;
        !           115: 
        !           116:     bcopy ((char *) data, po -> pio_ptr, n);
        !           117:     po -> pio_ptr += n, po -> pio_cnt -= n;
        !           118: 
        !           119:     return n;
        !           120: }
        !           121: 
        !           122: 
        !           123: static int  dg_flush (ps)
        !           124: register PS    ps;
        !           125: {
        !           126:     register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr;
        !           127:     register struct ps_inout *po = &pt -> ps_output;
        !           128:     register struct qbuf *qb = po -> pio_qb;
        !           129: 
        !           130:     qb -> qb_len = po -> pio_ptr - qb -> qb_data;
        !           131:     if ((*po -> pio_fnx) (pt -> ps_fd, qb) != qb -> qb_len)
        !           132:        return ps_seterr (ps, PS_ERR_IO, NOTOK);
        !           133: 
        !           134:     po -> pio_ptr = qb -> qb_data, po -> pio_cnt = pt -> ps_maxsize;
        !           135: 
        !           136:     return OK;
        !           137: }
        !           138: 
        !           139: 
        !           140: static int  dg_close (ps)
        !           141: register PS    ps;
        !           142: {
        !           143:     register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr;
        !           144: 
        !           145:     if (pt == NULL)
        !           146:        return OK;
        !           147: 
        !           148:     if (pt -> ps_input.pio_qb)
        !           149:        qb_free (pt -> ps_input.pio_qb);
        !           150:     if (pt -> ps_output.pio_qb)
        !           151:        qb_free (pt -> ps_output.pio_qb);
        !           152: 
        !           153:     free ((char *) pt);
        !           154: 
        !           155:     return OK;
        !           156: }
        !           157: 
        !           158: /*  */
        !           159: 
        !           160: int    dg_open (ps)
        !           161: register PS    ps;
        !           162: {
        !           163:     ps -> ps_primeP = dg_prime;
        !           164:     ps -> ps_readP = dg_read;
        !           165:     ps -> ps_writeP = dg_write;
        !           166:     ps -> ps_flushP = dg_flush;
        !           167:     ps -> ps_closeP = dg_close;
        !           168: 
        !           169:     return OK;
        !           170: }
        !           171: 
        !           172: 
        !           173: int    dg_setup (ps, fd, size, rfx, wfx)
        !           174: register PS    ps;
        !           175: int    fd,
        !           176:        size;
        !           177: IFP    rfx,
        !           178:        wfx;
        !           179: {
        !           180:     register struct ps_dg *pt;
        !           181:     register struct ps_inout *po;
        !           182:     register struct qbuf *qb;
        !           183: 
        !           184:     if ((pt = (struct ps_dg *) calloc (1, sizeof *pt)) == NULL)
        !           185:        return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
        !           186:     ps -> ps_addr = (caddr_t) pt;
        !           187: 
        !           188:     pt -> ps_fd = fd;
        !           189:     pt -> ps_maxsize = size;
        !           190: 
        !           191:     if ((qb = (struct qbuf *) malloc (sizeof *qb
        !           192:                                          + (unsigned) pt -> ps_maxsize))
        !           193:            == NULL)
        !           194:        return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
        !           195:     qb -> qb_forw = qb -> qb_back = qb;
        !           196:     qb -> qb_len = 0;
        !           197:     qb -> qb_data = qb -> qb_base;
        !           198: 
        !           199:     po = &pt -> ps_output;
        !           200:     po -> pio_qb = qb;
        !           201:     po -> pio_ptr = qb -> qb_data, po -> pio_cnt = pt -> ps_maxsize;
        !           202:     if ((pt -> ps_input.pio_fnx = rfx) == NULLIFP
        !           203:            || (po -> pio_fnx = wfx) == NULLIFP)
        !           204:        return ps_seterr (ps, PS_ERR_XXX, NOTOK);
        !           205: 
        !           206:     return OK;
        !           207: }

unix.superglobalmegacorp.com

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