コード例 #1
0
int
ACE_TS_Clerk_Processor::fini (void)
{
  ACE_TRACE ("ACE_TS_Clerk_Processor::fini");

  // Cancel the timer
  if (this->timer_id_ != -1)
    ACE_Reactor::instance ()->cancel_timer (this->timer_id_);

  // Destroy all the handlers
  ACE_TS_Clerk_Handler **handler = 0;

  for (HANDLER_SET_ITERATOR set_iterator (this->handler_set_);
       set_iterator.next (handler) != 0;
       set_iterator.advance ())
    {
      if ((*handler)->state () != ACE_TS_Clerk_Handler::IDLE)
        // Mark state as DISCONNECTING so we don't try to reconnect...
        (*handler)->state (ACE_TS_Clerk_Handler::DISCONNECTING);

      // Deallocate resources.
      (*handler)->destroy (); // Will trigger a delete
    }

  // Remove the backing store
  this->shmem_->remove ();

  ACE_Connector <ACE_TS_Clerk_Handler, ACE_SOCK_CONNECTOR>::fini ();

  return 0;
}
コード例 #2
0
ファイル: Client_Test.cpp プロジェクト: azraelly/knetwork
int
Client_Test::list_type_entries (const char *pattern)
{
  ACE_BINDING_SET set;

  if (NAMING_CONTEXT ()->list_type_entries (set, pattern) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p Pattern matching failed!\n",
                       "Client_Test::list_types"),
                      0);
  else
    {
      ACE_BINDING_ITERATOR set_iterator (set);

      for (ACE_Name_Binding *entry = 0;
           set_iterator.next (entry) !=0;
           set_iterator.advance())
        {
          ACE_DEBUG ((LM_DEBUG,
                      "%s\t",
                      entry->name_.char_rep ()));
          ACE_DEBUG ((LM_DEBUG,
                      "%s\t",
                      entry->value_.char_rep ()));
          ACE_DEBUG ((LM_DEBUG,
                      "%s\n",
                      entry->type_));
        }
    }
  return 0;
}
コード例 #3
0
ファイル: etch_plain_mailbox.c プロジェクト: OBIGOGIT/etch
/**
 * etchmbox_contains_message() 
 * determines if the mailbox contains a message with the same memory address
 * as the specified message.   
 * @return TRUE or FALSE.   
 */
int etchmbox_contains_message(etch_plainmailbox* thisx, etch_message* thismsg)
{
    int result = FALSE, entrycount = 0;

    if (0 == etchqueue_lock(thisx->queue)) 
    {
        entrycount = thisx && thisx->queue? etch_apr_queue_size(thisx->queue->aprq): 0;

        if (entrycount) 
        {
            etch_iterator iterator;
            set_iterator(&iterator, thisx->queue, &thisx->queue->iterable);

            while(iterator.has_next(&iterator))
            {
                etch_mailbox_element* content = (etch_mailbox_element*) iterator.current_value;

                if (content && content->msg && content->msg == thismsg)  
                {   result = TRUE;
                    break;
                }               
                
                iterator.next(&iterator);
            }  
        }

        etchqueue_unlock(thisx->queue);
    } 

    return result;
}
コード例 #4
0
ファイル: Temperature_Grapher.cpp プロジェクト: asdlei00/ACE
// Listing 2 code/ch21
void Temperature_Grapher::update_graph (void)
{
  Name_Binding_Ptr lastUpdate
    (this->naming_context_.fetch ("lastUpdate"));

  if (!lastUpdate.get ())
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("No data to graph\n")));
      return;
    }
  // Listing 2

  // Listing 3 code/ch21
  Name_Binding_Ptr lastGraphed
    (this->naming_context_.fetch ("lastGraphed"));

  if (lastGraphed.get () &&
      lastGraphed->int_value () == lastUpdate->int_value ())
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Data already graphed\n")));
      return;
    }
  // Listing 3

  // Listing 4 code/ch21
  ACE_BINDING_SET set;
  if (this->naming_context_.list_name_entries
        (set, "history[") != 0)
    {
      ACE_DEBUG ((LM_INFO,
                  ACE_TEXT ("There's nothing to graph\n")));
      return;
    }
  // Listing 4

  // Listing 5 code/ch21
  Graphable_Element_List graphable;
  ACE_BINDING_ITERATOR set_iterator (set);
  for (ACE_Name_Binding *entry = 0;
       set_iterator.next (entry) != 0;
       set_iterator.advance ())
    {
      Name_Binding binding (entry);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\t%s\t%s\n"),
                  binding.type (),
                  binding.name (),
                  binding.value ()));

      Graphable_Element *ge = new Graphable_Element (entry);
      graphable.push_back (*ge);
    }
  // Listing 5

  // Listing 6 code/ch21
  Graph g;
  g.graph (lastUpdate->value (), graphable);
  this->naming_context_.rebind ("lastGraphed",
                                lastUpdate->int_value ());
  // Listing 6
}
コード例 #5
0
ファイル: etch_type.c プロジェクト: OBIGOGIT/etch
/* 
 * etchtype_set_validators_iterator()
 * initialize iterator over validators.
 */
