Changeset 1311:553ca76590b9 in roaraudio


Ignore:
Timestamp:
03/19/09 17:51:54 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

fixed a bug with pipe() based pipes, added some code for BUFFER based pipes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/vio_pipe.c

    r1309 r1311  
    6868   break; 
    6969  case ROAR_VIO_PIPE_TYPE_PIPE: 
     70    self->b.p[0] = self->b.p[1] = self->b.p[2] = self->b.p[3] = -1; 
     71 
    7072    if ( rw == O_RDWR || rw == O_RDONLY ) 
    7173     if ( pipe(self->b.p) == -1 ) { 
     
    176178 
    177179int     roar_vio_pipe_nonblock(struct roar_vio_calls * vio, int state) { 
     180 struct roar_vio_pipe * self; 
     181 
     182 if ( vio == NULL ) 
     183  return -1; 
     184 
     185 if ( (self = (struct roar_vio_pipe *)vio->inst) == NULL ) 
     186  return -1; 
     187 
     188 switch (self->type) { 
     189  case ROAR_VIO_PIPE_TYPE_PIPE: 
     190    if ( roar_socket_nonblock(self->b.p[ROAR_VIO_PIPE_S(self,vio)*2], state) == -1 ) 
     191     return -1; 
     192    return roar_socket_nonblock(self->b.p[(ROAR_VIO_PIPE_SR(self,vio)*2)+1], state); 
     193   break; 
     194  case ROAR_VIO_PIPE_TYPE_SOCKET: 
     195    return roar_socket_nonblock(self->b.p[ROAR_VIO_PIPE_S(self,vio)], state); 
     196   break; 
     197 } 
     198 
    178199 return -1; 
    179200} 
     
    187208ssize_t roar_vio_pipe_read    (struct roar_vio_calls * vio, void *buf, size_t count) { 
    188209 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. 
     210 int                    idx; 
     211 
     212 if ( vio == NULL ) 
     213  return -1; 
     214 
     215 if ( (self = (struct roar_vio_pipe *)vio->inst) == NULL ) 
     216  return -1; 
     217 
     218 switch (self->type) { 
     219  case ROAR_VIO_PIPE_TYPE_BUFFER: 
     220    idx = ROAR_VIO_PIPE_S(self,vio); 
     221 
     222    if ( (idx == 0 ? O_WRONLY : O_RDONLY) == (self->flags & (O_RDONLY|O_WRONLY|O_RDWR)) ) { 
     223     raise(SIGPIPE); 
     224     return -1; 
     225    } 
     226 
     227    if ( self->b.b[idx] == NULL ) 
     228     return 0; 
     229 
     230    if ( roar_buffer_shift_out(&(self->b.b[idx]), buf, &count) == -1 ) 
     231     return -1; 
     232 
     233    return count; 
    199234   break; 
    200235  case ROAR_VIO_PIPE_TYPE_PIPE: 
     
    211246ssize_t roar_vio_pipe_write   (struct roar_vio_calls * vio, void *buf, size_t count) { 
    212247 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. 
     248 struct roar_buffer   * next; 
     249 void                 * data; 
     250 int                    idx; 
     251 
     252 if ( vio == NULL ) 
     253  return -1; 
     254 
     255 if ( (self = (struct roar_vio_pipe *)vio->inst) == NULL ) 
     256  return -1; 
     257 
     258 switch (self->type) { 
     259  case ROAR_VIO_PIPE_TYPE_BUFFER: 
     260    idx = ROAR_VIO_PIPE_SR(self,vio); 
     261 
     262    if ( (idx == 0 ? O_WRONLY : O_RDONLY) == (self->flags & (O_RDONLY|O_WRONLY|O_RDWR)) ) { 
     263     raise(SIGPIPE); 
     264     return -1; 
     265    } 
     266 
     267    if ( roar_buffer_new(&next, count) == -1 ) 
     268     return -1; 
     269 
     270    if ( roar_buffer_get_data(next, &data) == -1 ) { 
     271     roar_buffer_free(next); 
     272     return -1; 
     273    } 
     274 
     275    memcpy(data, buf, count); 
     276 
     277    if ( self->b.b[idx] == NULL ) { 
     278     self->b.b[idx] = next; 
     279    } else { 
     280     if ( roar_buffer_add(self->b.b[idx], next) == -1 ) { 
     281      roar_buffer_free(next); 
     282      return -1; 
     283     } 
     284    } 
     285 
     286    return count; 
    223287   break; 
    224288  case ROAR_VIO_PIPE_TYPE_PIPE: 
Note: See TracChangeset for help on using the changeset viewer.