Annotation of libwww/Library/src/HTTee.c, revision 2.7
2.5 frystyk 1: /* HTee.c
2: ** TEE CLASS STREAM DEFINITION
3: **
4: ** (c) COPYRIGHT CERN 1994.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.1 timbl 6: **
7: ** The Tee class just writes to two streams. Easy.
8: ** See also the Black Hole stream which is even easier.
2.3 duns 9: **
10: ** HISTORY:
11: ** 8 Jul 94 FM Insulate free() from _free structure element.
12: **
2.1 timbl 13: */
14:
2.7 ! frystyk 15: /* Library include files */
! 16: #include "tcp.h"
! 17: #include "HTUtils.h"
2.1 timbl 18: #include "HTTee.h"
19:
20: /* Stream Object
21: ** ------------
22: */
23:
24: struct _HTStream {
25: CONST HTStreamClass * isa;
26:
27: HTStream * s1;
28: HTStream * s2;
29: };
30:
31:
32: PRIVATE void HTTee_put_character ARGS2(HTStream *, me, char, c)
33: {
34: (*me->s1->isa->put_character)(me->s1, c);
35: (*me->s2->isa->put_character)(me->s2, c);
36: }
37: PRIVATE void HTTee_put_string ARGS2(HTStream *, me, CONST char*, s)
38: {
39: (*me->s1->isa->put_string)(me->s1, s);
40: (*me->s2->isa->put_string)(me->s2, s);
41: }
42: PRIVATE void HTTee_write ARGS3(HTStream *, me, CONST char*, s, int, l)
43: {
44: (*me->s1->isa->put_block)(me->s1, s, l);
45: (*me->s2->isa->put_block)(me->s2, s, l);
46: }
2.4 frystyk 47: PRIVATE int HTTee_free ARGS1(HTStream *, me)
2.1 timbl 48: {
2.3 duns 49: (*me->s1->isa->_free)(me->s1);
50: (*me->s2->isa->_free)(me->s2);
2.2 luotonen 51: free(me);
2.4 frystyk 52: return 0;
2.1 timbl 53: }
2.4 frystyk 54: PRIVATE int HTTee_abort ARGS2(HTStream *, me, HTError, e)
2.1 timbl 55: {
56: (*me->s1->isa->abort)(me->s1, e);
57: (*me->s2->isa->abort)(me->s2, e);
2.2 luotonen 58: free(me);
2.4 frystyk 59: return EOF;
2.1 timbl 60: }
61:
62:
63: /* Tee stream
64: ** ----------
65: */
66: PRIVATE CONST HTStreamClass HTTeeClass =
67: {
68: "Tee",
69: HTTee_free,
70: HTTee_abort,
71: HTTee_put_character, HTTee_put_string,
72: HTTee_write
73: };
74:
75:
76: /* Tee creation
77: */
78: PUBLIC HTStream * HTTee ARGS2(HTStream *, s1,HTStream *, s2)
79: {
80: HTStream * me = (HTStream*)malloc(sizeof(*me));
81: if (!me) outofmem(__FILE__, "HTTee");
82: me->isa = &HTTeeClass;
83: me->s1 = s1;
84: me->s2 = s2;
85: return me;
86: }
87:
88:
Webmaster