Esempio n. 1
0
int cl_host_alias_list_cleanup(cl_raw_list_t** list_p) {
   cl_host_alias_list_elem_t* elem = NULL;
   int ret_val = CL_RETVAL_OK;
   if (list_p == NULL) {
      /* we expect an address of an pointer */
      return CL_RETVAL_PARAMS;
   }
   if (*list_p == NULL) {
      /* we expect an initalized pointer */
      return CL_RETVAL_PARAMS;
   }

   /* delete all entries in list */
   cl_raw_list_lock(*list_p);
   while ( (elem = cl_host_alias_list_get_first_elem(*list_p)) != NULL) {
      cl_raw_list_remove_elem(*list_p, elem->raw_elem);
      sge_free(&(elem->local_resolved_hostname));
      sge_free(&(elem->alias_name));
      sge_free(&elem);
   }
   cl_raw_list_unlock(*list_p);
   ret_val = cl_raw_list_cleanup(list_p);
   CL_LOG(CL_LOG_INFO,"host alias cleanup done");
   return ret_val;
}
Esempio n. 2
0
/*
 *  commlib debug log function callback 
 */
int on_communication_log(cl_raw_list_t* list_p) {
   cl_log_list_elem_t* elem = NULL;

   /* lock the list */
   cl_raw_list_lock(list_p);

   /* print out the complete log list and delete log message */
   while ( (elem = cl_log_list_get_first_elem(list_p) ) != NULL) {
      if (elem->log_parameter == NULL) {
         printf("COMMLIB LOGGING(%s): %s\n", 
                cl_log_list_convert_type_id(elem->log_type),
                elem->log_message);
      } else {
         printf("COMMLIB LOGGING(%s): %s %s\n", 
                cl_log_list_convert_type_id(elem->log_type),
                elem->log_message,
                elem->log_parameter);
      }
      cl_log_list_del_log(list_p);
   }
   
   /* unlock the list */
   cl_raw_list_unlock(list_p);
   return CL_RETVAL_OK;
}
Esempio n. 3
0
int my_log_flush_list(cl_raw_list_t* list_p) {
   int ret_val;
   cl_log_list_elem_t* elem = NULL;
   
   
   if (list_p == NULL) {
      return CL_RETVAL_LOG_NO_LOGLIST;
   }

   if (  ( ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }

   while ( (elem = cl_log_list_get_first_elem(list_p) ) != NULL) {
      char* param;
      if (elem->log_parameter == NULL) {
         param = "";
      } else {
         param = elem->log_parameter;
      }
      printf("%-15s|%-10s|%s%s\n",elem->log_thread_name,cl_log_list_convert_type_id(elem->log_type),elem->log_message,param);
      cl_log_list_del_log(list_p);
   }
   
   if (  ( ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   } 
   return CL_RETVAL_OK;
}
Esempio n. 4
0
int cl_host_list_set_alias_file_dirty(cl_raw_list_t* list_p) {
   int ret_val;
   cl_host_list_data_t* ldata = NULL;

   if (list_p == NULL ) {
      return CL_RETVAL_PARAMS;
   }
   
   /* lock host list */
   ret_val = cl_raw_list_lock(list_p);
   if (ret_val != CL_RETVAL_OK) {
      return ret_val;
   }

   /* list_p should be a hostlist */
   ldata = (cl_host_list_data_t*) list_p->list_data;
   if (ldata != NULL) {
      ldata->alias_file_changed = 1;
   } else {
      cl_raw_list_unlock(list_p);
      return CL_RETVAL_NO_FRAMEWORK_INIT;
   }

   /* unlock host list */
   ret_val = cl_raw_list_unlock(list_p);
   if (ret_val != CL_RETVAL_OK) {
      return ret_val;
   }
   return CL_RETVAL_OK;
}
int cl_endpoint_list_cleanup(cl_raw_list_t** list_p) {
   cl_endpoint_list_data_t* ldata = NULL;
   cl_endpoint_list_elem_t* elem = NULL;
   
   if (list_p == NULL) {
      /* we expect an address of an pointer */
      return CL_RETVAL_PARAMS;
   }

   if (*list_p == NULL) {
      /* we expect an initalized pointer */
      return CL_RETVAL_PARAMS;
   }

   /* delete all entries in list */
   cl_raw_list_lock(*list_p);
   while ( (elem = cl_endpoint_list_get_first_elem(*list_p)) != NULL) {
      cl_raw_list_remove_elem(*list_p, elem->raw_elem);
      cl_com_free_endpoint(&(elem->endpoint));
      sge_free(&elem);
   }
   cl_raw_list_unlock(*list_p);

   /* clean list private data */
   ldata = (*list_p)->list_data;
   if (ldata != NULL) {
      if (ldata->ht != NULL) {
         sge_htable_destroy(ldata->ht);
      }
      sge_free(&ldata);
   }
   (*list_p)->list_data = NULL;

   return cl_raw_list_cleanup(list_p);
}
int cl_endpoint_list_get_autoclose_mode(cl_raw_list_t* list_p, cl_com_endpoint_t* endpoint, cl_xml_connection_autoclose_t* autoclose) {
   int back = CL_RETVAL_UNKNOWN_ENDPOINT;
   int ret_val = CL_RETVAL_OK;
   cl_endpoint_list_elem_t* elem = NULL;
   
   if (list_p == NULL || endpoint == NULL || autoclose == NULL) {
      return CL_RETVAL_PARAMS;
   }

   *autoclose = CL_CM_AC_UNDEFINED;

   /* lock list */
   if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }

   elem = cl_endpoint_list_get_elem_endpoint(list_p, endpoint);
   if (elem != NULL) { 
      /* found matching endpoint */
      back = CL_RETVAL_OK;
      CL_LOG_INT(CL_LOG_INFO,"setting autoclose to:", elem->autoclose);
      *autoclose = elem->autoclose;
   } 

   /* unlock list */
   if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }
   return back;
}
int cl_endpoint_list_get_service_port(cl_raw_list_t* list_p, cl_com_endpoint_t* endpoint, int* service_port) {
   int back = CL_RETVAL_UNKNOWN_ENDPOINT;
   int ret_val = CL_RETVAL_OK;
   cl_endpoint_list_elem_t* elem = NULL;
   
   if (list_p == NULL || endpoint == NULL || service_port == NULL) {
      return CL_RETVAL_PARAMS;
   }

   *service_port = 0;

   /* lock list */
   if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }

   elem = cl_endpoint_list_get_elem_endpoint(list_p, endpoint);
   if (elem != NULL) { 
      /* found matching endpoint */
      back = CL_RETVAL_OK;
      *service_port = elem->service_port;
   } 

   /* unlock list */
   if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }
   return back;
}
Esempio n. 8
0
int cl_fd_list_unregister_fd(cl_raw_list_t* list_p, cl_fd_list_elem_t* elem, int lock_list) {
   int ret_val = CL_RETVAL_OK;

   if (list_p == NULL || elem == NULL) {
      return CL_RETVAL_PARAMS;
   }

   if (lock_list != 0) {
      /* lock list */
      if ((ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }

   cl_raw_list_remove_elem(list_p, elem->raw_elem);
   sge_free(&(elem->data));
   sge_free(&elem);

   if (lock_list != 0) {
      /* unlock list */
      if ((ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   return ret_val;
}
int cl_endpoint_list_undefine_endpoint(cl_raw_list_t* list_p, cl_com_endpoint_t* endpoint) {
   int back = CL_RETVAL_UNKNOWN_ENDPOINT;
   int ret_val = CL_RETVAL_OK;
   cl_endpoint_list_elem_t* elem = NULL;
   
   if (list_p == NULL || endpoint == NULL) {
      return CL_RETVAL_PARAMS;
   }

   /* lock list */
   if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }

   elem = cl_endpoint_list_get_elem_endpoint(list_p, endpoint);
   if (elem && elem->is_static == false) {
      cl_endpoint_list_data_t* ldata = NULL;

      cl_raw_list_remove_elem(list_p, elem->raw_elem);
      cl_com_free_endpoint(&(elem->endpoint));
      sge_free(&elem);

      ldata = list_p->list_data;
      if (ldata->ht != NULL) {
         sge_htable_delete(ldata->ht, endpoint->hash_id);
      }
      back = CL_RETVAL_OK;
   }

   /* unlock list */
   if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }
   return back;
}
int cl_app_message_queue_append(cl_raw_list_t*        list_p,
                                cl_com_connection_t*  rcv_connection,
                                cl_com_endpoint_t*    snd_destination,
                                cl_xml_ack_type_t     snd_ack_type,
                                cl_byte_t*            snd_data,
                                unsigned long         snd_size,
                                unsigned long         snd_response_mid,
                                unsigned long         snd_tag,
                                int                   do_lock) {

   int ret_val;
   cl_app_message_queue_elem_t* new_elem = NULL;

   if (list_p == NULL) {
      return CL_RETVAL_PARAMS;
   }

   /* add new element list */
   new_elem = (cl_app_message_queue_elem_t*) malloc(sizeof(cl_app_message_queue_elem_t));
   if (new_elem == NULL) {
      return CL_RETVAL_MALLOC;
   }

   new_elem->rcv_connection   = rcv_connection;
   new_elem->snd_destination  = snd_destination;
   new_elem->snd_ack_type     = snd_ack_type;
   new_elem->snd_data         = snd_data;
   new_elem->snd_size         = snd_size;
   new_elem->snd_response_mid = snd_response_mid;
   new_elem->snd_tag          = snd_tag;
   new_elem->raw_elem         = NULL;

   /* lock the list */
   if (do_lock != 0) {
      if (  ( ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   
   new_elem->raw_elem = cl_raw_list_append_elem(list_p, (void*) new_elem);
   if ( new_elem->raw_elem == NULL) {
      if (do_lock != 0) {
         cl_raw_list_unlock(list_p);
      }
      sge_free(&new_elem);
      return CL_RETVAL_MALLOC;
   }
   
   /* unlock the thread list */
   if (do_lock != 0) {
      if (  ( ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   return CL_RETVAL_OK;
}
Esempio n. 11
0
int cl_host_list_append_host(cl_raw_list_t* list_p,cl_com_host_spec_t* host, int lock_list ) {

   int ret_val;
   cl_host_list_elem_t* new_elem = NULL;

   if (host == NULL || list_p == NULL) {
      return CL_RETVAL_PARAMS;
   }

   /* lock the list */
   if (lock_list == 1) {
      if (  ( ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }

   /* add new element list */
   new_elem = (cl_host_list_elem_t*) malloc(sizeof(cl_host_list_elem_t));
   if (new_elem == NULL) {
      if (lock_list == 1) {
         cl_raw_list_unlock(list_p);
      }
      return CL_RETVAL_MALLOC;
   }

   new_elem->host_spec = host;
   new_elem->raw_elem = cl_raw_list_append_elem(list_p, (void*) new_elem);
   if ( new_elem->raw_elem == NULL) {
      free(new_elem);
      if (lock_list == 1) { 
         cl_raw_list_unlock(list_p);
      }
      return CL_RETVAL_MALLOC;
   }

   /* add element to hash table */
   if (host->unresolved_name != NULL) {
      cl_host_list_data_t* ldata = list_p->list_data;
      if (ldata->ht != NULL) {
         sge_htable_store(ldata->ht, host->unresolved_name, new_elem);
      }
   }
   
   /* unlock the thread list */
   if (lock_list == 1) {
      if (  ( ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   return CL_RETVAL_OK;
}
Esempio n. 12
0
int cl_fd_list_register_fd(cl_raw_list_t* list_p, cl_com_fd_data_t* fd, int lock_list) {
   
   int ret_val;
   cl_fd_list_elem_t* new_elem = NULL;

   if (fd == NULL || list_p == NULL) {
      return CL_RETVAL_PARAMS;
   }

   /* lock the list */
   if (lock_list == 1) {
      if ((ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }

   /* add a new elemt to the list */
   new_elem = (cl_fd_list_elem_t*) malloc(sizeof(cl_fd_list_elem_t));
   if (new_elem == NULL) {
      if (lock_list == 1) {
         cl_raw_list_unlock(list_p);
      }
      return CL_RETVAL_MALLOC;
   }

   new_elem->data = fd;
   new_elem->raw_elem = cl_raw_list_append_elem(list_p, (void*) new_elem);
   if (new_elem->raw_elem == NULL) {
      sge_free(&new_elem);
      if (lock_list == 1) {
         cl_raw_list_unlock(list_p);
      }
      return CL_RETVAL_MALLOC;
   }

   /* unlock the list */
   if (lock_list == 1) {
      if ((ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   return CL_RETVAL_OK;
}
int cl_app_message_queue_remove(cl_raw_list_t* list_p, cl_com_connection_t* connection, int do_lock, cl_bool_t remove_all_elements ) {
   int function_return = CL_RETVAL_CONNECTION_NOT_FOUND;
   int ret_val = CL_RETVAL_OK;
   cl_app_message_queue_elem_t* elem = NULL;
   cl_app_message_queue_elem_t* next_elem = NULL;


   if (list_p == NULL || connection == NULL) {
      return CL_RETVAL_PARAMS;
   }

   /* lock list */
   if (do_lock != 0) {
      if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }

   elem = cl_app_message_queue_get_first_elem(list_p);
   while ( elem != NULL) { 
      next_elem = cl_app_message_queue_get_next_elem(elem);
      if (elem->rcv_connection == connection) {
         /* found matching element */
         cl_raw_list_remove_elem(list_p, elem->raw_elem);
         sge_free(&elem);
         function_return = CL_RETVAL_OK;
         if (remove_all_elements == CL_FALSE) {
             break; /* break here, we don't want to remove all elems */
         }
      }
      elem = next_elem;
   } 


   /* unlock the thread list */
   if (do_lock != 0) {
      if (  ( ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }

   return function_return;
}
int cl_message_list_append_message(cl_raw_list_t* list_p, cl_com_message_t* message, int lock_list) {  /* CR check */

   int ret_val;
   cl_message_list_elem_t* new_elem = NULL;

   if (message == NULL || list_p == NULL) {
      return CL_RETVAL_PARAMS;
   }

   /* add new element list */
   new_elem = (cl_message_list_elem_t*) malloc(sizeof(cl_message_list_elem_t));
   if (new_elem == NULL) {
      return CL_RETVAL_MALLOC;
   }
   new_elem->message = message;

   /* lock the list */
   if (lock_list == 1) {
      if (  ( ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
         sge_free(&new_elem);
         return ret_val;
      }
   }

   new_elem->raw_elem = cl_raw_list_append_elem(list_p, (void*) new_elem);
   if ( new_elem->raw_elem == NULL) {
      sge_free(&new_elem);
      if (lock_list == 1) { 
         cl_raw_list_unlock(list_p);
      }
      return CL_RETVAL_MALLOC;
   }

   gettimeofday(&(message->message_insert_time),NULL);

   /* unlock the thread list */
   if (lock_list == 1) {
      if (  ( ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   return CL_RETVAL_OK;
}
Esempio n. 15
0
int cl_host_list_remove_host(cl_raw_list_t* list_p, cl_com_host_spec_t* host, int lock_list) {
   int ret_val = CL_RETVAL_OK;
   int function_return = CL_RETVAL_UNKOWN_HOST_ERROR;
   cl_host_list_elem_t* elem = NULL;
   
   if (list_p == NULL || host == NULL) {
      return CL_RETVAL_PARAMS;
   }

   if (lock_list != 0) {   
      /* lock list */
      if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }

    elem = cl_host_list_get_elem_host(list_p, host->unresolved_name);
    if (elem != NULL) {

         /* remove element from hash table */
         if (host->unresolved_name != NULL) {
            cl_host_list_data_t* ldata = list_p->list_data;
            if (ldata->ht != NULL) {
               sge_htable_delete(ldata->ht, host->unresolved_name);
            }
         }
   
         cl_raw_list_remove_elem(list_p, elem->raw_elem);
         function_return = CL_RETVAL_OK;
         cl_com_free_hostspec(&(elem->host_spec));
         free(elem);
    }

   if (lock_list != 0) {
      /* unlock list */
      if ((ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   return function_return;
}
Esempio n. 16
0
int cl_host_list_set_alias_file(cl_raw_list_t* list_p, const char *host_alias_file) {
   int ret_val;
   cl_host_list_data_t* ldata = NULL;

   if (list_p == NULL || host_alias_file == NULL) {
      return CL_RETVAL_PARAMS;
   }
   
   /* lock host list */
   ret_val = cl_raw_list_lock(list_p);
   if (ret_val != CL_RETVAL_OK) {
      return ret_val;
   }

   /* list_p should be a hostlist */
   ldata = (cl_host_list_data_t*) list_p->list_data;
   if (ldata != NULL) {
      if (ldata->host_alias_file != NULL) {
         free(ldata->host_alias_file);
         ldata->host_alias_file = NULL;
      }
      ldata->host_alias_file = strdup(host_alias_file);
      CL_LOG_STR(CL_LOG_INFO,"using host alias file:",ldata->host_alias_file);
      ldata->alias_file_changed = 1;
      if (ldata->host_alias_file == NULL) {
         cl_raw_list_unlock(list_p);
         return CL_RETVAL_MALLOC;
      }
   } else {
      cl_raw_list_unlock(list_p);
      return CL_RETVAL_NO_FRAMEWORK_INIT;
   }

   /* unlock host list */
   ret_val = cl_raw_list_unlock(list_p);
   if (ret_val != CL_RETVAL_OK) {
      return ret_val;
   }
   return CL_RETVAL_OK;
}
int cl_endpoint_list_get_last_touch_time(cl_raw_list_t* list_p, cl_com_endpoint_t* endpoint, unsigned long* touch_time) {

   int back                      = CL_RETVAL_UNKNOWN_ENDPOINT;
   int ret_val                   = CL_RETVAL_OK;
   cl_endpoint_list_elem_t* elem = NULL;
   

   if (list_p == NULL || endpoint == NULL) {
      return CL_RETVAL_PARAMS;
   }

   /* set time to 0 if endpoint not found, otherwise return last communication time */
   /* otherwise return error */
   if (touch_time) {
      *touch_time = 0;
   }

   /* lock list */
   if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }

   elem = cl_endpoint_list_get_elem_endpoint(list_p, endpoint);
   if (elem != NULL) { 
      /* found matching endpoint */
      back = CL_RETVAL_OK;
      CL_LOG_STR(CL_LOG_INFO,"found endpoint comp_host:", elem->endpoint->comp_host);
      if (touch_time) {
         *touch_time = elem->last_used;
      }
   } 

   /* unlock list */
   if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }
   return back;

}
Esempio n. 18
0
int cl_host_alias_list_remove_host(cl_raw_list_t* list_p, cl_host_alias_list_elem_t* element, int lock_list) {
   cl_host_alias_list_elem_t* elem = NULL;
   int ret_val = CL_RETVAL_OK;
   int function_return = CL_RETVAL_UNKNOWN;

   if (  list_p == NULL || element == NULL) {
      return CL_RETVAL_PARAMS;
   }

   if (lock_list != 0) {   
      /* lock list */
      if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   
   elem = cl_host_alias_list_get_first_elem(list_p);
   while ( elem != NULL) { 
      if (elem == element) {
         /* found matching element */
         cl_raw_list_remove_elem(list_p, elem->raw_elem);
         function_return = CL_RETVAL_OK;
         sge_free(&(elem->local_resolved_hostname));
         sge_free(&(elem->alias_name));
         sge_free(&elem);
         elem = NULL;
         break;
      }
      elem = cl_host_alias_list_get_next_elem(elem);
   }

   if (lock_list != 0) {
      /* unlock list */
      if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   return function_return;
}
int cl_message_list_remove_message(cl_raw_list_t* list_p, cl_com_message_t* message, int lock_list) {  /*CR check */
   int function_return = CL_RETVAL_CONNECTION_NOT_FOUND;
   int ret_val = CL_RETVAL_OK;
   cl_message_list_elem_t* elem = NULL;
   
   if (list_p == NULL || message == NULL) {
      return CL_RETVAL_PARAMS;
   }

   if (lock_list != 0) {   
      /* lock list */
      if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }

   elem = cl_message_list_get_first_elem(list_p);
   while ( elem != NULL) { 
      if (elem->message == message) {
         /* found matching element */
         gettimeofday(&(message->message_remove_time),NULL);

         function_return = CL_RETVAL_OK;
         cl_raw_list_remove_elem(list_p, elem->raw_elem);
         sge_free(&elem);
         break;
      }
      elem = cl_message_list_get_next_elem(elem);
   } 

   if (lock_list != 0) {
      /* unlock list */
      if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   return function_return;
}
Esempio n. 20
0
int cl_host_alias_list_get_local_resolved_name(cl_raw_list_t* list_p, char* alias_name,char** local_resolved_name ) {
   cl_host_alias_list_elem_t* elem = NULL;
   int ret_val;
   if   (list_p == NULL || alias_name == NULL || local_resolved_name == NULL)  {
      return CL_RETVAL_PARAMS;
   }
   if (*local_resolved_name != NULL) {
      CL_LOG(CL_LOG_ERROR,"need empty pointer pointer");
      return CL_RETVAL_PARAMS;
   }
   
   if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }


   elem = cl_host_alias_list_get_first_elem(list_p);
   while ( elem != NULL) { 
      if ( strcasecmp(alias_name,elem->alias_name) == 0) {
         *local_resolved_name = strdup(elem->local_resolved_hostname);
         if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
            sge_free(local_resolved_name);
            return ret_val;
         }
         if (*local_resolved_name == NULL) {
            return CL_RETVAL_MALLOC;
         }
         return CL_RETVAL_OK;
      }
      elem = cl_host_alias_list_get_next_elem(elem);
   }
   
   if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }
   return CL_RETVAL_UNKNOWN;
}
Esempio n. 21
0
void *my_thread(void *t_conf) {
   cl_thread_settings_t* thread_p = NULL;
   int counter = 0;
   int do_exit = 0;
   /* get pointer to cl_thread_settings_t struct */
   cl_thread_settings_t *thread_config = (cl_thread_settings_t*)t_conf; 

   /* setup thread */
   printf("thread %d: initialize\n", thread_config->thread_id);



   /* thread init done, trigger startup conditon variable*/
   cl_thread_func_startup(thread_config);


   printf("thread %d: enter mainloop\n", thread_config->thread_id);

   /* ok, thread main */
   while (do_exit == 0) {
      int ret_val;

      printf("thread %d: try locking thread_list ...\n", thread_config->thread_id);
 
      /* check for cancel */
      cl_thread_func_testcancel(thread_config);
      if (cl_raw_list_lock(thread_list) == CL_RETVAL_OK) {
         int id;
         printf("thread %d: locked thread_list\n", thread_config->thread_id);

         if (thread_config->thread_id == 1) {
            thread_p = cl_thread_list_get_thread_by_id(thread_list,2);
            id = 2;
         } else {
            thread_p = cl_thread_list_get_thread_by_id(thread_list,1);
            id = 1;
         }
         if (thread_p) {
            if (thread_config->thread_id == 1) {
               cl_thread_trigger_event(thread_p);
               counter++;
               printf("thread %d: triggered %d events\n", thread_config->thread_id, counter); 
            }
         } else {
            printf("thread %d: thread %d not found\n", thread_config->thread_id,id);
         }
         printf("thread %d: unlocking thread_list\n", thread_config->thread_id);

         cl_raw_list_unlock(thread_list);
      }

      if ((ret_val = cl_thread_wait_for_event(thread_config,0,10000)) != CL_RETVAL_OK) {  /* nothing to do */
         switch(ret_val) {
            case CL_RETVAL_CONDITION_WAIT_TIMEOUT:
/*               printf("thread %d: got timeout\n", thread_config->thread_id);  */
               break;
            default: {
               printf("thread %d: got error: %d\n", thread_config->thread_id, ret_val);
               do_exit = 1;
            }
         }
      }
   }

   printf("thread %d: exit\n", thread_config->thread_id);
   
   /* at least set exit state */
   cl_thread_func_cleanup(thread_config);  
   return(NULL);
}
Esempio n. 22
0
int cl_host_list_copy(cl_raw_list_t** destination, cl_raw_list_t* source, cl_bool_t create_hash) {
   int ret_val = CL_RETVAL_OK;
   cl_host_list_data_t* ldata_source = NULL;
   cl_host_list_data_t* ldata_dest = NULL;
   cl_host_alias_list_elem_t* alias_elem = NULL;
   cl_host_list_elem_t* host_elem = NULL;

   if (source == NULL) {
      return CL_RETVAL_PARAMS;
   }  

   ret_val = cl_raw_list_lock(source);
   if (ret_val != CL_RETVAL_OK) {
      return ret_val;
   }

   /* create a new host list */
   ldata_source = (cl_host_list_data_t*) source->list_data;
   if (ldata_source != NULL) {
      ret_val = cl_host_list_setup(destination, 
                                   source->list_name,
                                   ldata_source->resolve_method,
                                   ldata_source->host_alias_file,
                                   ldata_source->local_domain_name,
                                   ldata_source->entry_life_time,
                                   ldata_source->entry_update_time,
                                   ldata_source->entry_reresolve_time,
                                   create_hash);
   } else {
      CL_LOG(CL_LOG_ERROR,"not list data specified");
      ret_val = CL_RETVAL_UNKNOWN;
   }

   if (ret_val != CL_RETVAL_OK) {
      cl_raw_list_unlock(source);
      cl_host_list_cleanup(destination);
      return ret_val;
   }

   /* list created, now get private data structures */ 
   ldata_dest = (cl_host_list_data_t*) (*destination)->list_data;

   ldata_dest->alias_file_changed = ldata_source->alias_file_changed;
   ldata_dest->last_refresh_time  = ldata_source->last_refresh_time;

   /* now copy alias list */
   cl_raw_list_lock(ldata_source->host_alias_list);

   alias_elem = cl_host_alias_list_get_first_elem(ldata_source->host_alias_list);
   while(alias_elem) {
      ret_val = cl_host_alias_list_append_host(ldata_dest->host_alias_list, 
                                               alias_elem->local_resolved_hostname,
                                               alias_elem->alias_name, 0);
      if (ret_val != CL_RETVAL_OK) {
         cl_raw_list_unlock(ldata_source->host_alias_list);
         cl_raw_list_unlock(source);
         cl_host_list_cleanup(destination);
         return ret_val;
      }
      alias_elem = cl_host_alias_list_get_next_elem(alias_elem);
   }
   cl_raw_list_unlock(ldata_source->host_alias_list);

   /* ok, now copy the entries */
   host_elem = cl_host_list_get_first_elem(source);
   while(host_elem) {
      cl_com_host_spec_t* new_host_spec = NULL;
      
      new_host_spec = ( cl_com_host_spec_t*) malloc( sizeof(cl_com_host_spec_t) );
      if (new_host_spec == NULL) {
         cl_raw_list_unlock(source);
         cl_host_list_cleanup(destination);
         return CL_RETVAL_MALLOC;
      }

      /* copy host_spec_ type */
      new_host_spec->resolve_error     = host_elem->host_spec->resolve_error;
      new_host_spec->last_resolve_time = host_elem->host_spec->last_resolve_time;
      new_host_spec->creation_time     = host_elem->host_spec->creation_time;
       
      if ( host_elem->host_spec->resolved_name ) {
         new_host_spec->resolved_name = strdup(host_elem->host_spec->resolved_name);
         if ( new_host_spec->resolved_name == NULL) {
            cl_com_free_hostspec(&new_host_spec);
            cl_raw_list_unlock(source);
            cl_host_list_cleanup(destination);
            return CL_RETVAL_MALLOC;
         }
      } else {
         new_host_spec->resolved_name = NULL;
      }

      if ( host_elem->host_spec->unresolved_name ) {
         new_host_spec->unresolved_name = strdup(host_elem->host_spec->unresolved_name);
         if ( new_host_spec->unresolved_name == NULL) {
            cl_com_free_hostspec(&new_host_spec);
            cl_raw_list_unlock(source);
            cl_host_list_cleanup(destination);
            return CL_RETVAL_MALLOC;
         }
      } else {
         new_host_spec->unresolved_name = NULL;
      }

      if ( host_elem->host_spec->in_addr) {
         new_host_spec->in_addr = cl_com_copy_in_addr(host_elem->host_spec->in_addr);
         if ( new_host_spec->in_addr == NULL) {
            cl_com_free_hostspec(&new_host_spec);
            cl_raw_list_unlock(source);
            cl_host_list_cleanup(destination);
            return CL_RETVAL_MALLOC;
         }
      } else {
         new_host_spec->in_addr = NULL;
      }
 
      if ( host_elem->host_spec->hostent) {
         new_host_spec->hostent = cl_com_copy_hostent(host_elem->host_spec->hostent);
         if ( new_host_spec->hostent == NULL) {
            cl_com_free_hostspec(&new_host_spec);
            cl_raw_list_unlock(source);
            cl_host_list_cleanup(destination);
            return CL_RETVAL_MALLOC;
         }
      } else {
         new_host_spec->hostent = NULL;
      }

      cl_host_list_append_host((*destination), new_host_spec, 0);
      host_elem = cl_host_list_get_next_elem(host_elem);
   }
   
   ret_val = cl_raw_list_unlock( source );
   return ret_val;
}
int cl_endpoint_list_define_endpoint(cl_raw_list_t* list_p, cl_com_endpoint_t* endpoint, int service_port, cl_xml_connection_autoclose_t autoclose, bool is_static) {

   int ret_val = CL_RETVAL_OK;
   struct timeval now;
   cl_com_endpoint_t* dup_endpoint = NULL;
   cl_endpoint_list_elem_t* new_elem = NULL;
   cl_endpoint_list_elem_t* elem = NULL;

   if (endpoint == NULL || list_p == NULL) {
      return CL_RETVAL_PARAMS;
   }

   /* lock the list and check for duplicate entry */
   if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }

   elem = cl_endpoint_list_get_elem_endpoint(list_p, endpoint);
   if (elem) {
      /* found matching endpoint */
      gettimeofday(&now,NULL);
      elem->last_used = now.tv_sec;
      elem->service_port = service_port;
      elem->autoclose = autoclose;
      if (elem->is_static == true && is_static == false ) {
         CL_LOG(CL_LOG_DEBUG,"can't set static element to non static");
      } else {
         elem->is_static = is_static;
      }
     
      /* unlock the list */
      if ((ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
      return CL_RETVAL_OK;
   }

   /* unlock the list */
   if ((ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }

   /* create a copy of endpoint */
   dup_endpoint = cl_com_dup_endpoint(endpoint);
   if (dup_endpoint == NULL) {
      return CL_RETVAL_MALLOC;
   }

   /* add new element list */
   new_elem = (cl_endpoint_list_elem_t*) malloc(sizeof(cl_endpoint_list_elem_t));
   if (new_elem == NULL) {
      cl_com_free_endpoint(&dup_endpoint);
      return CL_RETVAL_MALLOC;
   }

   gettimeofday(&now,NULL);
   new_elem->endpoint = dup_endpoint;
   new_elem->service_port = service_port;
   new_elem->autoclose = autoclose;
   new_elem->is_static = is_static;
   new_elem->last_used = now.tv_sec;

   /* lock the list */
   if ((ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
      sge_free(&new_elem);
      return ret_val;
   }
   new_elem->raw_elem = cl_raw_list_append_elem(list_p, (void*) new_elem);
   if ( new_elem->raw_elem == NULL) {
      cl_raw_list_unlock(list_p);
      cl_com_free_endpoint(&dup_endpoint);
      sge_free(&new_elem);
      return CL_RETVAL_MALLOC;
   } else {
      cl_endpoint_list_data_t* ldata = list_p->list_data;
      if (ldata->ht != NULL) {
         sge_htable_store(ldata->ht, dup_endpoint->hash_id, new_elem);
      }
   }

   /* unlock the list */
   if ((ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
      return ret_val;
   }

   return CL_RETVAL_OK;
}
Esempio n. 24
0
void *my_test_thread(void *t_conf) {
   cl_thread_settings_t* thread_p = NULL;
   int counter = 0;
   int do_exit = 0;
   /* get pointer to cl_thread_settings_t struct */
   cl_thread_settings_t *thread_config = (cl_thread_settings_t*)t_conf; 

   /* setup thread config ( at least done by call to cl_thread_func_startup() ) */
   if (cl_thread_set_thread_config(thread_config) != CL_RETVAL_OK) {
      printf("cl_thread_set_thread_config() error\n");
   }
   
   CL_LOG( CL_LOG_INFO,   "starting initialization ...");
   /* setup thread  begin */

   /* enter setup code here ... */

   /* setup thread  end */

   /* thread init done, trigger startup conditon variable*/
   cl_thread_func_startup(thread_config);

   CL_LOG( CL_LOG_INFO,  "starting main loop ...");

   /* ok, thread main */
   while (do_exit == 0) {
      int ret_val;

      /* check for cancel */
      cl_thread_func_testcancel(thread_config); 

      CL_LOG( CL_LOG_INFO,  "try to get thread list lock ...");
      if (cl_raw_list_lock(thread_list) == CL_RETVAL_OK) {
         int id;
         CL_LOG( CL_LOG_INFO,  "locked thread list");

         if (thread_config->thread_id == 1) {
            thread_p = cl_thread_list_get_thread_by_id(thread_list,2);
            id = 2;
         } else {
            thread_p = cl_thread_list_get_thread_by_id(thread_list,1);
            id = 1;
         }
         if (thread_p) {
            if (thread_config->thread_id == 1) {
               cl_thread_trigger_event(thread_p);
               counter++;
               CL_LOG_INT( CL_LOG_INFO,  "events triggered: ", counter);
            }
         } else {
            CL_LOG_INT( CL_LOG_INFO,  "can't find thread : ", id);
         }
         CL_LOG( CL_LOG_INFO,  "unlocking thread list ...");
         cl_raw_list_unlock(thread_list);
      }

      /* sleep till event arives */
      if ((ret_val = cl_thread_wait_for_event(thread_config,0,10000)) != CL_RETVAL_OK) {  /* nothing to do */
         switch(ret_val) {
            case CL_RETVAL_CONDITION_WAIT_TIMEOUT:
/*               printf("thread %d: got timeout\n", thread_config->thread_id);  */
               break;
            default: {
               CL_LOG_INT( CL_LOG_INFO,  ">got error<: ", ret_val);
               do_exit = 1;
            }
         }
      }
   }


   /* this only happens on error */
   CL_LOG( CL_LOG_INFO,  "exiting ...");

   /* at least set exit state */
   cl_thread_func_cleanup(thread_config);  
   return(NULL);
}
Esempio n. 25
0
int cl_host_alias_list_append_host(cl_raw_list_t* list_p, char* local_resolved_name, char* alias_name, int lock_list) {

   cl_host_alias_list_elem_t* new_elem = NULL;
   int ret_val;
   char* help = NULL;

   if (list_p == NULL || local_resolved_name == NULL  || alias_name == NULL ) {
      return CL_RETVAL_PARAMS;
   }
 
   if ( cl_host_alias_list_get_alias_name(list_p, local_resolved_name, &help ) == CL_RETVAL_OK) {
      CL_LOG_STR(CL_LOG_ERROR,"alias for host exists already:", help);
      sge_free(&help);
      return CL_RETVAL_ALIAS_EXISTS;
   }

#if 0
   /* CR: 
    *
    * enable this code for 1:1 mapping or for virtual host mapping
    * (e.g. my_virtual_hostname real_host_name in alias file ) 
    *
    * DO NOT FORGET TO ALSO ENABLE CODE IN cl_com_cached_gethostbyname() 
    */

   if ( cl_host_alias_list_get_local_resolved_name(list_p, alias_name, &help ) == CL_RETVAL_OK) {
      CL_LOG_STR(CL_LOG_ERROR,"hostname for alias exists already:", help);
      sge_free(&help);
      return CL_RETVAL_ALIAS_EXISTS;
   }
#endif

   /* lock the list */
   if (lock_list == 1) {
      if (  ( ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
 
   /* add new element list */
   new_elem = (cl_host_alias_list_elem_t*) malloc(sizeof(cl_host_alias_list_elem_t));
   if (new_elem == NULL) {
      if (lock_list == 1) {
         cl_raw_list_unlock(list_p);
      }
      return CL_RETVAL_MALLOC;
   }

   new_elem->local_resolved_hostname = strdup(local_resolved_name);
   if (new_elem->local_resolved_hostname == NULL) {
      sge_free(&new_elem);
      if (lock_list == 1) { 
         cl_raw_list_unlock(list_p);
      }
      return CL_RETVAL_MALLOC;
   }

   new_elem->alias_name = strdup(alias_name);
   if (new_elem->alias_name == NULL) {
      sge_free(&(new_elem->local_resolved_hostname));
      sge_free(&new_elem);
      if (lock_list == 1) { 
         cl_raw_list_unlock(list_p);
      }
      return CL_RETVAL_MALLOC;
   }

   new_elem->raw_elem = cl_raw_list_append_elem(list_p, (void*) new_elem);
   if ( new_elem->raw_elem == NULL) {
      sge_free(&(new_elem->local_resolved_hostname));
      sge_free(&(new_elem->alias_name));
      sge_free(&new_elem);
      if (lock_list == 1) { 
         cl_raw_list_unlock(list_p);
      }
      return CL_RETVAL_MALLOC;
   }

  
   /* unlock the thread list */
   if (lock_list == 1) {
      if (  ( ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
         return ret_val;
      }
   }
   return CL_RETVAL_OK;
}
extern int main(int argc, char** argv)
{
    struct sigaction sa;
    static int runs = 100;


    cl_com_handle_t* handle = NULL;
    cl_com_message_t* message = NULL;
    cl_com_endpoint_t* sender = NULL;

    int bytes_received = 0;
    unsigned long total_bytes_sent = 0;
    unsigned long total_bytes_received = 0;
    unsigned long total_connections = 0;
    unsigned long total_connection_sum = 0;
#if 1
    char* welcome_text = "Welcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\nWelcome to the tcp framework module!Welcome to the tcp framework module!Welcome to the tcp framework module!\n";
#else
    char* welcome_text = "This message is from thread 1";
#endif

    struct timeval now;
    long start_time;
    long appl_start_time;
    long end_time;
    int retval = CL_RETVAL_PARAMS;
    int welcome_text_size;
    int close_connection = 0;
    unsigned long last_mid = 0;
    int i;
    cl_framework_t framework = CL_CT_TCP;
    cl_xml_connection_autoclose_t autoclose;

    /* setup signalhandling */
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = sighandler_client;  /* one handler for all signals */
    sigemptyset(&sa.sa_mask);
    sigaction(SIGINT, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGHUP, &sa, NULL);
    sigaction(SIGPIPE, &sa, NULL);


    if (argc < 7) {
        printf("wrong parameters, param1 = server host, param2 = port number, param3 = client id, param4=debug_level, param5=sleep time, param6=do_close, [param7=framework(TCP/SSL)]\n");
        exit(1);
    }
    prof_mt_init();
    cl_com_setup_commlib(CL_NO_THREAD, (cl_log_t)atoi(argv[4]), NULL);
    if (atoi(argv[6]) != 0) {
        close_connection = 1;
    }
    if (argv[7]) {
        framework = CL_CT_UNDEFINED;
        if (strcmp(argv[7], "TCP") == 0) {
            framework=CL_CT_TCP;
            printf("using TCP framework\n");
        }
        if (strcmp(argv[7], "SSL") == 0) {
            framework=CL_CT_SSL;
            printf("using SSL framework\n");
        }
        if (framework == CL_CT_UNDEFINED) {
            printf("unexpected framework type\n");
            exit(1);
        }
    }

    cl_com_set_alias_file("./alias_file");
    if ( framework == CL_CT_SSL) {
        cl_ssl_setup_t ssl_config;
        ssl_config.ssl_method           = CL_SSL_v23;                 /*  v23 method                                  */
        ssl_config.ssl_CA_cert_pem_file = getenv("SSL_CA_CERT_FILE"); /*  CA certificate file                         */
        ssl_config.ssl_CA_key_pem_file  = NULL;                       /*  private certificate file of CA (not used)   */
        ssl_config.ssl_cert_pem_file    = getenv("SSL_CERT_FILE");    /*  certificates file                           */
        ssl_config.ssl_key_pem_file     = getenv("SSL_KEY_FILE");     /*  key file                                    */
        ssl_config.ssl_rand_file        = getenv("SSL_RAND_FILE");    /*  rand file (if RAND_status() not ok)         */
        ssl_config.ssl_crl_file         = getenv("SSL_CRL_FILE");     /*  revocation list file                        */
        ssl_config.ssl_reconnect_file   = NULL;                       /*  file for reconnect data    (not used)       */
        ssl_config.ssl_refresh_time     = 0;                          /*  key alive time for connections (not used)   */
        ssl_config.ssl_password         = NULL;                       /*  password for encrypted keyfiles (not used)  */
        ssl_config.ssl_verify_func      = NULL;                       /*  function callback for peer user/name check  */

        if (ssl_config.ssl_CA_cert_pem_file == NULL ||
                ssl_config.ssl_cert_pem_file    == NULL ||
                ssl_config.ssl_key_pem_file     == NULL ||
                ssl_config.ssl_rand_file        == NULL) {
            printf("please set the following environment variables:\n");
            printf("SSL_CA_CERT_FILE         = CA certificate file\n");
            printf("SSL_CERT_FILE            = certificates file\n");
            printf("SSL_KEY_FILE             = key file\n");
            printf("(optional) SSL_RAND_FILE = rand file (if RAND_status() not ok)\n");
        }
        cl_com_specify_ssl_configuration(&ssl_config);
    }
    CL_LOG_STR(CL_LOG_INFO,"connection to server on host", argv[1]);
    CL_LOG_INT(CL_LOG_INFO,"using port",atoi(argv[2]));

    CL_LOG_STR(CL_LOG_INFO,"component is","client");
    CL_LOG_INT(CL_LOG_INFO,"id ist",atoi(argv[3]));
#define SELECT_TIMEOUT 1
#if 0
#define CREATE_SERVICE
#endif

#ifdef CREATE_SERVICE
    cl_com_append_known_endpoint_from_name(argv[1], "server", 1,atoi(argv[2]),CL_CM_AC_DISABLED , 1);
    handle=cl_com_create_handle(NULL,framework,CL_CM_CT_MESSAGE , CL_TRUE, 0 , CL_TCP_DEFAULT, "client", atoi(argv[3]),SELECT_TIMEOUT,0 );
    if (handle == NULL) {
        printf("could not get handle\n");
        exit(1);
    } else {
        int my_port;
        cl_com_get_service_port(handle,&my_port);
        printf("I'm reachable at port %d!\n", my_port);
    }
#else
    handle=cl_com_create_handle(NULL,framework,CL_CM_CT_MESSAGE , CL_FALSE, atoi(argv[2]) , CL_TCP_DEFAULT,"client", atoi(argv[3]),SELECT_TIMEOUT,0 );
    if (handle == NULL) {
        printf("could not get handle\n");
        exit(1);
    }
#endif

    cl_com_set_auto_close_mode(handle,CL_CM_AC_ENABLED );
    cl_com_get_auto_close_mode(handle,&autoclose);
    if (autoclose != CL_CM_AC_ENABLED ) {
        printf("could not enable autoclose\n");
        exit(1);
    }

    printf("local hostname is \"%s\"\n", handle->local->comp_host);
    printf("local component is \"%s\"\n", handle->local->comp_name);
    printf("local component id is \"%ld\"\n", handle->local->comp_id);

#ifdef CREATE_SERVICE
    cl_com_get_known_endpoint_port_from_name(argv[1], "server", 1, &i);
    printf("connecting to port \"%d\" on host \"%s\"\n", i, argv[1]);
#else
    cl_com_get_connect_port(handle, &i);
    printf("connecting to port \"%d\" on host \"%s\"\n", i, argv[1]);
#endif


    gettimeofday(&now,NULL);
    start_time =    now.tv_sec;
    appl_start_time = start_time;
    welcome_text_size = strlen(welcome_text) + 1;

    if (getenv("CL_RUNS")) {
        runs = atoi(getenv("CL_RUNS"));
    } else {
        runs = -1;  /* disable runs shutdown */
    }
    while(do_shutdown != 1) {
        unsigned long mid = 0;
        int my_sent_error = 0;

        CL_LOG(CL_LOG_INFO,"main loop");
        if (runs > 0) {
            runs--;
        }

        /* printf("sending to \"%s\" ...\n", argv[1]);  */

        /*     CL_LOG(CL_LOG_ERROR,"sending ack message ..."); */

        my_sent_error = cl_commlib_send_message(handle, argv[1], "server", 1, CL_MIH_MAT_ACK, (cl_byte_t**)&welcome_text , welcome_text_size, &mid ,0,0, CL_TRUE, CL_FALSE);
        if ( retval == CL_RETVAL_CONNECTION_NOT_FOUND ) {
            CL_LOG(CL_LOG_ERROR,"after new connection");
        }

        if (last_mid >= mid || mid == 1) {
            total_connections++;
            total_connection_sum++;
        }
        last_mid = mid;

#if 1
        if (my_sent_error != CL_RETVAL_OK) {
            printf("cl_commlib_send_message() returned %s\n", cl_get_error_text(my_sent_error));
#ifdef CREATE_SERVICE
            cl_com_get_known_endpoint_port_from_name(argv[1], "server", 1, &i);
            printf("connecting to port \"%d\" on host \"%s\"\n", i, argv[1]);
#else
            cl_com_get_connect_port(handle, &i);
            printf("connecting to port \"%d\" on host \"%s\"\n", i, argv[1]);
#endif

            /* exit(1); */
#if CL_DO_SLOW
            sleep(atoi(argv[5]));
#endif
            cl_commlib_trigger(handle,1);
            continue;
        }
#endif
#if 1
        retval = CL_RETVAL_PARAMS;
        while (retval != CL_RETVAL_OK ) {


            while ( (retval=cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender)) == CL_RETVAL_OK) {
                if (message != NULL) {
                    cl_com_free_endpoint(&sender);
                    cl_com_free_message(&message);
                } else {
                    break;
                }
            }

            if ( retval == CL_RETVAL_CONNECTION_NOT_FOUND ) {
                CL_LOG(CL_LOG_ERROR,"connection not found (1)");
                break;
            }

            retval = cl_commlib_check_for_ack(handle, argv[1], "server", 1, mid, CL_TRUE );
            if (retval != CL_RETVAL_MESSAGE_WAIT_FOR_ACK && retval != CL_RETVAL_OK) {
                printf("retval of cl_commlib_check_for_ack(%ld) is %s\n",mid,cl_get_error_text(retval));
                /* exit(1);  */
                break;
            }
            if (retval == CL_RETVAL_OK) {
                CL_LOG_INT(CL_LOG_INFO,"received ack for message mid", (int)mid);
            } else {
                cl_commlib_trigger(handle, 1);
            }

            if ( retval == CL_RETVAL_CONNECTION_NOT_FOUND ) {
                CL_LOG(CL_LOG_ERROR,"connection not found (2)");
                break;
            }



            /*        printf("retval of cl_commlib_check_for_ack(%ld) is %s\n",mid,cl_get_error_text(retval));  */
        }
        if (retval == CL_RETVAL_CONNECTION_NOT_FOUND) {
            cl_commlib_trigger(handle, 1);
            continue;
        }
#endif


        total_bytes_sent  = total_bytes_sent + welcome_text_size;
        CL_LOG_INT(CL_LOG_INFO,"bytes sent:", welcome_text_size);

        bytes_received = 0;
        while (bytes_received != welcome_text_size ) {

            cl_commlib_trigger(handle, 1);


            CL_LOG_INT(CL_LOG_INFO,"waiting for mid .... ", (int)mid);
            retval = cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, mid, &message, &sender);


            CL_LOG_STR(CL_LOG_INFO,"waiting for bytes ...", cl_get_error_text(retval));
            if (retval == CL_RETVAL_CONNECTION_NOT_FOUND) {
#if CL_DO_SLOW
                /*           CL_LOG(CL_LOG_ERROR,"connection not found"); */

                if (atoi(argv[5]) > 0) {
                    printf("sleeping...\n");
                    sleep(atoi(argv[5]));
                }
#endif
                break;
            }
            if (message != NULL) {

                /*   printf("received message from \"%s\"\n", sender->comp_host); */
                CL_LOG_INT(CL_LOG_INFO,"bytes received:", (int)message->message_length);
                if (strcmp((char*)message->message, welcome_text) != 0) {
                    printf("------------------------> message transfer error\n");
                }
                total_bytes_received = total_bytes_received + message->message_length;
                bytes_received = bytes_received + (int)message->message_length;
                cl_com_free_endpoint(&sender);
                cl_com_free_message(&message);
            }

            while ( (retval = cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender)) == CL_RETVAL_OK) {
                if (message != NULL) {
                    cl_com_free_endpoint(&sender);
                    cl_com_free_message(&message);
                } else {
                    break;
                }
            }

            if (retval == CL_RETVAL_CONNECTION_NOT_FOUND) {
                CL_LOG(CL_LOG_ERROR,"connection not found (3)");
                break;

            }


#if CL_DO_SLOW
            sleep(atoi(argv[5]));
#endif
            if (do_shutdown == 1) {
                break;
            }
        }


#if CL_DO_SLOW
        sleep(atoi(argv[5]));
#endif
        gettimeofday(&now,NULL);
        end_time =    now.tv_sec;
        if (end_time - start_time >= 2 ) {
            cl_com_connection_t* con = NULL;
            cl_connection_list_elem_t* elem = NULL;
            /*        printf("Kbit/s sent: %.2f   ", ((total_bytes_sent * 8.0)/1024.0) /  (double)(end_time - start_time));
                    printf("Kbit/s read: %.2f   ", ((total_bytes_received * 8.0)/1024.0) /  (double)(end_time - start_time)); */
            printf("KBit/s     : %.2f   ", (((total_bytes_received + total_bytes_sent) * 8.0)/1024.0) /  (double)(end_time - start_time));
            printf("connections/s: %.2f ", (double) total_connections / (double)(end_time - start_time));
            printf("avg. connections/s: %.2f", (double) total_connection_sum / (double)(end_time - appl_start_time));
            cl_raw_list_lock(handle->connection_list);
            elem = cl_connection_list_get_first_elem(handle->connection_list);
            if (elem != NULL) {
                con = elem->connection;
                if (elem->connection->local) {
                    printf("[for comp host, comp name, comp id: \"%s\", \"%s\", \"%ld\"]    \n",con->local->comp_host, con->local->comp_name , con->local->comp_id);
                }
            } else {
                printf("     \n");
            }
            cl_raw_list_unlock(handle->connection_list);


            start_time =    now.tv_sec;
            total_bytes_sent = 0;
            total_bytes_received = 0;
            total_connections = 0;
            fflush(stdout);
        }
        if (close_connection != 0) {

            while (cl_commlib_shutdown_handle(handle, CL_TRUE) == CL_RETVAL_MESSAGE_IN_BUFFER) {
                printf("got message\n");
                message = NULL;
                cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender);
                if (message != NULL) {
                    cl_com_free_endpoint(&sender);
                    cl_com_free_message(&message);
                } else {
                    printf("error shutdown handle");
                    exit(-1);
                    break;
                }
            }
#ifdef CREATE_SERVICE
            handle=cl_com_create_handle(NULL,framework,CL_CM_CT_MESSAGE , CL_TRUE, 0 , CL_TCP_DEFAULT, "client", atoi(argv[3]),SELECT_TIMEOUT,0 );
            if (handle == NULL) {
                printf("could not get handle\n");
                exit(-1);
            } else {
                int my_port;
                cl_com_get_service_port(handle,&my_port);
                printf("I'm reachable at port %d!\n", my_port);
            }
#else
            handle=cl_com_create_handle(NULL,framework,CL_CM_CT_MESSAGE , CL_FALSE, atoi(argv[2]) , CL_TCP_DEFAULT, "client", atoi(argv[3]), SELECT_TIMEOUT,0 );
            if (handle == NULL) {
                printf("could not get handle\n");
                exit(-1);
            }
#endif
            cl_com_set_auto_close_mode(handle,CL_CM_AC_ENABLED );
            cl_com_get_auto_close_mode(handle,&autoclose);
            if (autoclose != CL_CM_AC_ENABLED ) {
                printf("could not enable autoclose\n");
                exit(1);
            }
        }
        if (runs == 0) {
            do_shutdown = 1;
        }
    }
    printf("do_shutdown received\n");
    fflush(stdout);
    while (cl_commlib_shutdown_handle(handle, CL_TRUE) == CL_RETVAL_MESSAGE_IN_BUFFER) {
        printf("got message\n");
        message = NULL;

        cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender);
        if (message != NULL) {
            cl_com_free_endpoint(&sender);
            cl_com_free_message(&message);
        } else {
            break;
        }
    }
    printf("cleanup commlib ...\n");
    cl_com_cleanup_commlib();

    printf("main done\n");
    fflush(stdout);
    return 0;
}