Changeset 69:5ef65a9359b3 in roaraudio


Ignore:
Timestamp:
07/12/08 14:49:32 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support to fork a roard instance in background

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/socket.h

    r2 r69  
    1010#define ROAR_SOCKET_TYPE_INET 1 
    1111#define ROAR_SOCKET_TYPE_UNIX 2 
     12#define ROAR_SOCKET_TYPE_FORK 3 
     13#define ROAR_SOCKET_TYPE_PIPE ROAR_SOCKET_TYPE_FORK 
    1214 
    1315#define ROAR_SOCKET_QUEUE_LEN 8 
     
    2325int roar_socket_new_tcp (void); 
    2426int roar_socket_new_unix (void); 
    25 int roar_socket_open (int mode, int type, char * host, int port); 
     27int roar_socket_open       (int mode, int type, char * host, int port); 
     28int roar_socket_open_fork  (int mode, char * host, int port); 
    2629int roar_socket_open_proxy (int mode, int type, char * host, int port, char * proxy_type); 
    2730 
  • libroar/socket.c

    r60 r69  
    7575 if ( type == ROAR_SOCKET_TYPE_UNKNOWN ) { 
    7676  type = ROAR_SOCKET_TYPE_INET; 
    77   if ( *host == '/' ) 
     77  if ( *host == '/' ) { 
    7878   type = ROAR_SOCKET_TYPE_UNIX; 
     79  } else if ( strcmp(host, "+fork") == 0 ) { 
     80   type = ROAR_SOCKET_TYPE_FORK; 
     81  } 
    7982 } 
    8083 
     
    110113  } 
    111114  // hey! we have a socket... 
    112  } else { 
     115 } else if ( type == ROAR_SOCKET_TYPE_UNIX ) { 
    113116  socket_addr_un.sun_family = AF_UNIX; 
    114117  strncpy(socket_addr_un.sun_path, host, sizeof(socket_addr_un.sun_path) - 1); 
     
    121124   return -1; 
    122125  } 
     126 } else if ( type == ROAR_SOCKET_TYPE_FORK ) { 
     127  return roar_socket_open_fork(mode, host, port); 
     128 } else { 
     129  return -1; 
    123130 } 
    124131 
     
    130137 
    131138 return fh; 
     139} 
     140 
     141int roar_socket_open_fork  (int mode, char * host, int port) { 
     142 int socks[2]; 
     143 int r; 
     144 char fhstr[8]; 
     145 
     146 if ( mode == MODE_LISTEN ) 
     147  return -1; 
     148 
     149 if ( socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == -1 ) { 
     150  return -1; 
     151 } 
     152 
     153 r = fork(); 
     154 
     155 if ( r == -1 ) { // error! 
     156  ROAR_ERR("roar_socket_open_fork(*): Can not fork: %s", strerror(errno)); 
     157  close(socks[0]); 
     158  close(socks[1]); 
     159  return -1; 
     160 } else if ( r == 0 ) { // we are the child 
     161  close(socks[0]); 
     162 
     163  snprintf(fhstr, 7, "%i", socks[1]); 
     164 
     165  execlp("roard", "roard", "--no-listen", "--client-fh", fhstr, NULL); 
     166 
     167  // we are still alive? 
     168  ROAR_ERR("roar_socket_open_fork(*): alive after exec(), that's bad!"); 
     169  _exit(1); 
     170 } else { // we are the parent 
     171  close(socks[1]); 
     172  return socks[0]; 
     173 } 
     174 
     175 return -1; 
    132176} 
    133177 
Note: See TracChangeset for help on using the changeset viewer.