Changeset 3293:f8b44412b38d in roaraudio


Ignore:
Timestamp:
02/01/10 21:32:50 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

support for listen sockets

Location:
libroar
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libroar/vio_dstr.c

    r3292 r3293  
    204204   break; 
    205205  case ROAR_VIO_DEF_TYPE_SOCKET: 
    206      if ( roar_vio_open_def_socket(calls, def) == -1 ) 
     206     if ( roar_vio_open_def_socket(calls, def, opts) == -1 ) 
    207207      return -1; 
    208208   break; 
  • libroar/vio_socket.c

    r1650 r3293  
    3939#endif 
    4040 
    41 int     roar_vio_open_def_socket          (struct roar_vio_calls * calls, struct roar_vio_defaults * def) { 
     41int     roar_vio_open_def_socket          (struct roar_vio_calls * calls, struct roar_vio_defaults * def, char * opts) { 
    4242#ifdef _CAN_OPERATE 
    4343 int       fh  = -1; 
    4444 socklen_t len =  0; 
     45 int       listening  = 0; 
     46 int       one_client = 0; 
     47 int       client; 
    4548 
    4649 if ( calls == NULL || def == NULL ) 
    4750  return -1; 
     51 
     52 if ( opts != NULL ) { 
     53  if ( strstr(opts, "listen") != NULL ) { 
     54   listening  = 1; 
     55   one_client = 1; 
     56  } 
     57 } 
    4858 
    4959 if ( def->type != ROAR_VIO_DEF_TYPE_SOCKET ) 
     
    132142  return -1; 
    133143 
    134  if ( connect(fh, &(def->d.socket.sa.sa), len) == -1 ) { 
    135   close(fh); 
    136   return -1; 
     144 if ( listening ) { 
     145  if ( bind(fh, &(def->d.socket.sa.sa), len) == -1 ) { 
     146   close(fh); 
     147   return -1; 
     148  } 
     149 
     150  if ( listen(fh, one_client ? 1 : 16) == -1 ) { 
     151   close(fh); 
     152   return -1; 
     153  } 
     154 
     155  if ( one_client ) { 
     156   client = accept(fh, NULL, NULL); 
     157   close(fh); 
     158 
     159   if ( client == -1 ) { 
     160    return -1; 
     161   } 
     162 
     163   fh = client; 
     164  } 
     165 } else { 
     166  if ( connect(fh, &(def->d.socket.sa.sa), len) == -1 ) { 
     167   close(fh); 
     168   return -1; 
     169  } 
    137170 } 
    138171 
Note: See TracChangeset for help on using the changeset viewer.