Changeset 1304:4c024e764410 in roaraudio
- Timestamp:
- 03/19/09 04:49:43 (15 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroar/vio_pipe.h
r1301 r1304 44 44 #define ROAR_VIO_PIPE_TYPE_SOCKET 3 45 45 46 #define ROAR_VIO_PIPE_S(self,stream) ((self->s0) == (stream) ? 0 : 1) 47 46 48 struct roar_vio_pipe { 47 49 int refcount; … … 52 54 int p[4]; 53 55 } b; 56 struct roar_vio_calls * s0; 54 57 }; 55 58 56 int roar_vio_open_pipe (struct roar_vio_calls * s1, struct roar_vio_calls * s2, int type, int flags); 59 int roar_vio_open_pipe (struct roar_vio_calls * s0, struct roar_vio_calls * s1, int type, int flags); 60 int roar_vio_pipe_init (struct roar_vio_calls * s, struct roar_vio_pipe * self, int flags); 61 62 ssize_t roar_vio_pipe_read (struct roar_vio_calls * vio, void *buf, size_t count); 63 ssize_t roar_vio_pipe_write (struct roar_vio_calls * vio, void *buf, size_t count); 64 int roar_vio_pipe_nonblock(struct roar_vio_calls * vio, int state); 65 int roar_vio_pipe_sync (struct roar_vio_calls * vio); 66 int roar_vio_pipe_close (struct roar_vio_calls * vio); 57 67 58 68 #endif -
libroar/vio_pipe.c
r1301 r1304 35 35 #include "libroar.h" 36 36 37 int roar_vio_open_pipe (struct roar_vio_calls * s 1, struct roar_vio_calls * s2, int type, int flags) {37 int roar_vio_open_pipe (struct roar_vio_calls * s0, struct roar_vio_calls * s1, int type, int flags) { 38 38 struct roar_vio_pipe * self; 39 39 int rw = flags & (O_RDONLY|O_WRONLY|O_RDWR); 40 40 41 if ( s 1 == NULL || s2== NULL )41 if ( s0 == NULL || s1 == NULL ) 42 42 return -1; 43 43 … … 48 48 49 49 self->refcount = 2; 50 self->type = type;51 50 self->flags = flags; 52 51 … … 59 58 } 60 59 60 self->type = type; 61 61 62 switch (type) { 62 63 case ROAR_VIO_PIPE_TYPE_BUFFER: 63 64 // no buffers need to be set up here, 64 65 // we handle the NULL pointer in the reader and writer func 66 free(self); 67 return -1; 65 68 break; 66 69 case ROAR_VIO_PIPE_TYPE_PIPE: … … 97 100 } 98 101 99 return 0; 102 roar_vio_pipe_init(s0, self, flags); 103 roar_vio_pipe_init(s1, self, flags); 104 105 self->s0 = s0; 106 107 return 0; 108 } 109 110 int roar_vio_pipe_init (struct roar_vio_calls * s, struct roar_vio_pipe * self, int flags) { 111 if ( s == NULL || self == NULL ) 112 return -1; 113 114 memset(s, 0, sizeof(struct roar_vio_calls)); 115 116 s->close = roar_vio_pipe_close; 117 s->read = roar_vio_pipe_read; 118 s->write = roar_vio_pipe_write; 119 s->nonblock = roar_vio_pipe_nonblock; 120 s->sync = roar_vio_pipe_sync; 121 122 s->inst = (void*) self; 123 124 if ( flags & O_NONBLOCK ) { 125 roar_vio_pipe_nonblock(s, ROAR_SOCKET_NONBLOCK); 126 } 127 128 return 0; 129 } 130 131 int roar_vio_pipe_close (struct roar_vio_calls * vio) { 132 struct roar_vio_pipe * self; 133 int idx; 134 135 if ( vio == NULL ) 136 return -1; 137 138 if ( (self = (struct roar_vio_pipe *)vio->inst) == NULL ) 139 return -1; 140 141 self->refcount--; 142 143 switch (self->type) { 144 case ROAR_VIO_PIPE_TYPE_BUFFER: 145 // this will be a bit more complex as we need to change the flags, too. 146 break; 147 case ROAR_VIO_PIPE_TYPE_PIPE: 148 switch (ROAR_VIO_PIPE_S(self, vio)) { 149 case 0: 150 close(self->b.p[0]); 151 close(self->b.p[1]); 152 self->b.p[0] = -1; 153 self->b.p[1] = -1; 154 break; 155 case 1: 156 close(self->b.p[2]); 157 close(self->b.p[3]); 158 self->b.p[2] = -1; 159 self->b.p[3] = -1; 160 break; 161 } 162 break; 163 case ROAR_VIO_PIPE_TYPE_SOCKET: 164 close(self->b.p[idx = ROAR_VIO_PIPE_S(self, vio)]); 165 self->b.p[idx] = -1; 166 break; 167 } 168 169 if ( ! self->refcount ) { 170 free(self); 171 } 172 173 vio->inst = NULL; 174 return 0; 175 } 176 177 int roar_vio_pipe_nonblock(struct roar_vio_calls * vio, int state) { 178 return -1; 179 } 180 181 int roar_vio_pipe_sync (struct roar_vio_calls * vio) { 182 // we may add fdatasync() calls here depending on the type 183 // but in general they should not be needed on pipes. 184 return 0; 185 } 186 187 ssize_t roar_vio_pipe_read (struct roar_vio_calls * vio, void *buf, size_t count) { 188 struct roar_vio_pipe * self; 189 190 if ( vio == NULL ) 191 return -1; 192 193 if ( (self = (struct roar_vio_pipe *)vio->inst) == NULL ) 194 return -1; 195 196 switch (self->type) { 197 case ROAR_VIO_PIPE_TYPE_BUFFER: 198 // this will be a bit more complex as we need to check the flags, too. 199 break; 200 case ROAR_VIO_PIPE_TYPE_PIPE: 201 return read(self->b.p[ROAR_VIO_PIPE_S(self,vio)*2], buf, count); 202 break; 203 case ROAR_VIO_PIPE_TYPE_SOCKET: 204 return read(self->b.p[ROAR_VIO_PIPE_S(self,vio)], buf, count); 205 break; 206 } 207 208 return -1; 209 } 210 211 ssize_t roar_vio_pipe_write (struct roar_vio_calls * vio, void *buf, size_t count) { 212 struct roar_vio_pipe * self; 213 214 if ( vio == NULL ) 215 return -1; 216 217 if ( (self = (struct roar_vio_pipe *)vio->inst) == NULL ) 218 return -1; 219 220 switch (self->type) { 221 case ROAR_VIO_PIPE_TYPE_BUFFER: 222 // this will be a bit more complex as we need to check the flags, too. 223 break; 224 case ROAR_VIO_PIPE_TYPE_PIPE: 225 return write(self->b.p[(ROAR_VIO_PIPE_S(self,vio)*2)+1], buf, count); 226 break; 227 case ROAR_VIO_PIPE_TYPE_SOCKET: 228 return write(self->b.p[ROAR_VIO_PIPE_S(self,vio)], buf, count); 229 break; 230 } 231 232 return -1; 100 233 } 101 234 -
roarclients/Makefile
r1279 r1304 1 TARGETS=roarcat roarcatad roarcat2sock roarcatsendfile roarcatplay roarcatpassfh roarbidir roarctl roarmon roarsockconnect roartypes roarvorbis roarvumeter roarfilt roarsin roar-config polytest roarsocktypes roarshout roarradio roarfctest roarmonhttp pinentrytest zcattest pgptest roarcatvio 1 TARGETS=roarcat roarcatad roarcat2sock roarcatsendfile roarcatplay roarcatpassfh roarbidir roarctl roarmon roarsockconnect roartypes roarvorbis roarvumeter roarfilt roarsin roar-config polytest roarsocktypes roarshout roarradio roarfctest roarmonhttp pinentrytest zcattest pgptest roarcatvio pipetest 2 2 3 3 include ../Makefile.conf … … 44 44 zcattest: zcattest.o 45 45 pgptest: pgptest.o 46 pipetest: pipetest.o 46 47 roarfctest: roarfctest.o 47 48 ${CC} ${LDFLAGS} -o roarfctest roarfctest.o $(lib_m) -lroardsp
Note: See TracChangeset
for help on using the changeset viewer.