Changeset 487:a25cdf58b8fe in roaraudio


Ignore:
Timestamp:
08/13/08 17:59:27 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added Af_INET support to roar_simple_new_stream_obj()

Location:
libroar
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libroar/simple.c

    r451 r487  
    6969 static int count = 0; 
    7070 struct group   * grp  = NULL; 
     71 int    type = ROAR_SOCKET_TYPE_UNIX; 
     72 int    port = 0; 
     73 struct sockaddr_in   socket_addr; 
     74 socklen_t            len            = sizeof(struct sockaddr_in); 
    7175 
    72  sprintf(file, "/tmp/.libroar-simple-stream.%i-%i", getpid(), count++); 
    73  
    74  if ( (listen = roar_socket_listen(ROAR_SOCKET_TYPE_UNIX, file, 0)) == -1 ) { 
     76 if ( getsockname(con->fh, (struct sockaddr *)&socket_addr, &len) == -1 ) { 
    7577  return -1; 
    7678 } 
    7779 
    78  chmod(file, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP); 
     80 if ( socket_addr.sin_family == AF_INET ) { 
     81  type = ROAR_SOCKET_TYPE_INET; 
     82 } 
    7983 
    80  grp = getgrnam(ROAR_DEFAULT_SOCKGRP); 
     84 if ( type == ROAR_SOCKET_TYPE_UNIX ) { 
     85  sprintf(file, "/tmp/.libroar-simple-stream.%i-%i", getpid(), count++); 
     86 } else { 
     87  strcpy(file, inet_ntoa(socket_addr.sin_addr)); 
     88 } 
    8189 
    82  if ( grp ) 
    83   chown(file, -1, grp->gr_gid); 
     90 if ( (listen = roar_socket_listen(type, file, port)) == -1 ) { 
     91  return -1; 
     92 } 
     93 
     94 if ( type == ROAR_SOCKET_TYPE_INET ) { 
     95  len = sizeof(struct sockaddr_in); 
     96  if ( getsockname(listen, (struct sockaddr *)&socket_addr, &len) == -1 ) { 
     97   return -1; 
     98  } 
     99  port = ROAR_NET2HOST16(socket_addr.sin_port); 
     100  ROAR_DBG("roar_simple_new_stream_obj(*): port=%i", port); 
     101 } 
     102 
     103 if ( type == ROAR_SOCKET_TYPE_UNIX ) { 
     104  chmod(file, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP); 
     105 
     106  grp = getgrnam(ROAR_DEFAULT_SOCKGRP); 
     107 
     108  if ( grp ) 
     109   chown(file, -1, grp->gr_gid); 
     110 } 
    84111 
    85112 if ( roar_stream_new(s, rate, channels, bits, codec) == -1 ) { 
     
    91118 } 
    92119 
    93  if ( roar_stream_connect_to_ask(con, s, ROAR_SOCKET_TYPE_UNIX, file, 0) != -1 ) { 
     120 if ( roar_stream_connect_to_ask(con, s, type, file, port) != -1 ) { 
    94121 
    95122  if ( (fh = accept(listen, NULL, NULL)) != -1 ) { 
     
    110137 
    111138 close(listen); 
    112  unlink(file); 
     139 
     140 if ( type == ROAR_SOCKET_TYPE_UNIX ) { 
     141  unlink(file); 
     142 } 
    113143 
    114144 return fh; 
  • libroar/stream.c

    r465 r487  
    9393 if ( host == NULL ) 
    9494  return -1; 
     95 
     96 ROAR_DBG("roar_stream_connect_to_ask(*): Ask the server to connect to: %s:%i", host, port); 
    9597 
    9698 m.cmd     = ROAR_CMD_CON_STREAM; 
Note: See TracChangeset for help on using the changeset viewer.