Changeset 69:5ef65a9359b3 in roaraudio
- Timestamp:
- 07/12/08 14:49:32 (16 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroar/socket.h
r2 r69 10 10 #define ROAR_SOCKET_TYPE_INET 1 11 11 #define ROAR_SOCKET_TYPE_UNIX 2 12 #define ROAR_SOCKET_TYPE_FORK 3 13 #define ROAR_SOCKET_TYPE_PIPE ROAR_SOCKET_TYPE_FORK 12 14 13 15 #define ROAR_SOCKET_QUEUE_LEN 8 … … 23 25 int roar_socket_new_tcp (void); 24 26 int roar_socket_new_unix (void); 25 int roar_socket_open (int mode, int type, char * host, int port); 27 int roar_socket_open (int mode, int type, char * host, int port); 28 int roar_socket_open_fork (int mode, char * host, int port); 26 29 int roar_socket_open_proxy (int mode, int type, char * host, int port, char * proxy_type); 27 30 -
libroar/socket.c
r60 r69 75 75 if ( type == ROAR_SOCKET_TYPE_UNKNOWN ) { 76 76 type = ROAR_SOCKET_TYPE_INET; 77 if ( *host == '/' ) 77 if ( *host == '/' ) { 78 78 type = ROAR_SOCKET_TYPE_UNIX; 79 } else if ( strcmp(host, "+fork") == 0 ) { 80 type = ROAR_SOCKET_TYPE_FORK; 81 } 79 82 } 80 83 … … 110 113 } 111 114 // hey! we have a socket... 112 } else {115 } else if ( type == ROAR_SOCKET_TYPE_UNIX ) { 113 116 socket_addr_un.sun_family = AF_UNIX; 114 117 strncpy(socket_addr_un.sun_path, host, sizeof(socket_addr_un.sun_path) - 1); … … 121 124 return -1; 122 125 } 126 } else if ( type == ROAR_SOCKET_TYPE_FORK ) { 127 return roar_socket_open_fork(mode, host, port); 128 } else { 129 return -1; 123 130 } 124 131 … … 130 137 131 138 return fh; 139 } 140 141 int 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; 132 176 } 133 177
Note: See TracChangeset
for help on using the changeset viewer.