]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
added trbnetd locking by signals usr1 and usr2
authorhadaq <hadaq>
Wed, 8 Feb 2012 17:06:24 +0000 (17:06 +0000)
committerhadaq <hadaq>
Wed, 8 Feb 2012 17:06:24 +0000 (17:06 +0000)
trbnetd/server/trbnetd.c
trbnetd/trbnetrpc.c

index 13f3eddddcc5d3a7a155b38136ddd586be9c79e8..3c8df761951f6dfc671eab71a710680e79ae128d 100644 (file)
@@ -14,7 +14,9 @@
 
 #include "trbrpc.h"
 
-static const char trbnetd_version[] = "$Revision: 1.11 $";
+static const char trbnetd_version[] = "$Revision: 1.12 $";
+
+static int daemon_lock = 0;
 
 int trbnetrpcprog_1_freeresult(SVCXPRT * transp,
                                xdrproc_t xdr_result, caddr_t result)
@@ -44,6 +46,7 @@ bool_t register_read_1_svc(uint16_t trb_address,
   int status;
   
   /* allocate buffer memory */
+  retVal->data.Buffer_len = 0;
   retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * dsize);
   if (retVal->data.Buffer_val == NULL) {
     fprintf(stderr, "register_read: malloc failed\n");
@@ -51,7 +54,12 @@ bool_t register_read_1_svc(uint16_t trb_address,
     retVal->status.trb_errno = TRB_RPC_ERROR;
     return TRUE;
   }
-  
+
+  if (daemon_lock == 1) {
+    retVal->status.retVal = -128;
+    return TRUE;
+  }
+
   status = trb_register_read(trb_address, reg_address,
                              (uint32_t *) retVal->data.Buffer_val, dsize);
   retVal->data.Buffer_len = status == -1 ? 0 : status;
@@ -68,8 +76,9 @@ bool_t registertime_read_1_svc(uint16_t trb_address,
                                struct svc_req * rqstp)
 {
   int status;
-  /* allocate buffer memory */
 
+  /* allocate buffer memory */
+  retVal->data.Buffer_len = 0;
   retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * dsize);
   if (retVal->data.Buffer_val == NULL) {
     fprintf(stderr, "registertime_read: malloc failed\n");
@@ -78,6 +87,11 @@ bool_t registertime_read_1_svc(uint16_t trb_address,
     return TRUE;
   }
 
+  if (daemon_lock == 1) {
+    retVal->status.retVal = -128;
+    return TRUE;
+  }
+
   status = trb_registertime_read(trb_address, reg_address,
                                  (uint32_t *) retVal->data.Buffer_val, dsize);
   retVal->data.Buffer_len = status == -1 ? 0 : status;
@@ -98,6 +112,7 @@ bool_t register_read_mem_1_svc(uint16_t trb_address,
   int status;
 
   /* allocate buffer memory */
+  retVal->data.Buffer_len = 0;
   retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * dsize);
   if (retVal->data.Buffer_val == NULL) {
     fprintf(stderr, "register_read_mem: malloc failed\n");
@@ -105,6 +120,11 @@ bool_t register_read_mem_1_svc(uint16_t trb_address,
     retVal->status.retVal = -1;
     return TRUE;
   }
+
+  if (daemon_lock == 1) {
+    retVal->status.retVal = -128;
+    return TRUE;
+  }
   
   status = trb_register_read_mem(trb_address, reg_address, option, size,
                                  (uint32_t *) retVal->data.Buffer_val, dsize);
@@ -127,6 +147,7 @@ bool_t registertime_read_mem_1_svc(uint16_t trb_address,
   int status;
 
   /* allocate buffer memory */
+  retVal->data.Buffer_len = 0;
   retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * dsize);
   if (retVal->data.Buffer_val == NULL) {
     fprintf(stderr, "registertime_read_mem: malloc failed\n");
@@ -150,7 +171,12 @@ bool_t register_write_1_svc(uint16_t trb_address,
                             uint32_t value, 
                             Status* retVal, 
                             struct svc_req* rqstp)
-{
+{  
+  if (daemon_lock == 1) {
+    retVal->retVal = -128;
+    return TRUE;
+  }
+  
   retVal->retVal = trb_register_write(trb_address, reg_address, value);
   copyStatus(retVal);
   
@@ -164,6 +190,11 @@ bool_t register_write_mem_1_svc(uint16_t trb_address,
                                 Status* retVal, 
                                 struct svc_req* rqstp)
 {
+  if (daemon_lock == 1) {
+    retVal->retVal = -128;
+    return TRUE;
+  }
+  
   retVal->retVal =
     trb_register_write_mem(trb_address, reg_address, option, 
                            (uint32_t*)data.Buffer_val, data.Buffer_len);
@@ -178,9 +209,8 @@ bool_t read_uid_1_svc(uint16_t trb_address,
                       struct svc_req* rqstp)
 {
   int status;
-
+  
   /* allocate buffer memory */
-  retVal->data.Buffer_val = NULL;
   retVal->data.Buffer_len = 0;
   retVal->data.Buffer_val = (uint32_t*)malloc(sizeof(uint32_t) * dsize);
   
@@ -190,7 +220,12 @@ bool_t read_uid_1_svc(uint16_t trb_address,
     retVal->status.retVal = -1;
     return TRUE;
   }
-    
+  
+  if (daemon_lock == 1) {
+    retVal->status.retVal = -128;
+    return TRUE;
+  } 
+  
   status = trb_read_uid(trb_address, 
                         (uint32_t*)retVal->data.Buffer_val,
                         dsize);
@@ -207,6 +242,11 @@ bool_t set_address_1_svc(uint64_t uid,
                          Status* retVal, 
                          struct svc_req* rqstp)
 {
+  if (daemon_lock == 1) {
+    retVal->retVal = -128;
+    return TRUE;
+  } 
+  
   retVal->retVal = trb_set_address(uid, endpoint, trb_address);
   copyStatus(retVal);
   
@@ -216,6 +256,11 @@ bool_t set_address_1_svc(uint64_t uid,
 bool_t network_reset_1_svc(Status* retVal, 
                            struct svc_req* rqstp)
 {
+  if (daemon_lock == 1) {
+    retVal->retVal = -128;
+    return TRUE;
+  }
+  
   retVal->retVal = network_reset();
   copyStatus(retVal);
   
@@ -229,6 +274,11 @@ bool_t send_trigger_1_svc(uint8_t type,
                           Status* retVal, 
                           struct svc_req* rqstp)
 {
+  if (daemon_lock == 1) {
+    retVal->retVal = -128;
+    return TRUE;
+  }
+  
   retVal->retVal = trb_send_trigger(type, trg_info, trg_random, trg_number);
   copyStatus(retVal);
   
@@ -243,6 +293,11 @@ bool_t send_trigger_rich_1_svc(uint8_t input,
                                Status* retVal, 
                                struct svc_req* rqstp)
 {
+  if (daemon_lock == 1) {
+    retVal->retVal = -128;
+    return TRUE;
+  } 
+  
   retVal->retVal =
     trb_send_trigger_rich(input, type, trg_info, trg_random, trg_number);
   copyStatus(retVal);
@@ -261,6 +316,7 @@ bool_t ipu_data_read_1_svc(uint8_t type,
   int status;
   
   /* allocate buffer memory */
+  retVal->data.Buffer_len = 0;
   retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * dsize);
   if (retVal->data.Buffer_val == NULL) {
     fprintf(stderr, "ipu_data_read: malloc failed\n");
@@ -268,7 +324,12 @@ bool_t ipu_data_read_1_svc(uint8_t type,
     retVal->status.retVal = -1;
     return TRUE;
   }
-
+  
+  if (daemon_lock == 1) {
+    retVal->status.retVal = -128;
+    return TRUE;
+  }
+  
   status = trb_ipu_data_read(type, trg_info, trg_random, trg_number,
                              (uint32_t *)retVal->data.Buffer_val, dsize);
   
@@ -286,6 +347,7 @@ bool_t fpga_register_read_1_svc(uint16_t reg_address,
   int status;
   
   /* allocate buffer memory */
+  retVal->data.Buffer_len = 0;
   retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * 1);
   if (retVal->data.Buffer_val == NULL) {
     fprintf(stderr, "fpga_register_read: malloc failed\n");
@@ -294,6 +356,11 @@ bool_t fpga_register_read_1_svc(uint16_t reg_address,
     return TRUE;
   }
   
+  if (daemon_lock == 1) {
+    retVal->status.retVal = -128;
+    return TRUE;
+  }
+  
   status = fpga_register_read(reg_address,
                               (uint32_t *)retVal->data.Buffer_val);
     
@@ -309,6 +376,11 @@ bool_t fpga_register_write_1_svc(uint16_t reg_address,
                                  Status* retVal, 
                                  struct svc_req* rqstp)
 {
+  if (daemon_lock == 1) {
+    retVal->retVal = -128;
+    return TRUE;
+  }
+  
   retVal->retVal = fpga_register_write(reg_address, value);
   copyStatus(retVal);
   
@@ -319,6 +391,11 @@ bool_t trb_fifo_flush_1_svc(uint8_t channel,
                             Status* retVal,
                             struct svc_req* rqstp)
 {
+  if (daemon_lock == 1) {
+    retVal->retVal = -128;
+    return TRUE;
+  }
+  
   retVal->retVal = trb_fifo_flush(channel);
   copyStatus(retVal);
   
@@ -328,6 +405,11 @@ bool_t trb_fifo_flush_1_svc(uint8_t channel,
 bool_t com_reset_1_svc(Status* retVal,
                        struct svc_req* rqstp)
 {
+  if (daemon_lock == 1) {
+    retVal->retVal = -128;
+    return TRUE;
+  }
+  
   retVal->retVal = com_reset();
   copyStatus(retVal);
   
@@ -342,6 +424,11 @@ bool_t register_modify_1_svc(uint16_t trb_address,
                              Status* retVal, 
                              struct svc_req* rqstp)
 {
+  if (daemon_lock == 1) {
+    retVal->retVal = -128;
+    return TRUE;
+  }
+  
   retVal->retVal = 
     trb_register_modify(trb_address, reg_address, mode, bitMask, bitValue);
   
@@ -354,6 +441,22 @@ extern void trbnetrpcprog_1(struct svc_req *rqstp, register SVCXPRT * transp);
 
 /* ------ MAIN ---------------------------------------------------------- */
 
+static void blockDaemon(int sig) {
+  switch (sig) {
+  
+  case SIGUSR1:
+    daemon_lock = 1;
+    break;
+  
+  case SIGUSR2:
+    daemon_lock = 0;
+    break;
+    
+  default:
+    break;
+  }
+}
+
 void usage(const char *progName)
 {
   fprintf(stdout, "Usage: %s [-h] [-f]\n", progName);
@@ -361,6 +464,9 @@ void usage(const char *progName)
   fprintf(stdout, "  -h    give this help\n");
   fprintf(stdout, "  -f    execute as foreground process\n");
   fprintf(stdout, "  -V    version number\n");
+  fprintf(stdout, "\nSignals:\n");
+  fprintf(stdout, "  USR1  lock daemon\n");
+  fprintf(stdout, "  USR2  unlock daemon\n");
 }
 
 static pid_t myPid = -1;
@@ -402,7 +508,11 @@ int main(int argc, char **argv)
   sigemptyset(&blockSet);
   sigaddset(&blockSet, SIGPIPE);
   sigprocmask(SIG_BLOCK, &blockSet, NULL);
-  
+
+  /* Add SIGUSR1 for blocking daemon */
+  if (signal(SIGUSR1, blockDaemon) == SIG_ERR) abort();
+  if (signal(SIGUSR2, blockDaemon) == SIG_ERR) abort();
+
   pmap_unset(TRBNETRPCPROG, TRBNETRPCVERS);
 
   transp = svctcp_create(RPC_ANYSOCK, 0, 0);
index 38d765e6b7f94b094be3fa5fee050b82c3678739..8ce1236a2d033cf266262b4f7b28a4154abfad54 100644 (file)
@@ -1,15 +1,17 @@
 #include <stdio.h>
 #include <rpc/rpc.h>            /* always needed  */
+#include <unistd.h>
 #include "trbrpc.h"             /* will be generated by rpcgen */
 #include <trberror.h>
 
 #include "trbnet.h"
 
-const char trbnet_version[] = "$Revision: 1.10 $  RPC";
+const char trbnet_version[] = "$Revision: 1.11 $  RPC";
 unsigned int trb_debug = 0;
 unsigned int trb_dma = 0;
 static CLIENT *trb_client = NULL;
 static char trb_server[128] = "";
+static const unsigned int SLEEP_TIME = 2; 
 
 static void copyStatus(const Status* status)
 {
@@ -58,23 +60,26 @@ int trb_register_read(uint16_t trb_address,
   RetVal retVal;
   
   if (trb_client == NULL) return -1;
+  do {
+    retVal.data.Buffer_val = data;
+    retVal.data.Buffer_len = dsize;
+    
+    status =
+      register_read_1(trb_address, reg_address, dsize, 
+                      &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.status.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
-  retVal.data.Buffer_val = data;
-  retVal.data.Buffer_len = dsize;
-
-  status =
-    register_read_1(trb_address, reg_address, dsize, 
-                    &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
-
   copyStatus(&retVal.status);
   return retVal.status.retVal;
 }
@@ -87,23 +92,26 @@ int trb_registertime_read(uint16_t trb_address,
   RetVal retVal;
   
   if (trb_client == NULL) return -1;
-  
-  retVal.data.Buffer_val = data;
-  retVal.data.Buffer_len = dsize;
+  do {
+    retVal.data.Buffer_val = data;
+    retVal.data.Buffer_len = dsize;
 
-  status =
-    registertime_read_1(trb_address, reg_address, dsize, 
+    status =
+      registertime_read_1(trb_address, reg_address, dsize, 
                         &retVal, trb_client);
   
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
-
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.status.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
+  
   copyStatus(&retVal.status);
   return retVal.status.retVal;
 }
@@ -119,22 +127,25 @@ int trb_register_read_mem(uint16_t trb_address,
   RetVal retVal;
   
   if (trb_client == NULL) return -1;
-  
-  retVal.data.Buffer_val = data;
-  retVal.data.Buffer_len = dsize;
-  
-  status =
-    register_read_mem_1(trb_address, reg_address, option, size, dsize,
-                        &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
+  do {  
+    retVal.data.Buffer_val = data;
+    retVal.data.Buffer_len = dsize;
+    
+    status =
+      register_read_mem_1(trb_address, reg_address, option, size, dsize,
+                          &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.status.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
   copyStatus(&retVal.status);
   return retVal.status.retVal;
@@ -149,25 +160,28 @@ int trb_registertime_read_mem(uint16_t trb_address,
 {
   enum clnt_stat status;
   RetVal retVal;
-  
+
   if (trb_client == NULL) return -1;
+  do {  
+    retVal.data.Buffer_val = data;
+    retVal.data.Buffer_len = dsize;
+    
+    status =
+      registertime_read_mem_1(trb_address, reg_address, option, size, dsize,
+                              &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.status.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
-  retVal.data.Buffer_val = data;
-  retVal.data.Buffer_len = dsize;
-  
-  status =
-    registertime_read_mem_1(trb_address, reg_address, option, size, dsize,
-                            &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
-
   copyStatus(&retVal.status);
   return retVal.status.retVal;
 }
@@ -181,20 +195,24 @@ int trb_read_uid(uint16_t trb_address,
   RetVal retVal;
   
   if (trb_client == NULL) return -1;
+  do {
+    retVal.data.Buffer_val = data;
+    retVal.data.Buffer_len = dsize;
+    
+    status = read_uid_1(trb_address, dsize, &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
   
-  retVal.data.Buffer_val = data;
-  retVal.data.Buffer_len = dsize;
-  
-  status = read_uid_1(trb_address, dsize, &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
+    if (retVal.status.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
   copyStatus(&retVal.status);
   return retVal.status.retVal;
@@ -209,18 +227,21 @@ int trb_register_write(uint16_t trb_address,
   Status retVal;
 
   if (trb_client == NULL) return -1;
-
-  status = register_write_1(trb_address, reg_address, value,
-                            &retVal, trb_client);
+  do {
+    status = register_write_1(trb_address, reg_address, value,
+                              &retVal, trb_client);
     
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
   copyStatus(&retVal);
   return retVal.retVal;
@@ -237,21 +258,24 @@ int trb_register_write_mem(uint16_t trb_address,
   Buffer buffer;
     
   if (trb_client == NULL) return -1;
+  do {
+    buffer.Buffer_val = (uint32_t*)data;
+    buffer.Buffer_len = size;
   
-  buffer.Buffer_val = (uint32_t*)data;
-  buffer.Buffer_len = size;
-  
-  status = register_write_mem_1(trb_address, reg_address, option, buffer,
-                                &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
+    status = register_write_mem_1(trb_address, reg_address, option, buffer,
+                                  &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
 
   copyStatus(&retVal);
   return retVal.retVal;
@@ -265,18 +289,21 @@ int trb_set_address(uint64_t uid,
   Status retVal;
   
   if (trb_client == NULL) return -1;
-
-  status = set_address_1(uid, endpoint, trb_address,
-                         &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
+  do {
+    status = set_address_1(uid, endpoint, trb_address,
+                           &retVal, trb_client);
+  
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
   copyStatus(&retVal);
   return retVal.retVal;
@@ -294,22 +321,25 @@ int trb_ipu_data_read(uint8_t type,
   RetVal retVal;
   
   if (trb_client == NULL) return -1;
+  do {
+    retVal.data.Buffer_val = data;
+    retVal.data.Buffer_len = dsize;
   
-  retVal.data.Buffer_val = data;
-  retVal.data.Buffer_len = dsize;
-  
-  status =
-    ipu_data_read_1(type, trg_info, trg_random, trg_number, dsize,
-                    &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
+    status =
+      ipu_data_read_1(type, trg_info, trg_random, trg_number, dsize,
+                      &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.status.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
 
   copyStatus(&retVal.status);
   return retVal.status.retVal;
@@ -324,17 +354,20 @@ int trb_send_trigger(uint8_t type,
   Status retVal;
   
   if (trb_client == NULL) return -1;
-  
-  status = send_trigger_1(type, info, random, number, &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
+  do {
+    status = send_trigger_1(type, info, random, number, &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
   copyStatus(&retVal);
   return retVal.retVal; 
@@ -350,19 +383,22 @@ int trb_send_trigger_rich(uint8_t input,
   Status retVal;
   
   if (trb_client == NULL) return -1;
+  do {
+    status = send_trigger_rich_1(input, type, info, random, number,
+                                 &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
-  status = send_trigger_rich_1(input, type, info, random, number,
-                               &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
-
   copyStatus(&retVal);
   return retVal.retVal; 
 }
@@ -373,21 +409,24 @@ int fpga_register_read(uint32_t reg_address, uint32_t* value)
   RetVal retVal;
   
   if (trb_client == NULL) return -1;
+  do {
+    retVal.data.Buffer_val = value;
+    retVal.data.Buffer_len = 1;
 
-  retVal.data.Buffer_val = value;
-  retVal.data.Buffer_len = 1;
-
-  status = fpga_register_read_1(reg_address,
-                                &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
+    status = fpga_register_read_1(reg_address,
+                                  &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.status.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
   copyStatus(&retVal.status);
   return retVal.status.retVal;
@@ -399,18 +438,21 @@ int fpga_register_write(uint32_t reg_address, uint32_t value)
   Status retVal;
   
   if (trb_client == NULL) return -1;
+  do {
+    status = fpga_register_write_1(reg_address, value, &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
-  status = fpga_register_write_1(reg_address, value, &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
-
   copyStatus(&retVal);
   return retVal.retVal; 
 }
@@ -421,18 +463,21 @@ int trb_fifo_flush(uint8_t channel)
   Status retVal;
   
   if (trb_client == NULL) return -1;
+  do {
+    status = trb_fifo_flush_1(channel, &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
-  status = trb_fifo_flush_1(channel, &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
-
   copyStatus(&retVal);
   return retVal.retVal;
 }
@@ -443,18 +488,21 @@ int network_reset()
   Status retVal;
   
   if (trb_client == NULL) return -1;
-
-  status = network_reset_1(&retVal, trb_client);
+  do {
+    status = network_reset_1(&retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
-
   copyStatus(&retVal);
   return retVal.retVal;
 }
@@ -474,19 +522,22 @@ int trb_register_modify(uint16_t trb_address,
   Status retVal;
   
   if (trb_client == NULL) return -1;
-  
-  status =
-    register_modify_1(trb_address, reg_address, mode, bitMask, bitValue, 
-                      &retVal, trb_client);
-  
-  if (status != RPC_SUCCESS) {
-    /*
-     * An error occurred while calling the server.
-     * Print error message and stop.
-     */
-    trb_errno = status + 256;
-    return -1;
-  }
+  do { 
+    status =
+      register_modify_1(trb_address, reg_address, mode, bitMask, bitValue, 
+                        &retVal, trb_client);
+    
+    if (status != RPC_SUCCESS) {
+      /*
+       * An error occurred while calling the server.
+       * Print error message and stop.
+       */
+      trb_errno = status + 256;
+      return -1;
+    }
+    if (retVal.retVal != -128) break;
+    sleep(SLEEP_TIME);
+  } while (1);
   
   copyStatus(&retVal);
   return retVal.retVal;