1da2e3ebdSchin /***********************************************************************
2da2e3ebdSchin * *
3da2e3ebdSchin * This software is part of the ast package *
4*3e14f97fSRoger A. Faulkner * Copyright (c) 1985-2010 AT&T Intellectual Property *
5da2e3ebdSchin * and is licensed under the *
6da2e3ebdSchin * Common Public License, Version 1.0 *
77c2fbfb3SApril Chin * by AT&T Intellectual Property *
8da2e3ebdSchin * *
9da2e3ebdSchin * A copy of the License is available at *
10da2e3ebdSchin * http://www.opensource.org/licenses/cpl1.0.txt *
11da2e3ebdSchin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12da2e3ebdSchin * *
13da2e3ebdSchin * Information and Software Systems Research *
14da2e3ebdSchin * AT&T Research *
15da2e3ebdSchin * Florham Park NJ *
16da2e3ebdSchin * *
17da2e3ebdSchin * Glenn Fowler <gsf@research.att.com> *
18da2e3ebdSchin * David Korn <dgk@research.att.com> *
19da2e3ebdSchin * Phong Vo <kpv@research.att.com> *
20da2e3ebdSchin * *
21da2e3ebdSchin ***********************************************************************/
22da2e3ebdSchin #include "sfhdr.h"
23da2e3ebdSchin
24da2e3ebdSchin /* Invoke event handlers for a stream
25da2e3ebdSchin **
26da2e3ebdSchin ** Written by Kiem-Phong Vo.
27da2e3ebdSchin */
28da2e3ebdSchin
29da2e3ebdSchin #if __STD_C
_sfraiseall(int type,Void_t * data)30da2e3ebdSchin static int _sfraiseall(int type, Void_t* data)
31da2e3ebdSchin #else
32da2e3ebdSchin static int _sfraiseall(type, data)
33da2e3ebdSchin int type; /* type of event */
34da2e3ebdSchin Void_t* data; /* associated data */
35da2e3ebdSchin #endif
36da2e3ebdSchin {
37da2e3ebdSchin Sfio_t *f;
38da2e3ebdSchin Sfpool_t *p, *next;
39da2e3ebdSchin int n, rv;
40da2e3ebdSchin
41da2e3ebdSchin rv = 0;
42da2e3ebdSchin for(p = &_Sfpool; p; p = next)
43da2e3ebdSchin {
44da2e3ebdSchin for(next = p->next; next; next = next->next)
45da2e3ebdSchin if(next->n_sf > 0)
46da2e3ebdSchin break;
47da2e3ebdSchin for(n = 0; n < p->n_sf; ++n)
48da2e3ebdSchin { f = p->sf[n];
49da2e3ebdSchin if(sfraise(f, type, data) < 0)
50da2e3ebdSchin rv -= 1;
51da2e3ebdSchin }
52da2e3ebdSchin }
53da2e3ebdSchin return rv;
54da2e3ebdSchin }
55da2e3ebdSchin
56da2e3ebdSchin #if __STD_C
sfraise(Sfio_t * f,int type,Void_t * data)57da2e3ebdSchin int sfraise(Sfio_t* f, int type, Void_t* data)
58da2e3ebdSchin #else
59da2e3ebdSchin int sfraise(f, type, data)
60da2e3ebdSchin Sfio_t* f; /* stream */
61da2e3ebdSchin int type; /* type of event */
62da2e3ebdSchin Void_t* data; /* associated data */
63da2e3ebdSchin #endif
64da2e3ebdSchin {
65da2e3ebdSchin reg Sfdisc_t *disc, *next, *d;
66da2e3ebdSchin reg int local, rv;
677c2fbfb3SApril Chin SFMTXDECL(f);
68da2e3ebdSchin
69da2e3ebdSchin if(!f)
70da2e3ebdSchin return _sfraiseall(type,data);
71da2e3ebdSchin
727c2fbfb3SApril Chin SFMTXENTER(f, -1);
73da2e3ebdSchin
74da2e3ebdSchin GETLOCAL(f,local);
75da2e3ebdSchin if(!SFKILLED(f) &&
76da2e3ebdSchin !(local &&
77da2e3ebdSchin (type == SF_NEW || type == SF_CLOSING ||
78da2e3ebdSchin type == SF_FINAL || type == SF_ATEXIT)) &&
79da2e3ebdSchin SFMODE(f,local) != (f->mode&SF_RDWR) && _sfmode(f,0,local) < 0)
80da2e3ebdSchin SFMTXRETURN(f, -1);
81da2e3ebdSchin SFLOCK(f,local);
82da2e3ebdSchin
83da2e3ebdSchin for(disc = f->disc; disc; )
84da2e3ebdSchin { next = disc->disc;
85da2e3ebdSchin if(type == SF_FINAL)
86da2e3ebdSchin f->disc = next;
87da2e3ebdSchin
88da2e3ebdSchin if(disc->exceptf)
89da2e3ebdSchin { SFOPEN(f,0);
90da2e3ebdSchin if((rv = (*disc->exceptf)(f,type,data,disc)) != 0 )
91da2e3ebdSchin SFMTXRETURN(f, rv);
92da2e3ebdSchin SFLOCK(f,0);
93da2e3ebdSchin }
94da2e3ebdSchin
95da2e3ebdSchin if((disc = next) )
96da2e3ebdSchin { /* make sure that "next" hasn't been popped */
97da2e3ebdSchin for(d = f->disc; d; d = d->disc)
98da2e3ebdSchin if(d == disc)
99da2e3ebdSchin break;
100da2e3ebdSchin if(!d)
101da2e3ebdSchin disc = f->disc;
102da2e3ebdSchin }
103da2e3ebdSchin }
104da2e3ebdSchin
105da2e3ebdSchin SFOPEN(f,local);
106da2e3ebdSchin SFMTXRETURN(f, 0);
107da2e3ebdSchin }
108