Changeset 4326:c53e2ed183a2 in roaraudio
- Timestamp:
- 09/08/10 01:30:26 (14 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroar/client.h
r3718 r4326 39 39 #include "libroar.h" 40 40 41 #define ROAR_CLIENT(x) ((struct roar_client*)(x)) 42 41 43 struct roar_client { 42 44 int fh; /* controll connection */ -
roard/clients.c
r4325 r4326 51 51 int i; 52 52 int s; 53 struct roar_client_server * ns; 53 54 struct roar_client * n; 54 55 55 56 for (i = 0; i < ROAR_CLIENTS_MAX; i++) { 56 57 if ( g_clients[i] == NULL ) { 57 n = roar_mm_malloc(sizeof(struct roar_client)); 58 ns = roar_mm_malloc(sizeof(struct roar_client_server)); 59 n = ROAR_CLIENT(ns); 60 61 memset(ns, 0, sizeof(struct roar_client_server)); 62 58 63 if ( n != NULL ) { 59 64 n->pid = -1; … … 79 84 } 80 85 81 g_clients[i] = n ;86 g_clients[i] = ns; 82 87 83 88 counters_inc(clients, 1); … … 134 139 _CHECK_CID(id); 135 140 136 if ( g_clients[id]->execed != -1) {141 if (ROAR_CLIENT(g_clients[id])->execed != -1) { 137 142 // return streams_delete(g_clients[id]->execed); 138 g_clients[id]->execed = -1;143 ROAR_CLIENT(g_clients[id])->execed = -1; 139 144 close_client_fh = 0; 140 145 } 141 146 142 147 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 143 streams_delete( g_clients[id]->streams[i]);144 } 145 146 if ( g_clients[id]->fh != -1 && close_client_fh )147 close( g_clients[id]->fh);148 149 roar_nnode_free(&( g_clients[id]->nnode));148 streams_delete(ROAR_CLIENT(g_clients[id])->streams[i]); 149 } 150 151 if ( ROAR_CLIENT(g_clients[id])->fh != -1 && close_client_fh ) 152 close(ROAR_CLIENT(g_clients[id])->fh); 153 154 roar_nnode_free(&(ROAR_CLIENT(g_clients[id])->nnode)); 150 155 151 156 roar_mm_free(g_clients[id]); … … 163 168 _CHECK_CID(id); 164 169 165 c = g_clients[id];170 c = ROAR_CLIENT(g_clients[id]); 166 171 167 172 if ( c->fh == -1 ) { … … 170 175 } 171 176 172 if (nocheck_exec || g_clients[id]->execed != -1) {177 if (nocheck_exec || c->execed != -1) { 173 178 close(c->fh); 174 179 c->fh = -1; … … 182 187 _CHECK_CID(id); 183 188 184 *client = g_clients[id];189 *client = ROAR_CLIENT(g_clients[id]); 185 190 186 191 if ( *client == NULL ) … … 199 204 _CHECK_CID(id); 200 205 201 if ( (c = g_clients[id]) == NULL )206 if ( (c = ROAR_CLIENT(g_clients[id])) == NULL ) 202 207 return -1; 203 208 … … 226 231 _CHECK_CID(id); 227 232 228 return g_clients[id]->fh;233 return ROAR_CLIENT(g_clients[id])->fh; 229 234 } 230 235 … … 232 237 _CHECK_CID(id); 233 238 234 g_clients[id]->pid = pid;239 ROAR_CLIENT(g_clients[id])->pid = pid; 235 240 236 241 return 0; … … 240 245 _CHECK_CID(id); 241 246 242 g_clients[id]->uid = uid;247 ROAR_CLIENT(g_clients[id])->uid = uid; 243 248 244 249 return 0; … … 248 253 _CHECK_CID(id); 249 254 250 g_clients[id]->gid = gid;255 ROAR_CLIENT(g_clients[id])->gid = gid; 251 256 252 257 return 0; … … 267 272 } 268 273 269 g_clients[id]->proto = proto;270 g_clients[id]->byteorder = byteorder;274 ROAR_CLIENT(g_clients[id])->proto = proto; 275 ROAR_CLIENT(g_clients[id])->byteorder = byteorder; 271 276 272 277 return 0; … … 277 282 int clients_check_all (void) { 278 283 #ifdef ROAR_HAVE_SELECT 284 struct roar_client * c; 279 285 struct timeval tv; 280 286 fd_set r, e; … … 298 304 299 305 for (i = 0; i < ROAR_CLIENTS_MAX; i++) { 300 if ( g_clients[i]== NULL )306 if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) 301 307 continue; 302 308 303 if ( (fh = g_clients[i]->fh) != -1 ) {309 if ( (fh = c->fh) != -1 ) { 304 310 have++; 305 311 … … 316 322 317 323 for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { 318 if ( (fh = streams_get_fh( g_clients[i]->streams[j])) != -1 ) {319 ROAR_DBG("clients_check_all(*): g_clients[i=%i]->streams[j=%i] = %i, fh = %i", i, j, g_clients[i]->streams[j], fh);324 if ( (fh = streams_get_fh(c->streams[j])) != -1 ) { 325 ROAR_DBG("clients_check_all(*): g_clients[i=%i]->streams[j=%i] = %i, fh = %i", i, j, c->streams[j], fh); 320 326 if ( fh > -1 ) { 321 327 FD_SET(fh, &r); … … 324 330 max_fh = fh; 325 331 } else if ( fh == -2 ) { 326 streams_check( g_clients[i]->streams[j]);332 streams_check(c->streams[j]); 327 333 } 328 334 … … 334 340 if ( !have_stream && have_streamless < MAX_STREAMLESS ) { 335 341 streamless[have_streamless ].id = i; 336 if ( (streamless[have_streamless++].fh = g_clients[i]->fh) == -1 )342 if ( (streamless[have_streamless++].fh = c->fh) == -1 ) 337 343 have_streamless--; 338 344 } … … 347 353 348 354 for (i = 0; i < ROAR_CLIENTS_MAX; i++) { 349 if ( g_clients[i]== NULL )355 if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) 350 356 continue; 351 357 352 if ( (fh = g_clients[i]->fh) != -1 ) {358 if ( (fh = c->fh) != -1 ) { 353 359 if ( FD_ISSET(fh, &r) ) { 354 if ( g_clients[i]->execed == -1 ) {360 if ( c->execed == -1 ) { 355 361 clients_check(i); 356 if ( g_clients[i] != NULL && g_clients[i]->execed != -1 ) {362 if ( g_clients[i] != NULL && ROAR_CLIENT(g_clients[i])->execed != -1 ) { 357 363 FD_CLR(fh, &r); 358 364 } … … 370 376 } 371 377 372 if ( g_clients[i]== NULL )378 if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) 373 379 continue; 374 380 … … 379 385 380 386 //ROAR_WARN("clients_check_all(*): client=%i: client exists", i); 381 ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, g_clients[i]->streams[j]);382 383 if ( (fh = streams_get_fh( g_clients[i]->streams[j])) != -1 ) {387 ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, c->streams[j]); 388 389 if ( (fh = streams_get_fh(c->streams[j])) != -1 ) { 384 390 ROAR_DBG("clients_check_all(*): client=%i, stream=%i: fh=%i", i, j, fh); 385 391 if ( fh > -1 && FD_ISSET(fh, &r) ) { 386 streams_check( g_clients[i]->streams[j]);392 streams_check(c->streams[j]); 387 393 } 388 394 } … … 399 405 400 406 for (i = 0; i < have_streamless; i++) { 401 if ( ! g_clients[j = streamless[i].id])407 if ( g_clients[j = streamless[i].id] == NULL ) 402 408 continue; 403 409 404 if ( g_clients[j]->execed != -1 )410 if ( ROAR_CLIENT(g_clients[j])->execed != -1 ) 405 411 continue; 406 412 … … 433 439 434 440 int clients_check (int id) { 441 struct roar_client * c; 435 442 struct roar_message m; 436 443 struct roar_connection con; … … 444 451 _CHECK_CID(id); 445 452 446 if ( g_clients[id]->fh == -1 ) 453 c = ROAR_CLIENT(g_clients[id]); 454 455 if ( c->fh == -1 ) 447 456 return -1; 448 457 449 roar_connect_fh(&con, g_clients[id]->fh);450 451 switch ( g_clients[id]->proto) {458 roar_connect_fh(&con, c->fh); 459 460 switch (c->proto) { 452 461 case ROAR_PROTO_ROARAUDIO: 453 462 r = roar_recv_message(&con, &m, &data); … … 554 563 */ 555 564 556 ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, g_clients[i]->execed);565 ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, ROAR_CLIENT(g_clients[i])->execed); 557 566 558 567 /* … … 563 572 //if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { 564 573 ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> ?", i, j); 565 if ( g_clients[i]->streams[j] != -1 ) {566 ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> %i", i, j, g_clients[i]->streams[j]);567 streams_send_mon( g_clients[i]->streams[j]);574 if ( ROAR_CLIENT(g_clients[i])->streams[j] != -1 ) { 575 ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> %i", i, j, ROAR_CLIENT(g_clients[i])->streams[j]); 576 streams_send_mon(ROAR_CLIENT(g_clients[i])->streams[j]); 568 577 569 578 // the client may be deleted here, check if it still exists: … … 587 596 588 597 int clients_send_filter(struct roar_audio_info * sa, uint32_t pos) { 598 struct roar_client * c; 589 599 int i; 590 600 int fh; 591 601 592 602 for (i = 0; i < ROAR_CLIENTS_MAX; i++) { 593 if ( g_clients[i]== NULL )603 if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) 594 604 continue; 595 605 596 if ( (fh = g_clients[i]->fh) == -1 )606 if ( (fh = c->fh) == -1 ) 597 607 continue; 598 608 599 if ( g_clients[i]->execed == -1 ) {609 if ( c->execed == -1 ) { 600 610 // TODO: add some code to send a message to the client insetd of the raw data. 601 611 } else { 602 612 // streams_check(g_clients[i]->execed); 603 streams_send_filter( g_clients[i]->execed);613 streams_send_filter(c->execed); 604 614 // if ( streams_send_mon(g_clients[i]->execed) == -1 ) 605 615 // clients_delete(i); // delete client in case we could not write … … 611 621 612 622 int client_stream_exec (int client, int stream) { 623 struct roar_client * c; 613 624 int i; 614 625 int fh; … … 623 634 #endif 624 635 636 c = ROAR_CLIENT(g_clients[client]); 637 625 638 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 626 if ( g_clients[client]->streams[i] == stream ) {627 g_clients[client]->execed = stream;639 if ( c->streams[i] == stream ) { 640 c->execed = stream; 628 641 if ( streams_is_ready(stream) == 0 ) { 629 streams_set_fh(stream, g_clients[client]->fh);642 streams_set_fh(stream, c->fh); 630 643 streams_set_socktype(stream, ROAR_SOCKET_TYPE_GENSTR); 631 644 } else { 632 645 ROAR_DBG("client_stream_exec(client=%i, stream=%i): fh=?", client, stream); 633 if ( (fh = g_clients[client]->fh) != -1 ) {646 if ( (fh = c->fh) != -1 ) { 634 647 close(fh); 635 g_clients[client]->fh = -1;648 c->fh = -1; 636 649 } 637 650 } … … 653 666 654 667 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 655 if ( g_clients[client]->streams[i] == stream ) {668 if ( ROAR_CLIENT(g_clients[client])->streams[i] == stream ) { 656 669 ROAR_DBG("client_stream_set_fh(client=%i, stream=%i, fh=%i): stream found, index %i", client, stream, fh, i); 657 670 return streams_set_fh(stream, fh); … … 669 682 670 683 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 671 if ( g_clients[client]->streams[i] == -1 ) {672 g_clients[client]->streams[i] = stream;684 if ( ROAR_CLIENT(g_clients[client])->streams[i] == -1 ) { 685 ROAR_CLIENT(g_clients[client])->streams[i] = stream; 673 686 streams_set_client(stream, client); 674 687 return 0; … … 685 698 686 699 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 687 if ( g_clients[client]->streams[i] == stream ) {688 g_clients[client]->streams[i] = -1;689 690 if ( stream == g_clients[client]->execed ) {700 if ( ROAR_CLIENT(g_clients[client])->streams[i] == stream ) { 701 ROAR_CLIENT(g_clients[client])->streams[i] = -1; 702 703 if ( stream == ROAR_CLIENT(g_clients[client])->execed ) { 691 704 ROAR_DBG("client_stream_delete(client=%i, stream=%i): stream is execed one, deleting client!", client, stream); 692 705 clients_delete(client); -
roard/include/client.h
r3927 r4326 47 47 */ 48 48 49 struct roar_client * g_clients[ROAR_CLIENTS_MAX]; 49 struct roar_client_server { 50 struct roar_client _client; 51 } * g_clients[ROAR_CLIENTS_MAX]; 50 52 51 53
Note: See TracChangeset
for help on using the changeset viewer.