int etchtype_set_validators_iterator(etch_type* type, etch_iterator* iterator)
{
    etch_hashtable* map = NULL;
    etch_type_impl* impl = (etch_type_impl*) type->impl;
    if (impl) map = impl->vtormap;
    return map? set_iterator(iterator, map, &map->iterable): -1;
}
コード例 #6
0
ファイル: Name_Handler.cpp プロジェクト: binghuo365/BaseLab
int
ACE_Name_Handler::lists (void)
{
  ACE_TRACE (ACE_TEXT ("ACE_Name_Handler::lists"));

  ACE_PWSTRING_SET set;
  ACE_NS_WString pattern (this->name_request_.name (),
                          this->name_request_.name_len () / sizeof (ACE_WCHAR_T));

  // Get the index into the list table
  int index = ACE_LIST_MAP (this->name_request_.msg_type (),
                            ACE_Name_Request::LIST_OP_MASK);

  // Print the message type
  ACE_DEBUG ((LM_DEBUG, list_table_[index].description_));

  // Call the appropriate method
  if ((this->naming_context ()->*list_table_[index].operation_) (set, pattern) != 0)
    {
      // None found so send blank request back
      ACE_Name_Request end_rq (ACE_Name_Request::MAX_ENUM, 0, 0, 0, 0, 0, 0);

      if (this->send_request (end_rq) == -1)
        return -1;
    }
  else
    {
      ACE_NS_WString *one_entry = 0;

      for (ACE_Unbounded_Set_Iterator<ACE_NS_WString> set_iterator (set);
           set_iterator.next (one_entry) !=0;
           set_iterator.advance())
        {
          ACE_Name_Request nrq ((this->*list_table_[index].request_factory_) (one_entry));

          // Create a request by calling the appropriate method obtained
          // by accessing into the table. Then send the request across.
          if (this->send_request (nrq) == -1)
            return -1;
        }

      // Send last message indicator.
      ACE_Name_Request nrq (ACE_Name_Request::MAX_ENUM,
                            0, 0,
                            0, 0,
                            0, 0);
      return this->send_request (nrq);
    }
  return 0;
}
コード例 #7
0
hash_table *HashCreate(size_t size)
{
      size_t i;
      bucket **temp;
      hash_table *result;
      hash_table_iterator *t_it;
      /*off=TRUE; found=FALSE;*/
      
      
      /* default initialization, I think I've to do that by hand in C*/ 
      
      
      result = malloc(sizeof(hash_table));
      if (!result){
        return NULL;
      }
      
      t_it = malloc(sizeof(hash_table_iterator));
      if (!t_it){
        free(result);
        return NULL;
      }
      /* t_b = malloc (sizeof(bucket)); */
/*       if (!t_b){ */
/*           free(t_it); */
/*           free(result); */
/*           return NULL; */
/*       } */
      result->iterator = t_it;
      set_iterator(result,NULL,(size_t)0);
      
      result -> size  = size;
      temp = (bucket * *)malloc(sizeof(bucket *) * size);
      
      if (!temp){
          free(result->iterator);
          free(result);
          return NULL;
      }
      
      for (i=0;i<size;i++)
          temp[i] = NULL;

      result->table = temp;
      result->off = TRUE;
      result->found = FALSE;
      return result;
}
コード例 #8
0
ファイル: hashtable_database.cpp プロジェクト: genjix/fastdb
void hashtable_database_writer::store(const hash_digest& key_hash,
    size_t value_size, write_value_function write)
{
    // Calculate the end of the last record.
    const uint64_t header_size = 24 + buckets_ * 8;
    const uint64_t records_end_offset = header_size + total_records_size_;
    // [ tx hash ]              32
    // [ varuint value size ]
    // [ ... value data ... ]
    // [ next tx in bucket ]    8
    const size_t record_size =
        32 + variable_uint_size(value_size) + value_size + 8;
    // If a record crosses a page boundary then we align it with
    // the beginning of the next page.
    const size_t record_begin =
        align_if_crossing_page(page_size_, records_end_offset, record_size);
    BITCOIN_ASSERT(file_.size() >= record_begin + record_size);
    // We will insert new transactions at the beginning of the bucket's list.
    // I assume that more recent transactions in the blockchain are used
    // more often than older ones.
    // We lookup the existing value in the bucket first.
    const uint64_t bucket_index = remainder(key_hash.data(), buckets_);
    BITCOIN_ASSERT(bucket_index < buckets_);
    const uint64_t previous_bucket_value = read_bucket_value(bucket_index);
    // Now begin writing the record itself.
    uint8_t* entry = file_.data() + record_begin;
    auto serial = make_serializer(entry);
    serial.write_hash(key_hash);
    serial.write_variable_uint(value_size);
    // Call the supplied callback to serialize the data.
    write(serial.iterator());
    serial.set_iterator(serial.iterator() + value_size);
    serial.write_8_bytes(previous_bucket_value);
    BITCOIN_ASSERT(serial.iterator() == entry + record_size);
    // Change file size value at file start.
    // This must be done first so any subsequent writes don't
    // overwrite this record in case of a crash or interruption.
    BITCOIN_ASSERT(record_begin >= header_size);
    const uint64_t alignment_padding =
        record_begin - header_size - total_records_size_;
    BITCOIN_ASSERT(alignment_padding <= page_size_);
    total_records_size_ += record_size + alignment_padding;
    // Now add record to bucket.
    const uint64_t record_begin_offset = record_begin - header_size;
    link_record(bucket_index, record_begin_offset);
}
コード例 #9
0
inline static void skip_empty_slots(hash_table  *table){
    /* assert(table);*/
    /* assert(NULL != it); */
    int tp = table->iterator->it_position;
    bucket *tbucket=NULL;
    
    while(tp < table->size){
        tbucket = (table->table)[tp];
        if (tbucket){
            table->off = FALSE;
            break;
        }
        tp++;
    }
    set_iterator(table,tbucket, tp);
    if (tp >= table->size)
        table->off = TRUE;
}
コード例 #10
0
ファイル: etch_type.c プロジェクト: OBIGOGIT/etch
/**
 * get_idname_by_id()
 * given a hashtable and an id_name "id", return the map's id_name key having that id.
 * note that a non-disposable *reference* is returned, not a copy.
 */
