Changeset 1304:4c024e764410 in roaraudio


Ignore:
Timestamp:
03/19/09 04:49:43 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added pipe impl. working for sockets at least and a simple test prog

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/vio_pipe.h

    r1301 r1304  
    4444#define ROAR_VIO_PIPE_TYPE_SOCKET     3 
    4545 
     46#define ROAR_VIO_PIPE_S(self,stream)  ((self->s0) == (stream) ? 0 : 1) 
     47 
    4648struct roar_vio_pipe { 
    4749 int refcount; 
     
    5254  int                  p[4]; 
    5355 } b; 
     56 struct roar_vio_calls * s0; 
    5457}; 
    5558 
    56 int roar_vio_open_pipe (struct roar_vio_calls * s1, struct roar_vio_calls * s2, int type, int flags); 
     59int roar_vio_open_pipe (struct roar_vio_calls * s0, struct roar_vio_calls * s1, int type, int flags); 
     60int roar_vio_pipe_init (struct roar_vio_calls * s,  struct roar_vio_pipe * self, int flags); 
     61 
     62ssize_t roar_vio_pipe_read    (struct roar_vio_calls * vio, void *buf, size_t count); 
     63ssize_t roar_vio_pipe_write   (struct roar_vio_calls * vio, void *buf, size_t count); 
     64int     roar_vio_pipe_nonblock(struct roar_vio_calls * vio, int state); 
     65int     roar_vio_pipe_sync    (struct roar_vio_calls * vio); 
     66int     roar_vio_pipe_close   (struct roar_vio_calls * vio); 
    5767 
    5868#endif 
  • libroar/vio_pipe.c

    r1301 r1304  
    3535#include "libroar.h" 
    3636 
    37 int roar_vio_open_pipe (struct roar_vio_calls * s1, struct roar_vio_calls * s2, int type, int flags) { 
     37int roar_vio_open_pipe (struct roar_vio_calls * s0, struct roar_vio_calls * s1, int type, int flags) { 
    3838 struct roar_vio_pipe * self; 
    3939 int                    rw = flags & (O_RDONLY|O_WRONLY|O_RDWR); 
    4040 
    41  if ( s1 == NULL || s2 == NULL ) 
     41 if ( s0 == NULL || s1 == NULL ) 
    4242  return -1; 
    4343 
     
    4848 
    4949 self->refcount = 2; 
    50  self->type     = type; 
    5150 self->flags    = flags; 
    5251 
     
    5958 } 
    6059 
     60 self->type     = type; 
     61 
    6162 switch (type) { 
    6263  case ROAR_VIO_PIPE_TYPE_BUFFER: 
    6364    // no buffers need to be set up here, 
    6465    // we handle the NULL pointer in the reader and writer func 
     66    free(self); 
     67    return -1; 
    6568   break; 
    6669  case ROAR_VIO_PIPE_TYPE_PIPE: 
     
    97100 } 
    98101 
    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 
     110int 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 
     131int     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 
     177int     roar_vio_pipe_nonblock(struct roar_vio_calls * vio, int state) { 
     178 return -1; 
     179} 
     180 
     181int     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 
     187ssize_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 
     211ssize_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; 
    100233} 
    101234 
  • 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 
     1TARGETS=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 
    22 
    33include ../Makefile.conf 
     
    4444zcattest: zcattest.o 
    4545pgptest: pgptest.o 
     46pipetest: pipetest.o 
    4647roarfctest: roarfctest.o 
    4748        ${CC} ${LDFLAGS} -o roarfctest roarfctest.o $(lib_m) -lroardsp 
Note: See TracChangeset for help on using the changeset viewer.