Changeset 1168:70be5878eba5 in roaraudio for libroar/simple.c
- Timestamp:
- 01/24/09 18:45:32 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/simple.c
r1166 r1168 120 120 int roar_simple_new_stream_obj (struct roar_connection * con, struct roar_stream * s, int rate, int channels, int bits, int codec, int dir) { 121 121 struct roar_message mes; 122 char file[80] ;123 int fh = -1, listen ;122 char file[80] = {0}; 123 int fh = -1, listen = -1; 124 124 static int count = 0; 125 125 struct group * grp = NULL; … … 131 131 fd_set fds; 132 132 struct timeval timeout = {10, 0}; 133 int socks[2]; // for socketpair() 133 134 134 135 if ( getsockname(con->fh, (struct sockaddr *)&socket_addr, &len) == -1 ) { … … 146 147 } 147 148 149 /* 148 150 if ( type == ROAR_SOCKET_TYPE_UNIX ) { 149 151 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 ) { 151 153 if ( roar_socket_get_local_nodename() ) { 152 154 snprintf(file, 24,"%s::roar$TMP%04x%02x", roar_socket_get_local_nodename(), getpid(), count++); … … 158 160 } 159 161 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 } 162 166 } 163 167 … … 171 175 port = ROAR_NET2HOST16(socket_addr.sin_port); 172 176 ROAR_DBG("roar_simple_new_stream_obj(*): port=%i", port); 177 /* 173 178 } else if ( type == ROAR_SOCKET_TYPE_UNIX ) { 174 179 #ifndef ROAR_TARGET_WIN32 … … 182 187 ROAR_ERR("roar_simple_new_stream_obj(*): There is no UNIX Domain Socket support in win32, download a real OS."); 183 188 #endif 189 */ 184 190 } else if ( type == ROAR_SOCKET_TYPE_DECNET ) { 185 191 len = sizeof(struct sockaddr_in); … … 195 201 } 196 202 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); 220 220 } 221 } 221 222 if ( (fh = accept(listen, NULL, NULL)) != -1 ) { 223 /* errr, do we need we any error handling here? */ 224 } 222 225 if ( roar_recv_message(con, &mes, NULL) == -1 ) { 223 226 close(fh); … … 227 230 fh = -1; 228 231 } 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 /* 233 253 if ( type == ROAR_SOCKET_TYPE_UNIX ) { 234 254 unlink(file); 235 255 } 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 } 236 263 237 264 s->fh = fh;
Note: See TracChangeset
for help on using the changeset viewer.