source: roaraudio/roard/clients.c @ 4333:d10f93a61265

Last change on this file since 4333:d10f93a61265 was 4326:c53e2ed183a2, checked in by phi, 14 years ago

use new roar_client_server struct for clients in roard

File size: 16.1 KB
RevLine 
[0]1//clients.c:
2
[668]3/*
[3358]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
[668]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
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[668]23 *
24 */
25
[0]26#include "roard.h"
27
[3910]28#define _CHECK_CID_RET(id,ret) if ( (id) < 0 || (id) > ROAR_CLIENTS_MAX || g_clients[(id)] == NULL ) return (ret)
29#define _CHECK_CID(id)         _CHECK_CID_RET((id), -1)
30
[0]31int clients_init (void) {
32 int i;
33
34 for (i = 0; i < ROAR_CLIENTS_MAX; i++)
35  g_clients[i] = NULL;
36
37 return 0;
38}
39
40int clients_free (void) {
41 int i;
42
43 for (i = 0; i < ROAR_CLIENTS_MAX; i++)
[3910]44  if ( g_clients[i] != NULL )
[0]45   clients_delete(i);
46
47 return 0;
48}
49
50int clients_new (void) {
51 int i;
52 int s;
[4326]53 struct roar_client_server * ns;
[0]54 struct roar_client * n;
55
56 for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
57  if ( g_clients[i] == NULL ) {
[4326]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
[0]63   if ( n != NULL ) {
64    n->pid    = -1;
[437]65    n->uid    = -1;
66    n->gid    = -1;
[0]67    n->fh     = -1;
68
69    *n->name = 0;
70    *n->host = 0;
71
[2614]72    n->proto     = ROAR_PROTO_ROARAUDIO;
73    n->byteorder = ROAR_BYTEORDER_NETWORK;
[2517]74
[346]75    n->acl   = NULL;
76
[0]77    n->execed = -1;
78    for (s = 0; s < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; s++)
79     n->streams[s] = -1;
80
[2815]81    if ( roar_nnode_new(&(n->nnode), ROAR_SOCKET_TYPE_UNKNOWN) == -1 ) {
[3063]82     roar_mm_free(n);
[2815]83     return -1;
84    }
85
[4326]86    g_clients[i] = ns;
[0]87
[4101]88    counters_inc(clients, 1);
[0]89    ROAR_DBG("clients_new(void) = %i", i);
90    return i;
91   } else {
92    ROAR_ERR("clients_new(void): Can not alloc memory for new client: %s", strerror(errno));
93    ROAR_ERR("clients_new(void) = -1");
94    return -1;
95   }
96  }
97 }
98
99 return -1;
100}
101
[3737]102int clients_new_from_fh(int fh, int proto, int byteorder, int update_nnode) {
103 struct roar_client * c;
104 int client;
105
106 if ( fh == -1 )
107  return -1;
108
109 if ( proto != ROAR_PROTO_ROARAUDIO || byteorder != ROAR_BYTEORDER_NETWORK )
110  return -1;
111
112 if ( (client = clients_new()) == -1 )
113  return -1;
114
115 if ( clients_set_fh(client, fh) == -1 ) {
116  clients_delete(client);
117  return -1;
118 }
119
120 if ( update_nnode ) {
121  if ( clients_get(client, &c) != -1 ) {
122   if ( roar_nnode_free(&(c->nnode)) != -1 ) {
123    roar_nnode_new_from_fh(&(c->nnode), fh, 1);
124   }
125  }
126 }
127
128 return 0;
129}
130
[0]131int clients_delete (int id) {
132 int i;
[1164]133 int close_client_fh = 1;
[0]134
[2608]135 ROAR_DBG("clients_delete(id=%i) = ?", id);
136
[4101]137 counters_inc(clients, -1);
138
[3910]139 _CHECK_CID(id);
[0]140
[4326]141 if (ROAR_CLIENT(g_clients[id])->execed != -1) {
[0]142//  return streams_delete(g_clients[id]->execed);
[4326]143  ROAR_CLIENT(g_clients[id])->execed = -1;
[1164]144  close_client_fh = 0;
[0]145 }
146
147 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) {
[4326]148  streams_delete(ROAR_CLIENT(g_clients[id])->streams[i]);
[0]149 }
150
[4326]151 if ( ROAR_CLIENT(g_clients[id])->fh != -1 && close_client_fh )
152  close(ROAR_CLIENT(g_clients[id])->fh);
[0]153
[4326]154 roar_nnode_free(&(ROAR_CLIENT(g_clients[id])->nnode));
[2815]155
[3063]156 roar_mm_free(g_clients[id]);
[0]157 g_clients[id] = NULL;
158
159 ROAR_DBG("clients_delete(id=%i) = 0", id);
160 return 0;
161}
162
[3927]163int clients_close      (int id, int nocheck_exec) {
164 struct roar_client * c;
165
166 ROAR_DBG("clients_close(id=%i) = ?", id);
167
168 _CHECK_CID(id);
169
[4326]170 c = ROAR_CLIENT(g_clients[id]);
[3927]171
172 if ( c->fh == -1 ) {
173  ROAR_DBG("clients_delete(id=%i) = 0", id);
174  return 0;
175 }
176
[4326]177 if (nocheck_exec || c->execed != -1) {
[3927]178  close(c->fh);
179  c->fh = -1;
180 }
181
182 ROAR_DBG("clients_delete(id=%i) = 0", id);
183 return 0;
184}
185
[0]186int clients_get       (int id, struct roar_client ** client) {
[3910]187 _CHECK_CID(id);
188
[4326]189 *client = ROAR_CLIENT(g_clients[id]);
[0]190
191 if ( *client == NULL )
192  return -1;
193
194 return 0;
195}
196
197int clients_set_fh    (int id, int    fh) {
[3713]198 struct roar_client * c;
199#ifdef SO_PEERCRED
200 struct ucred cred;
201 socklen_t cred_len = sizeof(cred);
202#endif
[501]203
[3910]204 _CHECK_CID(id);
205
[4326]206 if ( (c = ROAR_CLIENT(g_clients[id])) == NULL )
[0]207  return -1;
208
[3713]209 c->fh = fh;
210
211#ifdef SO_PEERCRED
212 if (getsockopt(fh, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len) != -1) {
213  if ( cred.pid != 0 ) {
214   c->pid = cred.pid;
215   c->uid = cred.uid;
216   c->gid = cred.gid;
217  }
218 } else {
219  ROAR_DBG("req_on_identify(): Can't get creds via SO_PEERCRED: %s", strerror(errno));
220 }
221#elif defined(ROAR_HAVE_GETPEEREID)
222 if (getpeereid(fh, &(c->uid), &(c->gid)) == -1) {
223  ROAR_DBG("req_on_identify(): Can't get creds via getpeereid(): %s", strerror(errno));
224 }
225#endif
[0]226
227 return 0;
228}
229
[755]230int clients_get_fh    (int id) {
[3910]231 _CHECK_CID(id);
[755]232
[4326]233 return ROAR_CLIENT(g_clients[id])->fh;
[755]234}
235
[0]236int clients_set_pid   (int id, int    pid) {
[3910]237 _CHECK_CID(id);
[0]238
[4326]239 ROAR_CLIENT(g_clients[id])->pid = pid;
[0]240
241 return 0;
242}
243
[439]244int clients_set_uid   (int id, int    uid) {
[3910]245 _CHECK_CID(id);
[439]246
[4326]247 ROAR_CLIENT(g_clients[id])->uid = uid;
[439]248
249 return 0;
250}
251
252int clients_set_gid   (int id, int    gid) {
[3910]253 _CHECK_CID(id);
[439]254
[4326]255 ROAR_CLIENT(g_clients[id])->gid = gid;
[439]256
257 return 0;
258}
259
[2517]260int clients_set_proto (int id, int    proto) {
[2614]261 int byteorder = ROAR_BYTEORDER_UNKNOWN;
262
[3910]263 _CHECK_CID(id);
[2517]264
[2614]265 switch (proto) {
266  case ROAR_PROTO_ROARAUDIO:
[2828]267  case ROAR_PROTO_ESOUND:
[3981]268  case ROAR_PROTO_RPLAY:
[3255]269  case ROAR_PROTO_SIMPLE:
[2614]270    byteorder = ROAR_BYTEORDER_NETWORK;
271   break;
272 }
273
[4326]274 ROAR_CLIENT(g_clients[id])->proto     = proto;
275 ROAR_CLIENT(g_clients[id])->byteorder = byteorder;
[2517]276
277 return 0;
278}
279
[498]280#define MAX_STREAMLESS 8
281
[0]282int clients_check_all (void) {
[1480]283#ifdef ROAR_HAVE_SELECT
[4326]284 struct roar_client * c;
[0]285 struct timeval tv;
286 fd_set r, e;
[66]287 int i, j;
[0]288 int ret;
289 int fh;
290 int max_fh = -1;
[71]291 int have = 0;
[498]292 struct {
293  int id;
294  int fh;
295 } streamless[MAX_STREAMLESS];
296 int have_streamless = 0;
297 int have_stream;
[0]298
299 FD_ZERO(&r);
300 FD_ZERO(&e);
301
302 tv.tv_sec  = 0;
303 tv.tv_usec = 1;
304
305 for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
[4326]306  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL )
[0]307   continue;
308
[4326]309  if ( (fh = c->fh) != -1 ) {
[71]310   have++;
311
[610]312   ROAR_DBG("clients_check_all(*): fh=%i", fh);
313
[66]314   FD_SET(fh, &r);
315   FD_SET(fh, &e);
316
317   if ( fh > max_fh )
318    max_fh = fh;
[84]319  }
[0]320
[498]321  have_stream = 0;
322
[84]323  for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) {
[4326]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);
[1504]326    if ( fh > -1 ) {
327     FD_SET(fh, &r);
[0]328
[1504]329     if ( fh > max_fh )
330      max_fh = fh;
[3579]331    } else if ( fh == -2 ) {
[4326]332     streams_check(c->streams[j]);
[1504]333    }
[498]334
335    have_stream = 1;
[66]336   }
[84]337   //printf("D: client=%i, stream=%i, fh=%i\n", i, j, fh);
[66]338  }
339
[498]340  if ( !have_stream && have_streamless < MAX_STREAMLESS ) {
341   streamless[have_streamless  ].id = i;
[4326]342   if ( (streamless[have_streamless++].fh = c->fh) == -1 )
[498]343    have_streamless--;
344  }
[0]345 }
346
[256]347 if ( max_fh == -1 )
348  return 0;
349
[0]350 if ( (ret = select(max_fh + 1, &r, NULL, &e, &tv)) < 1 ) {
[71]351  return ret < 0 ? ret : have;
[0]352 }
353
354 for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
[4326]355  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL )
[0]356   continue;
357
[4326]358  if ( (fh = c->fh) != -1 ) {
[66]359   if ( FD_ISSET(fh, &r) ) {
[4326]360    if ( c->execed == -1 ) {
[66]361     clients_check(i);
[4326]362     if ( g_clients[i] != NULL && ROAR_CLIENT(g_clients[i])->execed != -1 ) {
[1834]363      FD_CLR(fh, &r);
364     }
[255]365/*
[66]366    } else {
367     streams_check(g_clients[i]->execed);
[255]368*/
[66]369    }
370   }
[0]371
[84]372   if ( FD_ISSET(fh, &e) ) {
[66]373    clients_delete(i);
[84]374    continue;
375   }
376  }
377
[4326]378  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL )
[84]379   continue;
380
381  for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) {
[1611]382   ROAR_DBG("clients_check_all(*): D: client=%i, stream=%i, g_clients[i=%i] = %p", i, j, i, g_clients[i]);
[136]383   if ( g_clients[i] == NULL ) // streams_check() bellow can delete our client (why?)
384    break;
[1611]385
386   //ROAR_WARN("clients_check_all(*): client=%i: client exists", i);
[4326]387   ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, c->streams[j]);
[1611]388
[4326]389   if ( (fh = streams_get_fh(c->streams[j])) != -1 ) {
[1611]390    ROAR_DBG("clients_check_all(*): client=%i, stream=%i: fh=%i", i, j, fh);
[3579]391    if ( fh > -1 && FD_ISSET(fh, &r) ) {
[4326]392     streams_check(c->streams[j]);
[66]393    }
[0]394   }
395  }
396 }
397
[498]398 if ( have_streamless ) {
399   FD_ZERO(&r);
400
401   tv.tv_sec  = 0;
402   tv.tv_usec = 1;
403
404   max_fh = -1;
405
406   for (i = 0; i < have_streamless; i++) {
[4326]407    if ( g_clients[j = streamless[i].id] == NULL )
[607]408     continue;
409
[4326]410    if ( ROAR_CLIENT(g_clients[j])->execed != -1 )
[601]411     continue;
412
[498]413    fh = streamless[i].fh;
414
415    ROAR_DBG("clients_check_all(void): fh=%i", fh);
416    FD_SET(fh, &r);
417
418    if ( fh > max_fh )
419     max_fh = fh;
420   }
421
422   if ( (ret = select(max_fh + 1, &r, NULL, NULL, &tv)) < 0 ) {
423    return ret;
424   }
425
426   for (i = 0; i < have_streamless; i++) {
427    if ( FD_ISSET(streamless[i].fh, &r) ) {
428     clients_check(streamless[i].id);
429    }
430   }
431 }
432
[71]433 ROAR_DBG("clients_check_all(void) = %i // have value", have);
434 return have;
[1480]435#else
436 return -1;
437#endif
[0]438}
439
440int clients_check     (int id) {
[4326]441 struct roar_client   * c;
[0]442 struct roar_message    m;
443 struct roar_connection con;
444 char * data = NULL;
445 int oldcmd;
446 int r;
[498]447 int rv = 0;
[3926]448 uint32_t flags[2] = {COMMAND_FLAG_NONE, COMMAND_FLAG_NONE};
[4325]449 uint32_t event;
[0]450
[3910]451 _CHECK_CID(id);
452
[4326]453 c = ROAR_CLIENT(g_clients[id]);
454
455 if ( c->fh == -1 )
[0]456  return -1;
457
[4326]458 roar_connect_fh(&con, c->fh);
[0]459
[4326]460 switch (c->proto) {
[2517]461  case ROAR_PROTO_ROARAUDIO:
462    r = roar_recv_message(&con, &m, &data);
[0]463
[2517]464    if ( r == -1 ) { // should we drop the client?
465     clients_delete(id);
466     return -1;
467    }
[0]468
[4325]469    event = ROAR_NOTIFY_CMD2EVENT(m.cmd);
470
[2517]471    roar_debug_message_print(&m);
[0]472
[2517]473    oldcmd = m.cmd;
[0]474
[3926]475    if ( (r = command_exec(id, &m, &data, flags)) == -1 ) {
[2517]476     m.cmd     = ROAR_CMD_ERROR;
477     m.datalen = 0;
478     ROAR_DBG("clients_check(*): Exec of command faild!");
479    } else {
480     if ( m.cmd == oldcmd ) {
481      m.cmd     = ROAR_CMD_OK;
482      m.datalen = 0;
483     } else if ( m.cmd == ROAR_CMD_OK_STOP ) {
484      m.cmd     = ROAR_CMD_OK;
485      rv        = 1;
486     }
487    }
488
[4325]489    roar_notify_core_emit_simple(event, id, -1, -1, m.cmd, -1, NULL, 0);
490
[4298]491    ROAR_DBG("clients_check(*): data=%p", data);
492
[4297]493    roar_send_message(&con, &m, flags[1] & COMMAND_FLAG_OUT_LONGDATA ? data : NULL);
[3928]494
495    if ( flags[1] & COMMAND_FLAG_OUT_CLOSECON )
496     clients_close(id, 1);
497
[2517]498   break;
[2546]499#ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD
[2791]500#ifdef ROAR_HAVE_H_ESD
[2523]501  case ROAR_PROTO_ESOUND:
502    rv = emul_esd_check_client(id, NULL);
503   break;
[2546]504#endif
505#endif
[3981]506#ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY
507  case ROAR_PROTO_RPLAY:
[3982]508    rv = emul_rplay_check_client(id, NULL);
[3981]509   break;
510#endif
[4020]511#ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND
[3684]512  case ROAR_PROTO_RSOUND:
[3820]513    rv = emul_rsound_check_client(id, NULL);
[3825]514    if ( rv == 0 ) { // loop as long as we don't get an error.
515     while (rv == 0)
516      rv = emul_rsound_check_client(id, NULL);
517     rv = 0; // restore
518    } else { // in case of error delete the client
[4131]519     if (
520#ifdef EAGAIN
[4153]521          errno != EAGAIN      &&
[4131]522#endif
523#ifdef EWOULDBLOCK
[4153]524          errno != EWOULDBLOCK &&
[4131]525#endif
526#ifdef EINTR
[4153]527          errno != EINTR       &&
[4131]528#endif
[4153]529          1 ) {
[4131]530      rv = clients_delete(id);
531     } else {
532      rv = 0;
533     }
[3825]534    }
[3684]535   break;
536#endif
[2517]537  default:
538    rv = -1;
[0]539 }
540
[4297]541 if ( data != NULL )
[0]542  free(data);
543
[2517]544 ROAR_DBG("clients_check(id=%i) = %i", id, rv);
[498]545 return rv;
[0]546}
547
548int clients_send_mon  (struct roar_audio_info * sa, uint32_t pos) {
549 int i;
[934]550// int fh;
551 int j;
[2715]552 int keep_going;
[0]553
554 for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
555  if ( g_clients[i] == NULL )
556   continue;
557
[2715]558  keep_going = 1;
559
[934]560/*
[0]561  if ( (fh = g_clients[i]->fh) == -1 )
562   continue;
[934]563*/
[0]564
[4326]565  ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, ROAR_CLIENT(g_clients[i])->execed);
[1905]566
[2706]567/*
[0]568  if ( g_clients[i]->execed == -1 ) {
569   // TODO: add some code to send a message to the client insetd of the raw data.
[2706]570*/
[2715]571   for (j = 0; keep_going && j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) {
[934]572    //if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) {
[2715]573    ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> ?", i, j);
[4326]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]);
[2715]577
578     // the client may be deleted here, check if it still exists:
579     if ( g_clients[i] == NULL )
580      keep_going = 0;
[1905]581    }
[934]582   }
[2706]583/*
[0]584  } else {
585//   streams_check(g_clients[i]->execed);
586   streams_send_mon(g_clients[i]->execed);
587//   if ( streams_send_mon(g_clients[i]->execed) == -1 )
588//    clients_delete(i); // delete client in case we could not write
589  }
[2706]590*/
[0]591 }
592
[1902]593 // TODO: FIXME: should this really be -1?
[0]594 return -1;
595}
596
597int clients_send_filter(struct roar_audio_info * sa, uint32_t pos) {
[4326]598 struct roar_client * c;
[0]599 int i;
600 int fh;
601
602 for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
[4326]603  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL )
[0]604   continue;
605
[4326]606  if ( (fh = c->fh) == -1 )
[0]607   continue;
608
[4326]609  if ( c->execed == -1 ) {
[0]610   // TODO: add some code to send a message to the client insetd of the raw data.
611  } else {
612//   streams_check(g_clients[i]->execed);
[4326]613   streams_send_filter(c->execed);
[0]614//   if ( streams_send_mon(g_clients[i]->execed) == -1 )
615//    clients_delete(i); // delete client in case we could not write
616  }
617 }
618
619 return -1;
620}
621
622int client_stream_exec   (int client, int stream) {
[4326]623 struct roar_client * c;
[0]624 int i;
[3920]625 int fh;
[0]626
[3910]627 _CHECK_CID(client);
628
629#if 0
[1901]630 if ( g_clients[client] == NULL ) {
631  ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not exist", client, stream);
[0]632  return -1;
[1901]633 }
[3910]634#endif
[0]635
[4326]636 c = ROAR_CLIENT(g_clients[client]);
637
[0]638 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) {
[4326]639  if ( c->streams[i] == stream ) {
640   c->execed = stream;
[3921]641   if ( streams_is_ready(stream) == 0 ) {
[4326]642    streams_set_fh(stream, c->fh);
[3920]643    streams_set_socktype(stream, ROAR_SOCKET_TYPE_GENSTR);
644   } else {
[4254]645    ROAR_DBG("client_stream_exec(client=%i, stream=%i): fh=?", client, stream);
[4326]646    if ( (fh = c->fh) != -1 ) {
[3925]647     close(fh);
[4326]648     c->fh = -1;
[3925]649    }
[3920]650   }
[2815]651   ROAR_DBG("client_stream_exec(client=%i, stream=%i) = 0", client, stream);
[0]652   return 0;
653  }
654 }
655
[1901]656 ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not own stream", client, stream);
[0]657 return -1;
658}
659
[78]660int client_stream_set_fh (int client, int stream, int fh) {
661 int i;
662
[4240]663 ROAR_DBG("client_stream_set_fh(client=%i, stream=%i, fh=%i) = ?", client, stream, fh);
664
[3910]665 _CHECK_CID(client);
[78]666
667 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) {
[4326]668  if ( ROAR_CLIENT(g_clients[client])->streams[i] == stream ) {
[4240]669   ROAR_DBG("client_stream_set_fh(client=%i, stream=%i, fh=%i): stream found, index %i", client, stream, fh, i);
[4229]670   return streams_set_fh(stream, fh);
[78]671  }
672 }
673
[4240]674 ROAR_WARN("client_stream_set_fh(client=%i, stream=%i, fh=%i) = -1 // client does not own stream", client, stream, fh);
[78]675 return -1;
676}
677
[0]678int client_stream_add    (int client, int stream) {
679 int i;
680
[3910]681 _CHECK_CID(client);
[0]682
683 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) {
[4326]684  if ( ROAR_CLIENT(g_clients[client])->streams[i] == -1 ) {
685   ROAR_CLIENT(g_clients[client])->streams[i] = stream;
[0]686   streams_set_client(stream, client);
687   return 0;
688  }
689 }
690
691 return -1;
692}
693
694int client_stream_delete (int client, int stream) {
695 int i;
696
[3910]697 _CHECK_CID(client);
[0]698
699 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) {
[4326]700  if ( ROAR_CLIENT(g_clients[client])->streams[i] == stream ) {
701   ROAR_CLIENT(g_clients[client])->streams[i] = -1;
[0]702
[4326]703   if ( stream == ROAR_CLIENT(g_clients[client])->execed ) {
[0]704    ROAR_DBG("client_stream_delete(client=%i, stream=%i): stream is execed one, deleting client!", client, stream);
705    clients_delete(client);
706   }
707
708   ROAR_DBG("client_stream_delete(client=%i, stream=%i) = 0", client, stream);
709   return 0;
710  }
711 }
712
713 ROAR_DBG("client_stream_delete(client=%i, stream=%i) = -1", client, stream);
714 return -1;
715}
716
[767]717int client_stream_move   (int client, int stream) {
718 int old_client = streams_get_client(stream);
719
[771]720 ROAR_DBG("client_stream_move(client=%i, stream=%i): old_client = %i", client, stream, old_client);
721
[767]722 if ( old_client != -1 )
723  if ( client_stream_delete(old_client, stream) == -1 )
724   return -1;
725
726 return client_stream_add(client, stream);
727}
728
[0]729//ll
Note: See TracBrowser for help on using the repository browser.