[0] | 1 | //clients.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
[0] | 25 | #include "roard.h" |
---|
| 26 | |
---|
| 27 | int clients_init (void) { |
---|
| 28 | int i; |
---|
| 29 | |
---|
| 30 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) |
---|
| 31 | g_clients[i] = NULL; |
---|
| 32 | |
---|
| 33 | return 0; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | int clients_free (void) { |
---|
| 37 | int i; |
---|
| 38 | |
---|
| 39 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) |
---|
| 40 | if ( g_clients[i] ) |
---|
| 41 | clients_delete(i); |
---|
| 42 | |
---|
| 43 | return 0; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | int clients_new (void) { |
---|
| 47 | int i; |
---|
| 48 | int s; |
---|
| 49 | struct roar_client * n; |
---|
| 50 | |
---|
| 51 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 52 | if ( g_clients[i] == NULL ) { |
---|
| 53 | n = malloc(sizeof(struct roar_client)); |
---|
| 54 | if ( n != NULL ) { |
---|
| 55 | n->pid = -1; |
---|
[437] | 56 | n->uid = -1; |
---|
| 57 | n->gid = -1; |
---|
[0] | 58 | n->fh = -1; |
---|
| 59 | |
---|
| 60 | *n->name = 0; |
---|
| 61 | *n->host = 0; |
---|
| 62 | |
---|
[2614] | 63 | n->proto = ROAR_PROTO_ROARAUDIO; |
---|
| 64 | n->byteorder = ROAR_BYTEORDER_NETWORK; |
---|
[2517] | 65 | |
---|
[346] | 66 | n->acl = NULL; |
---|
| 67 | |
---|
[0] | 68 | n->execed = -1; |
---|
| 69 | for (s = 0; s < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; s++) |
---|
| 70 | n->streams[s] = -1; |
---|
| 71 | |
---|
| 72 | g_clients[i] = n; |
---|
| 73 | |
---|
| 74 | ROAR_DBG("clients_new(void) = %i", i); |
---|
| 75 | return i; |
---|
| 76 | } else { |
---|
| 77 | ROAR_ERR("clients_new(void): Can not alloc memory for new client: %s", strerror(errno)); |
---|
| 78 | ROAR_ERR("clients_new(void) = -1"); |
---|
| 79 | return -1; |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | return -1; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | int clients_delete (int id) { |
---|
| 88 | int i; |
---|
[1164] | 89 | int close_client_fh = 1; |
---|
[0] | 90 | |
---|
[2608] | 91 | ROAR_DBG("clients_delete(id=%i) = ?", id); |
---|
| 92 | |
---|
[0] | 93 | if ( g_clients[id] == NULL ) |
---|
| 94 | return -1; |
---|
| 95 | |
---|
| 96 | if (g_clients[id]->execed != -1) { |
---|
| 97 | // return streams_delete(g_clients[id]->execed); |
---|
| 98 | g_clients[id]->execed = -1; |
---|
[1164] | 99 | close_client_fh = 0; |
---|
[0] | 100 | } |
---|
| 101 | |
---|
| 102 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 103 | streams_delete(g_clients[id]->streams[i]); |
---|
| 104 | } |
---|
| 105 | |
---|
[1164] | 106 | if ( g_clients[id]->fh != -1 && close_client_fh ) |
---|
[0] | 107 | close(g_clients[id]->fh); |
---|
| 108 | |
---|
| 109 | free(g_clients[id]); |
---|
| 110 | g_clients[id] = NULL; |
---|
| 111 | |
---|
| 112 | ROAR_DBG("clients_delete(id=%i) = 0", id); |
---|
| 113 | return 0; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | int clients_get (int id, struct roar_client ** client) { |
---|
| 117 | *client = g_clients[id]; |
---|
| 118 | |
---|
| 119 | if ( *client == NULL ) |
---|
| 120 | return -1; |
---|
| 121 | |
---|
| 122 | return 0; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | int clients_set_fh (int id, int fh) { |
---|
[501] | 126 | |
---|
[0] | 127 | if ( g_clients[id] == NULL ) |
---|
| 128 | return -1; |
---|
| 129 | |
---|
| 130 | g_clients[id]->fh = fh; |
---|
| 131 | |
---|
| 132 | return 0; |
---|
| 133 | } |
---|
| 134 | |
---|
[755] | 135 | int clients_get_fh (int id) { |
---|
| 136 | if ( g_clients[id] == NULL ) |
---|
| 137 | return -1; |
---|
| 138 | |
---|
| 139 | return g_clients[id]->fh; |
---|
| 140 | } |
---|
| 141 | |
---|
[0] | 142 | int clients_set_pid (int id, int pid) { |
---|
| 143 | if ( g_clients[id] == NULL ) |
---|
| 144 | return -1; |
---|
| 145 | |
---|
| 146 | g_clients[id]->pid = pid; |
---|
| 147 | |
---|
| 148 | return 0; |
---|
| 149 | } |
---|
| 150 | |
---|
[439] | 151 | int clients_set_uid (int id, int uid) { |
---|
| 152 | if ( g_clients[id] == NULL ) |
---|
| 153 | return -1; |
---|
| 154 | |
---|
| 155 | g_clients[id]->uid = uid; |
---|
| 156 | |
---|
| 157 | return 0; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | int clients_set_gid (int id, int gid) { |
---|
| 161 | if ( g_clients[id] == NULL ) |
---|
| 162 | return -1; |
---|
| 163 | |
---|
| 164 | g_clients[id]->gid = gid; |
---|
| 165 | |
---|
| 166 | return 0; |
---|
| 167 | } |
---|
| 168 | |
---|
[2517] | 169 | int clients_set_proto (int id, int proto) { |
---|
[2614] | 170 | int byteorder = ROAR_BYTEORDER_UNKNOWN; |
---|
| 171 | |
---|
[2517] | 172 | if ( g_clients[id] == NULL ) |
---|
| 173 | return -1; |
---|
| 174 | |
---|
[2614] | 175 | switch (proto) { |
---|
| 176 | case ROAR_PROTO_ROARAUDIO: |
---|
| 177 | byteorder = ROAR_BYTEORDER_NETWORK; |
---|
| 178 | break; |
---|
[2619] | 179 | case ROAR_PROTO_ESOUND: |
---|
| 180 | byteorder = ROAR_BYTEORDER_NATIVE; |
---|
| 181 | break; |
---|
[2614] | 182 | } |
---|
| 183 | |
---|
| 184 | g_clients[id]->proto = proto; |
---|
| 185 | g_clients[id]->byteorder = byteorder; |
---|
[2517] | 186 | |
---|
| 187 | return 0; |
---|
| 188 | } |
---|
| 189 | |
---|
[498] | 190 | #define MAX_STREAMLESS 8 |
---|
| 191 | |
---|
[0] | 192 | int clients_check_all (void) { |
---|
[1480] | 193 | #ifdef ROAR_HAVE_SELECT |
---|
[0] | 194 | struct timeval tv; |
---|
| 195 | fd_set r, e; |
---|
[66] | 196 | int i, j; |
---|
[0] | 197 | int ret; |
---|
| 198 | int fh; |
---|
| 199 | int max_fh = -1; |
---|
[71] | 200 | int have = 0; |
---|
[498] | 201 | struct { |
---|
| 202 | int id; |
---|
| 203 | int fh; |
---|
| 204 | } streamless[MAX_STREAMLESS]; |
---|
| 205 | int have_streamless = 0; |
---|
| 206 | int have_stream; |
---|
[0] | 207 | |
---|
| 208 | FD_ZERO(&r); |
---|
| 209 | FD_ZERO(&e); |
---|
| 210 | |
---|
| 211 | tv.tv_sec = 0; |
---|
| 212 | tv.tv_usec = 1; |
---|
| 213 | |
---|
| 214 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 215 | if ( g_clients[i] == NULL ) |
---|
| 216 | continue; |
---|
| 217 | |
---|
[66] | 218 | if ( (fh = g_clients[i]->fh) != -1 ) { |
---|
[71] | 219 | have++; |
---|
| 220 | |
---|
[610] | 221 | ROAR_DBG("clients_check_all(*): fh=%i", fh); |
---|
| 222 | |
---|
[66] | 223 | FD_SET(fh, &r); |
---|
| 224 | FD_SET(fh, &e); |
---|
| 225 | |
---|
| 226 | if ( fh > max_fh ) |
---|
| 227 | max_fh = fh; |
---|
[84] | 228 | } |
---|
[0] | 229 | |
---|
[498] | 230 | have_stream = 0; |
---|
| 231 | |
---|
[84] | 232 | for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
| 233 | if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { |
---|
[2598] | 234 | ROAR_DBG("clients_check_all(*): g_clients[i=%i]->streams[j=%i] = %i, fh = %i", i, j, g_clients[i]->streams[j], fh); |
---|
[1504] | 235 | if ( fh > -1 ) { |
---|
| 236 | FD_SET(fh, &r); |
---|
[0] | 237 | |
---|
[1504] | 238 | if ( fh > max_fh ) |
---|
| 239 | max_fh = fh; |
---|
| 240 | } |
---|
[498] | 241 | |
---|
| 242 | have_stream = 1; |
---|
[66] | 243 | } |
---|
[84] | 244 | //printf("D: client=%i, stream=%i, fh=%i\n", i, j, fh); |
---|
[66] | 245 | } |
---|
| 246 | |
---|
[498] | 247 | if ( !have_stream && have_streamless < MAX_STREAMLESS ) { |
---|
| 248 | streamless[have_streamless ].id = i; |
---|
| 249 | if ( (streamless[have_streamless++].fh = g_clients[i]->fh) == -1 ) |
---|
| 250 | have_streamless--; |
---|
| 251 | } |
---|
[0] | 252 | } |
---|
| 253 | |
---|
[256] | 254 | if ( max_fh == -1 ) |
---|
| 255 | return 0; |
---|
| 256 | |
---|
[0] | 257 | if ( (ret = select(max_fh + 1, &r, NULL, &e, &tv)) < 1 ) { |
---|
[71] | 258 | return ret < 0 ? ret : have; |
---|
[0] | 259 | } |
---|
| 260 | |
---|
| 261 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 262 | if ( g_clients[i] == NULL ) |
---|
| 263 | continue; |
---|
| 264 | |
---|
[66] | 265 | if ( (fh = g_clients[i]->fh) != -1 ) { |
---|
| 266 | if ( FD_ISSET(fh, &r) ) { |
---|
| 267 | if ( g_clients[i]->execed == -1 ) { |
---|
| 268 | clients_check(i); |
---|
[1835] | 269 | if ( g_clients[i] != NULL && g_clients[i]->execed != -1 ) { |
---|
[1834] | 270 | FD_CLR(fh, &r); |
---|
| 271 | } |
---|
[255] | 272 | /* |
---|
[66] | 273 | } else { |
---|
| 274 | streams_check(g_clients[i]->execed); |
---|
[255] | 275 | */ |
---|
[66] | 276 | } |
---|
| 277 | } |
---|
[0] | 278 | |
---|
[84] | 279 | if ( FD_ISSET(fh, &e) ) { |
---|
[66] | 280 | clients_delete(i); |
---|
[84] | 281 | continue; |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | if ( g_clients[i] == NULL ) |
---|
| 286 | continue; |
---|
| 287 | |
---|
| 288 | for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
[1611] | 289 | ROAR_DBG("clients_check_all(*): D: client=%i, stream=%i, g_clients[i=%i] = %p", i, j, i, g_clients[i]); |
---|
[136] | 290 | if ( g_clients[i] == NULL ) // streams_check() bellow can delete our client (why?) |
---|
| 291 | break; |
---|
[1611] | 292 | |
---|
| 293 | //ROAR_WARN("clients_check_all(*): client=%i: client exists", i); |
---|
| 294 | ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, g_clients[i]->streams[j]); |
---|
| 295 | |
---|
[84] | 296 | if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { |
---|
[1611] | 297 | ROAR_DBG("clients_check_all(*): client=%i, stream=%i: fh=%i", i, j, fh); |
---|
[1504] | 298 | if ( fh == -2 ) { |
---|
| 299 | streams_check(g_clients[i]->streams[j]); |
---|
| 300 | } else if ( FD_ISSET(fh, &r) ) { |
---|
[84] | 301 | streams_check(g_clients[i]->streams[j]); |
---|
[66] | 302 | } |
---|
[0] | 303 | } |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | |
---|
[498] | 307 | if ( have_streamless ) { |
---|
| 308 | FD_ZERO(&r); |
---|
| 309 | |
---|
| 310 | tv.tv_sec = 0; |
---|
| 311 | tv.tv_usec = 1; |
---|
| 312 | |
---|
| 313 | max_fh = -1; |
---|
| 314 | |
---|
| 315 | for (i = 0; i < have_streamless; i++) { |
---|
[607] | 316 | if ( ! g_clients[j = streamless[i].id] ) |
---|
| 317 | continue; |
---|
| 318 | |
---|
| 319 | if ( g_clients[j]->execed != -1 ) |
---|
[601] | 320 | continue; |
---|
| 321 | |
---|
[498] | 322 | fh = streamless[i].fh; |
---|
| 323 | |
---|
| 324 | ROAR_DBG("clients_check_all(void): fh=%i", fh); |
---|
| 325 | FD_SET(fh, &r); |
---|
| 326 | |
---|
| 327 | if ( fh > max_fh ) |
---|
| 328 | max_fh = fh; |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | if ( (ret = select(max_fh + 1, &r, NULL, NULL, &tv)) < 0 ) { |
---|
| 332 | return ret; |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | for (i = 0; i < have_streamless; i++) { |
---|
| 336 | if ( FD_ISSET(streamless[i].fh, &r) ) { |
---|
| 337 | clients_check(streamless[i].id); |
---|
| 338 | } |
---|
| 339 | } |
---|
| 340 | } |
---|
| 341 | |
---|
[71] | 342 | ROAR_DBG("clients_check_all(void) = %i // have value", have); |
---|
| 343 | return have; |
---|
[1480] | 344 | #else |
---|
| 345 | return -1; |
---|
| 346 | #endif |
---|
[0] | 347 | } |
---|
| 348 | |
---|
| 349 | int clients_check (int id) { |
---|
| 350 | struct roar_message m; |
---|
| 351 | struct roar_connection con; |
---|
| 352 | char * data = NULL; |
---|
| 353 | int oldcmd; |
---|
| 354 | int r; |
---|
[498] | 355 | int rv = 0; |
---|
[0] | 356 | |
---|
| 357 | if ( g_clients[id] == NULL ) |
---|
| 358 | return -1; |
---|
| 359 | if ( g_clients[id]->fh == -1 ) |
---|
| 360 | return -1; |
---|
| 361 | |
---|
[1662] | 362 | roar_connect_fh(&con, g_clients[id]->fh); |
---|
[0] | 363 | |
---|
[2517] | 364 | switch (g_clients[id]->proto) { |
---|
| 365 | case ROAR_PROTO_ROARAUDIO: |
---|
| 366 | r = roar_recv_message(&con, &m, &data); |
---|
[0] | 367 | |
---|
[2517] | 368 | if ( r == -1 ) { // should we drop the client? |
---|
| 369 | clients_delete(id); |
---|
| 370 | return -1; |
---|
| 371 | } |
---|
[0] | 372 | |
---|
[2517] | 373 | roar_debug_message_print(&m); |
---|
[0] | 374 | |
---|
[2517] | 375 | oldcmd = m.cmd; |
---|
[0] | 376 | |
---|
[2517] | 377 | if ( (r = command_exec(id, &m, data)) == -1 ) { |
---|
| 378 | m.cmd = ROAR_CMD_ERROR; |
---|
| 379 | m.datalen = 0; |
---|
| 380 | ROAR_DBG("clients_check(*): Exec of command faild!"); |
---|
| 381 | } else { |
---|
| 382 | if ( m.cmd == oldcmd ) { |
---|
| 383 | m.cmd = ROAR_CMD_OK; |
---|
| 384 | m.datalen = 0; |
---|
| 385 | } else if ( m.cmd == ROAR_CMD_OK_STOP ) { |
---|
| 386 | m.cmd = ROAR_CMD_OK; |
---|
| 387 | rv = 1; |
---|
| 388 | } |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | roar_send_message(&con, &m, NULL); |
---|
| 392 | break; |
---|
[2546] | 393 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD |
---|
| 394 | #ifdef ROAR_HAVE_ESD |
---|
[2523] | 395 | case ROAR_PROTO_ESOUND: |
---|
| 396 | rv = emul_esd_check_client(id, NULL); |
---|
| 397 | break; |
---|
[2546] | 398 | #endif |
---|
| 399 | #endif |
---|
[2517] | 400 | default: |
---|
| 401 | rv = -1; |
---|
[0] | 402 | } |
---|
| 403 | |
---|
| 404 | if ( data ) |
---|
| 405 | free(data); |
---|
| 406 | |
---|
[2517] | 407 | ROAR_DBG("clients_check(id=%i) = %i", id, rv); |
---|
[498] | 408 | return rv; |
---|
[0] | 409 | } |
---|
| 410 | |
---|
| 411 | int clients_send_mon (struct roar_audio_info * sa, uint32_t pos) { |
---|
| 412 | int i; |
---|
[934] | 413 | // int fh; |
---|
| 414 | int j; |
---|
[2715] | 415 | int keep_going; |
---|
[0] | 416 | |
---|
| 417 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 418 | if ( g_clients[i] == NULL ) |
---|
| 419 | continue; |
---|
| 420 | |
---|
[2715] | 421 | keep_going = 1; |
---|
| 422 | |
---|
[934] | 423 | /* |
---|
[0] | 424 | if ( (fh = g_clients[i]->fh) == -1 ) |
---|
| 425 | continue; |
---|
[934] | 426 | */ |
---|
[0] | 427 | |
---|
[1905] | 428 | ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, g_clients[i]->execed); |
---|
| 429 | |
---|
[2706] | 430 | /* |
---|
[0] | 431 | if ( g_clients[i]->execed == -1 ) { |
---|
| 432 | // TODO: add some code to send a message to the client insetd of the raw data. |
---|
[2706] | 433 | */ |
---|
[2715] | 434 | for (j = 0; keep_going && j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
[934] | 435 | //if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { |
---|
[2715] | 436 | ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> ?", i, j); |
---|
[1905] | 437 | if ( g_clients[i]->streams[j] != -1 ) { |
---|
| 438 | ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> %i", i, j, g_clients[i]->streams[j]); |
---|
[934] | 439 | streams_send_mon(g_clients[i]->streams[j]); |
---|
[2715] | 440 | |
---|
| 441 | // the client may be deleted here, check if it still exists: |
---|
| 442 | if ( g_clients[i] == NULL ) |
---|
| 443 | keep_going = 0; |
---|
[1905] | 444 | } |
---|
[934] | 445 | } |
---|
[2706] | 446 | /* |
---|
[0] | 447 | } else { |
---|
| 448 | // streams_check(g_clients[i]->execed); |
---|
| 449 | streams_send_mon(g_clients[i]->execed); |
---|
| 450 | // if ( streams_send_mon(g_clients[i]->execed) == -1 ) |
---|
| 451 | // clients_delete(i); // delete client in case we could not write |
---|
| 452 | } |
---|
[2706] | 453 | */ |
---|
[0] | 454 | } |
---|
| 455 | |
---|
[1902] | 456 | // TODO: FIXME: should this really be -1? |
---|
[0] | 457 | return -1; |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | int clients_send_filter(struct roar_audio_info * sa, uint32_t pos) { |
---|
| 461 | int i; |
---|
| 462 | int fh; |
---|
| 463 | |
---|
| 464 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 465 | if ( g_clients[i] == NULL ) |
---|
| 466 | continue; |
---|
| 467 | |
---|
| 468 | if ( (fh = g_clients[i]->fh) == -1 ) |
---|
| 469 | continue; |
---|
| 470 | |
---|
| 471 | if ( g_clients[i]->execed == -1 ) { |
---|
| 472 | // TODO: add some code to send a message to the client insetd of the raw data. |
---|
| 473 | } else { |
---|
| 474 | // streams_check(g_clients[i]->execed); |
---|
| 475 | streams_send_filter(g_clients[i]->execed); |
---|
| 476 | // if ( streams_send_mon(g_clients[i]->execed) == -1 ) |
---|
| 477 | // clients_delete(i); // delete client in case we could not write |
---|
| 478 | } |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | return -1; |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | int client_stream_exec (int client, int stream) { |
---|
| 485 | int i; |
---|
| 486 | |
---|
[1901] | 487 | if ( g_clients[client] == NULL ) { |
---|
| 488 | ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not exist", client, stream); |
---|
[0] | 489 | return -1; |
---|
[1901] | 490 | } |
---|
[0] | 491 | |
---|
| 492 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 493 | if ( g_clients[client]->streams[i] == stream ) { |
---|
| 494 | g_clients[client]->execed = stream; |
---|
| 495 | streams_set_fh(stream, g_clients[client]->fh); |
---|
[378] | 496 | streams_set_socktype(stream, ROAR_SOCKET_TYPE_GENSTR); |
---|
[0] | 497 | return 0; |
---|
| 498 | } |
---|
| 499 | } |
---|
| 500 | |
---|
[1901] | 501 | ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not own stream", client, stream); |
---|
[0] | 502 | return -1; |
---|
| 503 | } |
---|
| 504 | |
---|
[78] | 505 | int client_stream_set_fh (int client, int stream, int fh) { |
---|
| 506 | int i; |
---|
| 507 | |
---|
| 508 | if ( g_clients[client] == NULL ) |
---|
| 509 | return -1; |
---|
| 510 | |
---|
| 511 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 512 | if ( g_clients[client]->streams[i] == stream ) { |
---|
| 513 | streams_set_fh(stream, fh); |
---|
| 514 | return 0; |
---|
| 515 | } |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | return -1; |
---|
| 519 | } |
---|
| 520 | |
---|
[0] | 521 | int client_stream_add (int client, int stream) { |
---|
| 522 | int i; |
---|
| 523 | |
---|
| 524 | if ( g_clients[client] == NULL ) |
---|
| 525 | return -1; |
---|
| 526 | |
---|
| 527 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 528 | if ( g_clients[client]->streams[i] == -1 ) { |
---|
| 529 | g_clients[client]->streams[i] = stream; |
---|
| 530 | streams_set_client(stream, client); |
---|
| 531 | return 0; |
---|
| 532 | } |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | return -1; |
---|
| 536 | } |
---|
| 537 | |
---|
| 538 | int client_stream_delete (int client, int stream) { |
---|
| 539 | int i; |
---|
| 540 | |
---|
| 541 | if ( g_clients[client] == NULL ) |
---|
| 542 | return -1; |
---|
| 543 | |
---|
| 544 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 545 | if ( g_clients[client]->streams[i] == stream ) { |
---|
| 546 | g_clients[client]->streams[i] = -1; |
---|
| 547 | |
---|
| 548 | if ( stream == g_clients[client]->execed ) { |
---|
| 549 | ROAR_DBG("client_stream_delete(client=%i, stream=%i): stream is execed one, deleting client!", client, stream); |
---|
| 550 | clients_delete(client); |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | ROAR_DBG("client_stream_delete(client=%i, stream=%i) = 0", client, stream); |
---|
| 554 | return 0; |
---|
| 555 | } |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | ROAR_DBG("client_stream_delete(client=%i, stream=%i) = -1", client, stream); |
---|
| 559 | return -1; |
---|
| 560 | } |
---|
| 561 | |
---|
[767] | 562 | int client_stream_move (int client, int stream) { |
---|
| 563 | int old_client = streams_get_client(stream); |
---|
| 564 | |
---|
[771] | 565 | ROAR_DBG("client_stream_move(client=%i, stream=%i): old_client = %i", client, stream, old_client); |
---|
| 566 | |
---|
[767] | 567 | if ( old_client != -1 ) |
---|
| 568 | if ( client_stream_delete(old_client, stream) == -1 ) |
---|
| 569 | return -1; |
---|
| 570 | |
---|
| 571 | return client_stream_add(client, stream); |
---|
| 572 | } |
---|
| 573 | |
---|
[0] | 574 | //ll |
---|