Changeset 1168:70be5878eba5 in roaraudio for libroar/simple.c


Ignore:
Timestamp:
01/24/09 18:45:32 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

use socketpair() for AF_UNIX sockets on roar_simple_new_stream*(), not temp sockets on the FS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/simple.c

    r1166 r1168  
    120120int roar_simple_new_stream_obj (struct roar_connection * con, struct roar_stream * s, int rate, int channels, int bits, int codec, int dir) { 
    121121 struct roar_message    mes; 
    122  char file[80]; 
    123  int fh = -1, listen; 
     122 char file[80] = {0}; 
     123 int fh = -1, listen = -1; 
    124124 static int count = 0; 
    125125 struct group   * grp  = NULL; 
     
    131131 fd_set fds; 
    132132 struct timeval timeout = {10, 0}; 
     133 int socks[2]; // for socketpair() 
    133134 
    134135 if ( getsockname(con->fh, (struct sockaddr *)&socket_addr, &len) == -1 ) { 
     
    146147 } 
    147148 
     149/* 
    148150 if ( type == ROAR_SOCKET_TYPE_UNIX ) { 
    149151  snprintf(file, 79, "/tmp/.libroar-simple-stream.%i-%i", getpid(), count++); 
    150  } else if ( type == ROAR_SOCKET_TYPE_DECNET ) { 
     152 } else */ if ( type == ROAR_SOCKET_TYPE_DECNET ) { 
    151153  if ( roar_socket_get_local_nodename() ) { 
    152154   snprintf(file, 24,"%s::roar$TMP%04x%02x", roar_socket_get_local_nodename(), getpid(), count++); 
     
    158160 } 
    159161 
    160  if ( (listen = roar_socket_listen(type, file, port)) == -1 ) { 
    161   return -1; 
     162 if ( type != ROAR_SOCKET_TYPE_UNIX ) { 
     163  if ( (listen = roar_socket_listen(type, file, port)) == -1 ) { 
     164   return -1; 
     165  } 
    162166 } 
    163167 
     
    171175  port = ROAR_NET2HOST16(socket_addr.sin_port); 
    172176  ROAR_DBG("roar_simple_new_stream_obj(*): port=%i", port); 
     177/* 
    173178 } else if ( type == ROAR_SOCKET_TYPE_UNIX ) { 
    174179#ifndef ROAR_TARGET_WIN32 
     
    182187  ROAR_ERR("roar_simple_new_stream_obj(*): There is no UNIX Domain Socket support in win32, download a real OS."); 
    183188#endif 
     189*/ 
    184190 } else if ( type == ROAR_SOCKET_TYPE_DECNET ) { 
    185191  len = sizeof(struct sockaddr_in); 
     
    195201 } 
    196202 
    197  if ( roar_stream_connect_to_ask(con, s, type, file, port) != -1 ) { 
    198  
    199   FD_ZERO(&fds); 
    200   FD_SET(listen, &fds); 
    201  
    202   if ( select(listen + 1, &fds, &fds, &fds, &timeout) < 1 ) { 
    203    close(listen); 
    204  
    205    // we don't need to check the content as we know it failed... 
    206    if ( roar_recv_message(con, &mes, NULL) == -1 ) 
    207     return -1; 
    208  
    209    if ( roar_kick(con, ROAR_OT_STREAM, s->id) == -1 ) 
    210     return -1; 
    211  
    212    return roar_simple_new_stream_attachexeced_obj(con, s, rate, channels, bits, codec, dir); 
    213   } 
    214  
    215   if ( (fh = accept(listen, NULL, NULL)) != -1 ) { 
    216    if ( dir == ROAR_DIR_PLAY ) { 
    217     shutdown(fh, SHUT_RD); 
    218    } else if ( dir == ROAR_DIR_MONITOR || dir == ROAR_DIR_RECORD ) { 
    219     shutdown(fh, SHUT_WR); 
     203 if ( type != ROAR_SOCKET_TYPE_UNIX ) { 
     204  if ( roar_stream_connect_to_ask(con, s, type, file, port) != -1 ) { 
     205 
     206   FD_ZERO(&fds); 
     207   FD_SET(listen, &fds); 
     208 
     209   if ( select(listen + 1, &fds, &fds, &fds, &timeout) < 1 ) { 
     210    close(listen); 
     211 
     212    // we don't need to check the content as we know it failed... 
     213    if ( roar_recv_message(con, &mes, NULL) == -1 ) 
     214     return -1; 
     215 
     216    if ( roar_kick(con, ROAR_OT_STREAM, s->id) == -1 ) 
     217     return -1; 
     218 
     219    return roar_simple_new_stream_attachexeced_obj(con, s, rate, channels, bits, codec, dir); 
    220220   } 
    221   } 
     221 
     222   if ( (fh = accept(listen, NULL, NULL)) != -1 ) { 
     223    /* errr, do we need we any error handling here? */ 
     224   } 
    222225   if ( roar_recv_message(con, &mes, NULL) == -1 ) { 
    223226    close(fh); 
     
    227230    fh = -1; 
    228231   } 
    229  } 
    230  
    231  close(listen); 
    232  
     232  } 
     233 
     234  close(listen); 
     235 } else { // this is type == ROAR_SOCKET_TYPE_UNIX 
     236  if ( socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == -1 ) { 
     237   roar_kick(con, ROAR_OT_STREAM, s->id); // we do not need to check for errors 
     238                                          // as we return -1 in both whys 
     239   return -1; 
     240  } 
     241 
     242  if ( roar_stream_passfh(con, s, socks[0]) == -1 ) { 
     243   roar_kick(con, ROAR_OT_STREAM, s->id); // we do not need to check for errors 
     244                                          // as we return -1 in both whys 
     245   return -1; 
     246  } 
     247 
     248  close(socks[0]); 
     249  fh = socks[1]; 
     250 } 
     251 
     252/* 
    233253 if ( type == ROAR_SOCKET_TYPE_UNIX ) { 
    234254  unlink(file); 
    235255 } 
     256*/ 
     257 
     258 if ( dir == ROAR_DIR_PLAY ) { 
     259  shutdown(fh, SHUT_RD); 
     260 } else if ( dir == ROAR_DIR_MONITOR || dir == ROAR_DIR_RECORD ) { 
     261  shutdown(fh, SHUT_WR); 
     262 } 
    236263 
    237264 s->fh = fh; 
Note: See TracChangeset for help on using the changeset viewer.