Index: include/libroar/client.h
===================================================================
--- include/libroar/client.h	(revision 3718)
+++ include/libroar/client.h	(revision 4326)
@@ -39,4 +39,6 @@
 #include "libroar.h"
 
+#define ROAR_CLIENT(x) ((struct roar_client*)(x))
+
 struct roar_client {
  int fh; /* controll connection */
Index: roard/clients.c
===================================================================
--- roard/clients.c	(revision 4325)
+++ roard/clients.c	(revision 4326)
@@ -51,9 +51,14 @@
  int i;
  int s;
+ struct roar_client_server * ns;
  struct roar_client * n;
 
  for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
   if ( g_clients[i] == NULL ) {
-   n = roar_mm_malloc(sizeof(struct roar_client));
+   ns = roar_mm_malloc(sizeof(struct roar_client_server));
+   n = ROAR_CLIENT(ns);
+
+   memset(ns, 0, sizeof(struct roar_client_server));
+
    if ( n != NULL ) {
     n->pid    = -1;
@@ -79,5 +84,5 @@
     }
 
-    g_clients[i] = n;
+    g_clients[i] = ns;
 
     counters_inc(clients, 1);
@@ -134,18 +139,18 @@
  _CHECK_CID(id);
 
- if (g_clients[id]->execed != -1) {
+ if (ROAR_CLIENT(g_clients[id])->execed != -1) {
 //  return streams_delete(g_clients[id]->execed);
-  g_clients[id]->execed = -1;
+  ROAR_CLIENT(g_clients[id])->execed = -1;
   close_client_fh = 0;
  }
 
  for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) {
-  streams_delete(g_clients[id]->streams[i]);
- }
-
- if ( g_clients[id]->fh != -1 && close_client_fh )
-  close(g_clients[id]->fh);
-
- roar_nnode_free(&(g_clients[id]->nnode));
+  streams_delete(ROAR_CLIENT(g_clients[id])->streams[i]);
+ }
+
+ if ( ROAR_CLIENT(g_clients[id])->fh != -1 && close_client_fh )
+  close(ROAR_CLIENT(g_clients[id])->fh);
+
+ roar_nnode_free(&(ROAR_CLIENT(g_clients[id])->nnode));
 
  roar_mm_free(g_clients[id]);
@@ -163,5 +168,5 @@
  _CHECK_CID(id);
 
- c = g_clients[id];
+ c = ROAR_CLIENT(g_clients[id]);
 
  if ( c->fh == -1 ) {
@@ -170,5 +175,5 @@
  }
 
- if (nocheck_exec || g_clients[id]->execed != -1) {
+ if (nocheck_exec || c->execed != -1) {
   close(c->fh);
   c->fh = -1;
@@ -182,5 +187,5 @@
  _CHECK_CID(id);
 
- *client = g_clients[id];
+ *client = ROAR_CLIENT(g_clients[id]);
 
  if ( *client == NULL )
@@ -199,5 +204,5 @@
  _CHECK_CID(id);
 
- if ( (c = g_clients[id]) == NULL )
+ if ( (c = ROAR_CLIENT(g_clients[id])) == NULL )
   return -1;
 
@@ -226,5 +231,5 @@
  _CHECK_CID(id);
 
- return g_clients[id]->fh;
+ return ROAR_CLIENT(g_clients[id])->fh;
 }
 
@@ -232,5 +237,5 @@
  _CHECK_CID(id);
 
- g_clients[id]->pid = pid;
+ ROAR_CLIENT(g_clients[id])->pid = pid;
 
  return 0;
@@ -240,5 +245,5 @@
  _CHECK_CID(id);
 
- g_clients[id]->uid = uid;
+ ROAR_CLIENT(g_clients[id])->uid = uid;
 
  return 0;
@@ -248,5 +253,5 @@
  _CHECK_CID(id);
 
- g_clients[id]->gid = gid;
+ ROAR_CLIENT(g_clients[id])->gid = gid;
 
  return 0;
@@ -267,6 +272,6 @@
  }
 
- g_clients[id]->proto     = proto;
- g_clients[id]->byteorder = byteorder;
+ ROAR_CLIENT(g_clients[id])->proto     = proto;
+ ROAR_CLIENT(g_clients[id])->byteorder = byteorder;
 
  return 0;
@@ -277,4 +282,5 @@
 int clients_check_all (void) {
 #ifdef ROAR_HAVE_SELECT
+ struct roar_client * c;
  struct timeval tv;
  fd_set r, e;
@@ -298,8 +304,8 @@
 
  for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
-  if ( g_clients[i] == NULL )
+  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL )
    continue;
 
-  if ( (fh = g_clients[i]->fh) != -1 ) {
+  if ( (fh = c->fh) != -1 ) {
    have++;
 
@@ -316,6 +322,6 @@
 
   for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) {
-   if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) {
-    ROAR_DBG("clients_check_all(*): g_clients[i=%i]->streams[j=%i] = %i, fh = %i", i, j, g_clients[i]->streams[j], fh);
+   if ( (fh = streams_get_fh(c->streams[j])) != -1 ) {
+    ROAR_DBG("clients_check_all(*): g_clients[i=%i]->streams[j=%i] = %i, fh = %i", i, j, c->streams[j], fh);
     if ( fh > -1 ) {
      FD_SET(fh, &r);
@@ -324,5 +330,5 @@
       max_fh = fh;
     } else if ( fh == -2 ) {
-     streams_check(g_clients[i]->streams[j]);
+     streams_check(c->streams[j]);
     }
 
@@ -334,5 +340,5 @@
   if ( !have_stream && have_streamless < MAX_STREAMLESS ) {
    streamless[have_streamless  ].id = i;
-   if ( (streamless[have_streamless++].fh = g_clients[i]->fh) == -1 )
+   if ( (streamless[have_streamless++].fh = c->fh) == -1 )
     have_streamless--;
   }
@@ -347,12 +353,12 @@
 
  for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
-  if ( g_clients[i] == NULL )
+  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL )
    continue;
 
-  if ( (fh = g_clients[i]->fh) != -1 ) {
+  if ( (fh = c->fh) != -1 ) {
    if ( FD_ISSET(fh, &r) ) {
-    if ( g_clients[i]->execed == -1 ) {
+    if ( c->execed == -1 ) {
      clients_check(i);
-     if ( g_clients[i] != NULL && g_clients[i]->execed != -1 ) {
+     if ( g_clients[i] != NULL && ROAR_CLIENT(g_clients[i])->execed != -1 ) {
       FD_CLR(fh, &r);
      }
@@ -370,5 +376,5 @@
   }
 
-  if ( g_clients[i] == NULL )
+  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL )
    continue;
 
@@ -379,10 +385,10 @@
 
    //ROAR_WARN("clients_check_all(*): client=%i: client exists", i);
-   ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, g_clients[i]->streams[j]);
-
-   if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) {
+   ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, c->streams[j]);
+
+   if ( (fh = streams_get_fh(c->streams[j])) != -1 ) {
     ROAR_DBG("clients_check_all(*): client=%i, stream=%i: fh=%i", i, j, fh);
     if ( fh > -1 && FD_ISSET(fh, &r) ) {
-     streams_check(g_clients[i]->streams[j]);
+     streams_check(c->streams[j]);
     }
    }
@@ -399,8 +405,8 @@
 
    for (i = 0; i < have_streamless; i++) {
-    if ( ! g_clients[j = streamless[i].id] )
+    if ( g_clients[j = streamless[i].id] == NULL )
      continue;
 
-    if ( g_clients[j]->execed != -1 )
+    if ( ROAR_CLIENT(g_clients[j])->execed != -1 )
      continue;
 
@@ -433,4 +439,5 @@
 
 int clients_check     (int id) {
+ struct roar_client   * c;
  struct roar_message    m;
  struct roar_connection con;
@@ -444,10 +451,12 @@
  _CHECK_CID(id);
 
- if ( g_clients[id]->fh == -1 )
+ c = ROAR_CLIENT(g_clients[id]);
+
+ if ( c->fh == -1 )
   return -1;
 
- roar_connect_fh(&con, g_clients[id]->fh);
-
- switch (g_clients[id]->proto) {
+ roar_connect_fh(&con, c->fh);
+
+ switch (c->proto) {
   case ROAR_PROTO_ROARAUDIO:
     r = roar_recv_message(&con, &m, &data);
@@ -554,5 +563,5 @@
 */
 
-  ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, g_clients[i]->execed);
+  ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, ROAR_CLIENT(g_clients[i])->execed);
 
 /*
@@ -563,7 +572,7 @@
     //if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) {
     ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> ?", i, j);
-    if ( g_clients[i]->streams[j] != -1 ) {
-     ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> %i", i, j, g_clients[i]->streams[j]);
-     streams_send_mon(g_clients[i]->streams[j]);
+    if ( ROAR_CLIENT(g_clients[i])->streams[j] != -1 ) {
+     ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> %i", i, j, ROAR_CLIENT(g_clients[i])->streams[j]);
+     streams_send_mon(ROAR_CLIENT(g_clients[i])->streams[j]);
 
      // the client may be deleted here, check if it still exists:
@@ -587,19 +596,20 @@
 
 int clients_send_filter(struct roar_audio_info * sa, uint32_t pos) {
+ struct roar_client * c;
  int i;
  int fh;
 
  for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
-  if ( g_clients[i] == NULL )
+  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL )
    continue;
 
-  if ( (fh = g_clients[i]->fh) == -1 )
+  if ( (fh = c->fh) == -1 )
    continue;
 
-  if ( g_clients[i]->execed == -1 ) {
+  if ( c->execed == -1 ) {
    // TODO: add some code to send a message to the client insetd of the raw data.
   } else {
 //   streams_check(g_clients[i]->execed);
-   streams_send_filter(g_clients[i]->execed);
+   streams_send_filter(c->execed);
 //   if ( streams_send_mon(g_clients[i]->execed) == -1 )
 //    clients_delete(i); // delete client in case we could not write
@@ -611,4 +621,5 @@
 
 int client_stream_exec   (int client, int stream) {
+ struct roar_client * c;
  int i;
  int fh;
@@ -623,15 +634,17 @@
 #endif
 
+ c = ROAR_CLIENT(g_clients[client]);
+
  for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) {
-  if ( g_clients[client]->streams[i] == stream ) {
-   g_clients[client]->execed = stream;
+  if ( c->streams[i] == stream ) {
+   c->execed = stream;
    if ( streams_is_ready(stream) == 0 ) {
-    streams_set_fh(stream, g_clients[client]->fh);
+    streams_set_fh(stream, c->fh);
     streams_set_socktype(stream, ROAR_SOCKET_TYPE_GENSTR);
    } else {
     ROAR_DBG("client_stream_exec(client=%i, stream=%i): fh=?", client, stream);
-    if ( (fh = g_clients[client]->fh) != -1 ) {
+    if ( (fh = c->fh) != -1 ) {
      close(fh);
-     g_clients[client]->fh = -1;
+     c->fh = -1;
     }
    }
@@ -653,5 +666,5 @@
 
  for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) {
-  if ( g_clients[client]->streams[i] == stream ) {
+  if ( ROAR_CLIENT(g_clients[client])->streams[i] == stream ) {
    ROAR_DBG("client_stream_set_fh(client=%i, stream=%i, fh=%i): stream found, index %i", client, stream, fh, i);
    return streams_set_fh(stream, fh);
@@ -669,6 +682,6 @@
 
  for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) {
-  if ( g_clients[client]->streams[i] == -1 ) {
-   g_clients[client]->streams[i] = stream;
+  if ( ROAR_CLIENT(g_clients[client])->streams[i] == -1 ) {
+   ROAR_CLIENT(g_clients[client])->streams[i] = stream;
    streams_set_client(stream, client);
    return 0;
@@ -685,8 +698,8 @@
 
  for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) {
-  if ( g_clients[client]->streams[i] == stream ) {
-   g_clients[client]->streams[i] = -1;
-
-   if ( stream == g_clients[client]->execed ) {
+  if ( ROAR_CLIENT(g_clients[client])->streams[i] == stream ) {
+   ROAR_CLIENT(g_clients[client])->streams[i] = -1;
+
+   if ( stream == ROAR_CLIENT(g_clients[client])->execed ) {
     ROAR_DBG("client_stream_delete(client=%i, stream=%i): stream is execed one, deleting client!", client, stream);
     clients_delete(client);
Index: roard/include/client.h
===================================================================
--- roard/include/client.h	(revision 3927)
+++ roard/include/client.h	(revision 4326)
@@ -47,5 +47,7 @@
 */
 
-struct roar_client * g_clients[ROAR_CLIENTS_MAX];
+struct roar_client_server {
+ struct roar_client _client;
+} * g_clients[ROAR_CLIENTS_MAX];
 
 
