Exemplo n.º 1
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;
}
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;
}