|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T d
Length: 4185 (0x1059) Types: TextFile Names: »dg2ps.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z« └─⟦de7628f85⟧ └─⟦this⟧ »isode-6.0/psap/dg2ps.c«
/* dg2ps.c - datagram-backed abstraction for PStreams */ #ifndef lint static char *rcsid = "$Header: /f/osi/psap/RCS/dg2ps.c,v 7.0 89/11/23 22:12:34 mrose Rel $"; #endif /* * $Header: /f/osi/psap/RCS/dg2ps.c,v 7.0 89/11/23 22:12:34 mrose Rel $ * * * $Log: dg2ps.c,v $ * Revision 7.0 89/11/23 22:12:34 mrose * Release 6.0 * */ /* * NOTICE * * Acquisition, use, and distribution of this module and related * materials are subject to the restrictions of a license agreement. * Consult the Preface in the User's Manual for the full terms of * this agreement. * */ /* LINTLIBRARY */ #include <stdio.h> #include "psap.h" struct ps_dg { int ps_fd; int ps_maxsize; struct ps_inout { struct qbuf *pio_qb; char *pio_ptr; int pio_cnt; IFP pio_fnx; } ps_input, ps_output; }; /* \f */ static int dg_prime (ps, waiting) register PS ps; int waiting; { struct qbuf *qb; register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr; register struct ps_inout *pi = &pt -> ps_input; if (waiting) return (pi -> pio_qb ? DONE : OK); if (pi -> pio_qb != NULL) { qb_free (pi -> pio_qb); pi -> pio_qb = NULL; } if ((*pi -> pio_fnx) (pt -> ps_fd, &qb) == NOTOK) return ps_seterr (ps, PS_ERR_IO, NOTOK); if (pi -> pio_qb = qb) pi -> pio_ptr = qb -> qb_data, pi -> pio_cnt = qb -> qb_len; else pi -> pio_ptr = NULL, pi -> pio_cnt = 0; return OK; } /* ARGSUSED */ static int dg_read (ps, data, n, in_line) register PS ps; PElementData data; PElementLen n; int in_line; { int cc; register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr; register struct ps_inout *pi = &pt -> ps_input; if ((cc = pi -> pio_cnt) <= 0) return 0; if (cc > n) cc = n; bcopy (pi -> pio_ptr, (char *) data, cc); pi -> pio_ptr += cc, pi -> pio_cnt -= cc; return cc; } /* ARGSUSED */ static int dg_write (ps, data, n, in_line) register PS ps; PElementData data; PElementLen n; int in_line; { register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr; register struct ps_inout *po = &pt -> ps_output; if (po -> pio_cnt < n) return 0; bcopy ((char *) data, po -> pio_ptr, n); po -> pio_ptr += n, po -> pio_cnt -= n; return n; } static int dg_flush (ps) register PS ps; { register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr; register struct ps_inout *po = &pt -> ps_output; register struct qbuf *qb = po -> pio_qb; qb -> qb_len = po -> pio_ptr - qb -> qb_data; if ((*po -> pio_fnx) (pt -> ps_fd, qb) != qb -> qb_len) return ps_seterr (ps, PS_ERR_IO, NOTOK); po -> pio_ptr = qb -> qb_data, po -> pio_cnt = pt -> ps_maxsize; return OK; } static int dg_close (ps) register PS ps; { register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr; if (pt == NULL) return OK; if (pt -> ps_input.pio_qb) qb_free (pt -> ps_input.pio_qb); if (pt -> ps_output.pio_qb) qb_free (pt -> ps_output.pio_qb); free ((char *) pt); return OK; } /* \f */ int dg_open (ps) register PS ps; { ps -> ps_primeP = dg_prime; ps -> ps_readP = dg_read; ps -> ps_writeP = dg_write; ps -> ps_flushP = dg_flush; ps -> ps_closeP = dg_close; return OK; } int dg_setup (ps, fd, size, rfx, wfx) register PS ps; int fd, size; IFP rfx, wfx; { register struct ps_dg *pt; register struct ps_inout *po; register struct qbuf *qb; if ((pt = (struct ps_dg *) calloc (1, sizeof *pt)) == NULL) return ps_seterr (ps, PS_ERR_NMEM, NOTOK); ps -> ps_addr = (caddr_t) pt; pt -> ps_fd = fd; pt -> ps_maxsize = size; if ((qb = (struct qbuf *) malloc (sizeof *qb + (unsigned) pt -> ps_maxsize)) == NULL) return ps_seterr (ps, PS_ERR_NMEM, NOTOK); qb -> qb_forw = qb -> qb_back = qb; qb -> qb_len = 0; qb -> qb_data = qb -> qb_base; po = &pt -> ps_output; po -> pio_qb = qb; po -> pio_ptr = qb -> qb_data, po -> pio_cnt = pt -> ps_maxsize; if ((pt -> ps_input.pio_fnx = rfx) == NULLIFP || (po -> pio_fnx = wfx) == NULLIFP) return ps_seterr (ps, PS_ERR_XXX, NOTOK); return OK; }