etch_id_name* etchtype_get_key_by_id (etch_hashtable* map, const unsigned id)
{
    etch_iterator iterator;

    hashtable_getlock(map);
    set_iterator(&iterator, map, &map->iterable);
    while(iterator.has_next(&iterator))
    {
        etch_id_name* this_idname = (etch_id_name*) iterator.current_key;
		if (this_idname->id == id) {
			hashtable_rellock(map);
			return this_idname;
		}
        iterator.next(&iterator);
    }
	hashtable_rellock(map);
    return NULL;
}
コード例 #11
0
ファイル: etch_type.c プロジェクト: OBIGOGIT/etch
/**
 * etchtype_get_validator_by_id()
 * caller will want to cast result to etch_validator*.
 * note that the etch_type header can't include etch_validator header,
 * thus the anonymous pointers to etch_validator in these methods.  
 */
etch_object* etchtype_get_validator_by_id (etch_type* type, const unsigned id)
{
    etch_hashtable* map;
    etch_iterator iterator;
    etch_type_impl* impl = (etch_type_impl*) type->impl;
    if (!impl || !id) return NULL;
    map = impl->vtormap;

    set_iterator(&iterator, map, &map->iterable);

    while(iterator.has_next(&iterator))
    {
        etch_field* this_field = (etch_field*) iterator.current_key;
        if (this_field->id == id) 
            return iterator.current_value;
        iterator.next(&iterator);
    }

    return NULL;
}
コード例 #12
0
ファイル: hashtable_database.cpp プロジェクト: genjix/fastdb
const hashtable_database_reader::get_result hashtable_database_reader::get(
    const hash_digest& key_hash) const
{
    uint64_t bucket_index = remainder(key_hash.data(), writer_.buckets());
    BITCOIN_ASSERT(bucket_index < writer_.buckets());
    uint64_t record_offset = read_record_offset(file_.data(), bucket_index);
    const uint64_t header_size = 24 + writer_.buckets() * 8;
    const uint8_t* all_records_begin = file_.data() + header_size;
    const uint8_t* all_records_end =
        all_records_begin + writer_.records_size();
    const uint8_t* record_begin = all_records_begin + record_offset;
    // We don't know the end of a record, so we use the end of all records
    // for the deserializer.
    // We will be jumping around the records since it's a chained
    // list per bucket.
    // Begin iterating the list.
    while (true)
    {
        auto deserial = make_deserializer(record_begin, all_records_end);
        const hash_digest current_hash = deserial.read_hash();
        uint64_t value_size = deserial.read_variable_uint();
        if (current_hash != key_hash)
        {
            // Move to next record in bucket.
            // Skip the transaction data.
            deserial.set_iterator(deserial.iterator() + value_size);
            uint64_t next_record = deserial.read_8_bytes();
            if (next_record == record_doesnt_exist)
                return {nullptr, nullptr};
            record_begin = all_records_begin + next_record;
            continue;
        }
        // We have the record!
        return {deserial.iterator(), deserial.iterator() + value_size};
    }
    BITCOIN_ASSERT_MSG(false, "Broke out of unbreakable loop!");
    return {nullptr, nullptr};
}
コード例 #13
0
ファイル: Client_Test.cpp プロジェクト: azraelly/knetwork
int
Client_Test::list_types (const char *pattern)
{
  ACE_PWSTRING_SET set;

  if (NAMING_CONTEXT ()->list_types (set, pattern) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p Pattern matching failed!\n",
                       "Client_Test::list_types"),
                      0);
  else
    {
      ACE_PWSTRING_ITERATOR set_iterator (set);

      for (ACE_NS_WString *type = 0;
           set_iterator.next (type) !=0;
           set_iterator.advance())
        ACE_DEBUG ((LM_DEBUG,
                    "%s\n",
                    type->char_rep ()));
    }
  return 0;
}
コード例 #14
0
int
ACE_TS_Clerk_Processor::init (int argc, ACE_TCHAR *argv[])
{
  ACE_TRACE ("ACE_TS_Clerk_Processor::init");
  // Use the options hook to parse the command line arguments and set
  // options.
  this->parse_args (argc, argv);

  this->alloc ();

#if !defined (ACE_WIN32)
  // Ignore SIPPIPE so each Output_Channel can handle it.
  ACE_Sig_Action sig ((ACE_SignalHandler) SIG_IGN, SIGPIPE);
  ACE_UNUSED_ARG (sig);
#endif /* ACE_WIN32 */

  ACE_Synch_Options &synch_options = this->blocking_semantics_ == 0
    ? ACE_Synch_Options::asynch : ACE_Synch_Options::synch;

  // Now set up connections to all servers
  ACE_TS_Clerk_Handler **handler = 0;

  for (HANDLER_SET_ITERATOR set_iterator (this->handler_set_);
       set_iterator.next (handler) != 0;
       set_iterator.advance ())
    {
      this->initiate_connection (*handler, synch_options);
    }
  // Now set up timer to receive updates from server
  // set the timer to go off after timeout value
  this->timer_id_ = ACE_Reactor::instance ()->schedule_timer (this,
                                                              0,
                                                              ACE_Time_Value (this->timeout_),
                                                              ACE_Time_Value (this->timeout_));
  return 0;
}
コード例 #15
0
ファイル: Name_Handler.cpp プロジェクト: binghuo365/BaseLab
int
ACE_Name_Handler::lists_entries (void)
{
  ACE_TRACE (ACE_TEXT ("ACE_Name_Handler::lists_entries"));
  ACE_BINDING_SET set;
  ACE_NS_WString pattern (this->name_request_.name (),
                          this->name_request_.name_len () / sizeof (ACE_WCHAR_T));

  int result = -1;

  const ACE_Name_Request::Constants msg_type =
    static_cast<ACE_Name_Request::Constants> (this->name_request_.msg_type ());

  // NOTE:  This multi-branch conditional statement used to be
  // (and should be) a switch statement.  However, it caused
  // Internal compiler error 980331 with egcs 1.1 (2.91.57).
  // So, the pointer-to-member-function temporary has been removed.
  if (msg_type == ACE_Name_Request::LIST_NAME_ENTRIES)
    {
#if 0
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("request for LIST_NAME_ENTRIES\n")));
#endif /* 0 */
      result = this->naming_context ()->
        ACE_Naming_Context::list_name_entries (set, pattern);
    }
  else if (msg_type == ACE_Name_Request::LIST_VALUE_ENTRIES)
    {
#if 0
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("request for LIST_VALUE_ENTRIES\n")));
#endif /* 0 */
      result = this->naming_context ()->
        ACE_Naming_Context::list_value_entries (set, pattern);
    }
  else if (msg_type == ACE_Name_Request::LIST_TYPE_ENTRIES)
    {
#if 0
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("request for LIST_TYPE_ENTRIES\n")));
#endif /* 0 */
      result = this->naming_context ()->
        ACE_Naming_Context::list_type_entries (set, pattern);
    }
  else
    return -1;

  if (result == 0)
    {
      ACE_Name_Binding *one_entry = 0;

      for (ACE_Unbounded_Set_Iterator<ACE_Name_Binding> set_iterator (set);
           set_iterator.next (one_entry) !=0;
           set_iterator.advance())
        {
           ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T>
             name_urep (one_entry->name_.rep ());
           ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T>
             value_urep (one_entry->value_.rep ());
           ACE_Name_Request mynrq (this->name_request_.msg_type (),
                                  name_urep.get (),
                                  one_entry->name_.length () * sizeof (ACE_WCHAR_T),
                                  value_urep.get (),
                                  one_entry->value_.length () * sizeof (ACE_WCHAR_T),
                                  one_entry->type_,
                                  ACE_OS::strlen (one_entry->type_));

          if (this->send_request (mynrq) == -1)
            return -1;
        }

      // send last message indicator
      ACE_Name_Request nrq (ACE_Name_Request::MAX_ENUM, 0, 0, 0, 0, 0, 0);

      if (this->send_request (nrq) == -1)
        return -1;
    }
  else
    {
      // None found so send blank request back.
      ACE_Name_Request end_rq (ACE_Name_Request::MAX_ENUM, 0, 0, 0, 0, 0, 0);

      if (this->send_request (end_rq) == -1)
        return -1;
    }

  return 0;
}
コード例 #16
0
ファイル: Volume.hpp プロジェクト: papaver/nkhive
inline typename Volume<T>::set_iterator
Volume<T>::setIterator() const
{
    return set_iterator(this);
}
コード例 #17
0
int
ACE_TS_Clerk_Processor::update_time ()
{
  ACE_TRACE ("ACE_TS_Clerk_Processor::update_time");
  ACE_UINT32 expected_sequence_num = this->cur_sequence_num_;

  // Increment sequence number
  this->cur_sequence_num_++;

  int count = 0;
  time_t total_delta = 0;
  ACE_Time_Info time_info;

  //  Call send_request() on all handlers
  ACE_TS_Clerk_Handler **handler = 0;

  for (HANDLER_SET_ITERATOR set_iterator (this->handler_set_);
       set_iterator.next (handler) != 0;
       set_iterator.advance ())
    {
      if ((*handler)->state () == ACE_TS_Clerk_Handler::ESTABLISHED)
        {
          if ((*handler)->send_request (this->cur_sequence_num_, time_info) == -1)
            return -1;
          // Check if sequence numbers match; otherwise discard
          else if (expected_sequence_num != 0 &&
                   time_info.sequence_num_ == expected_sequence_num)
            {
              count++;
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("[%d] Delta time: %d\n"),
                          count, time_info.delta_time_));

              // #### Can check here if delta value falls within a threshold ####
              total_delta += time_info.delta_time_;
            }
        }
    }
  // Update system_time_ using average of times obtained from all the servers.
  // Note that we are keeping two things in shared memory: the delta
  // time (difference between our system clock and the local clock),
  // and the last local time
  if (count > 0)
    {
      // At least one server is out there
      *(this->system_time_.delta_time_) = total_delta/count;
    }
  else
    {
      // No servers are out there (or this is the first time around
      // computing the time) so set delta time to zero. This
      // would mean that clients would use the actual local system time.
    *(this->system_time_.delta_time_) = 0;
  }
  // Update the last local time
  *(this->system_time_.last_local_time_) = ACE_OS::time (0);

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Average delta time: %d\n"),
              (int)(*(this->system_time_.delta_time_))));
  return 0;
}