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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
   int test = 1;
   int my_error = 0;
   cl_raw_list_t* list = NULL;
   cl_raw_list_t* log_list = NULL;

   my_error = cl_log_list_setup(&log_list, "test_dummy", 0, CL_LOG_FLUSHED , NULL);
   printf("log list setup: %s\n", cl_get_error_text(my_error));
   cl_log_list_set_log_level(log_list,CL_LOG_DEBUG);
   
   cl_raw_list_setup(&list, "dummy_list",1);
   cl_raw_list_append_elem( list , (void*) &test);
   printf("list entries: %ld\n", cl_raw_list_get_elem_count(list));
   
   my_error = CL_LOG(CL_LOG_INFO,"hallo");
   printf("log: %s\n", cl_get_error_text(my_error));

   printf("log list entries: %ld\n", cl_raw_list_get_elem_count(log_list));

   cl_raw_list_remove_elem( list , cl_raw_list_search_elem( list, (void*) &test) );

   printf("list entries: %ld\n", cl_raw_list_get_elem_count(list));
   my_error = cl_raw_list_cleanup(&list);
   if ( my_error != CL_RETVAL_OK) {
      printf("error cl_raw_list_cleanup() -> %s\n", cl_get_error_text(my_error));
      exit(1);
   }
   
   while (argc>1) {
      dummy(argv[argc-1]);
      argc--;
   }
   
   cl_log_list_cleanup(&log_list);
   return 0;
}
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;
}
Ejemplo n.º 7
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;
}