Commit | Line | Data |
---|---|---|
cf908fd1 WJ |
1 | /* ps_alloc.c - allocate a presentation stream */ |
2 | ||
3 | #ifndef lint | |
4 | static char *rcsid = "$Header: /f/osi/psap/RCS/ps_alloc.c,v 7.1 91/02/22 09:36:31 mrose Interim $"; | |
5 | #endif | |
6 | ||
7 | /* | |
8 | * $Header: /f/osi/psap/RCS/ps_alloc.c,v 7.1 91/02/22 09:36:31 mrose Interim $ | |
9 | * | |
10 | * | |
11 | * $Log: ps_alloc.c,v $ | |
12 | * Revision 7.1 91/02/22 09:36:31 mrose | |
13 | * Interim 6.8 | |
14 | * | |
15 | * Revision 7.0 89/11/23 22:13:19 mrose | |
16 | * Release 6.0 | |
17 | * | |
18 | */ | |
19 | ||
20 | /* | |
21 | * NOTICE | |
22 | * | |
23 | * Acquisition, use, and distribution of this module and related | |
24 | * materials are subject to the restrictions of a license agreement. | |
25 | * Consult the Preface in the User's Manual for the full terms of | |
26 | * this agreement. | |
27 | * | |
28 | */ | |
29 | ||
30 | ||
31 | /* LINTLIBRARY */ | |
32 | ||
33 | #include <stdio.h> | |
34 | #include "psap.h" | |
35 | ||
36 | ||
37 | /* A Presentatation Stream (or PStream) is the second generation of | |
38 | "generic" I/O stream-based handling. (For the first attempt, | |
39 | take a look at the prototype implementation of the TTI Trusted Mail | |
40 | Agent.) The idea is to present a common, simple I/O paradigm (i.e., | |
41 | the UNIX v7 philosophy) to protocol-translation entities regardless of | |
42 | the underlying medium (files, pipes, sockets, or strings). | |
43 | ||
44 | New streams are created by a call to ps_alloc(). It allocates memory | |
45 | and calls an open routine. This routine fills in the dispatch vectors | |
46 | for read/write and (optionally) close. It can also fill in any other | |
47 | part of the stream's structure it likes. | |
48 | ||
49 | Once created, I/O is done using the macros ps_read/ps_write. These | |
50 | return either NOTOK or OK; depending on how things went. The read/write | |
51 | routines are invoked as: | |
52 | ||
53 | int iofunc (ps, data, n, in_line) | |
54 | PS ps; | |
55 | PElementData data; | |
56 | PElementLen n; | |
57 | int in_line; | |
58 | ||
59 | They should read/write upto len bytes, starting at data, and return the | |
60 | number of bytes processed, or NOTOK on error. The routine ps_io() will | |
61 | make successive calls to fill/flush the data. If the read/write routine | |
62 | returns NOTOK, it should set ps_errno as well. | |
63 | ||
64 | Streams are removed by a call to ps_free (). It calls the close | |
65 | routine, if any, which should de-commission any parts of the stream's | |
66 | structure that are in use. ps_free() will then free the allocated | |
67 | memory. | |
68 | */ | |
69 | ||
70 | /* \f */ | |
71 | ||
72 | PS ps_alloc (io) | |
73 | register IFP io; | |
74 | { | |
75 | register PS ps; | |
76 | ||
77 | if ((ps = (PS) calloc (1, sizeof *ps)) == NULLPS) | |
78 | return NULLPS; | |
79 | ||
80 | if ((*io) (ps) == NOTOK) { | |
81 | ps_free (ps); | |
82 | return NULLPS; | |
83 | } | |
84 | ||
85 | return ps; | |
86 | } |