template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::forward_i (void)
{
  ACE_TRACE ("ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::forward_i");

  if (this->map_man_->table_ == 0)
    return -1;
  // Handle initial case specially.
  else if (this->index_ == -1)
    {
      this->index_++;
      return this->forward_i ();
    }
  else if (this->index_ >= ACE_static_cast (ssize_t, this->map_man_->total_size_))
    return 0;

  this->next_ = this->next_->next_;
  if (this->next_ == &this->map_man_->table_[this->index_])
    {
      while (++this->index_ < ACE_static_cast (ssize_t,
                                               this->map_man_->total_size_))
        {
          this->next_ = this->map_man_->table_[this->index_].next_;
          if (this->next_ != &this->map_man_->table_[this->index_])
            break;
        }
    }

  return this->index_ < ACE_static_cast (ssize_t, this->map_man_->total_size_);
}
// Listing 2 code/ch09
void echo_dgram (void)
{
  ACE_INET_Addr my_addr (ACE_static_cast (u_short, 10102));
  ACE_INET_Addr your_addr;
  ACE_SOCK_Dgram udp (my_addr);
  char buff[BUFSIZ];
  size_t buflen = sizeof (buff);
  ssize_t recv_cnt = udp.recv (buff, buflen, your_addr);
  if (recv_cnt > 0)
    udp.send (buff, ACE_static_cast (size_t, buflen), your_addr);
  udp.close ();
  return;
}
ACE_LPTRANSMIT_FILE_BUFFERS
ACE_Asynch_Transmit_File::Header_And_Trailer::transmit_buffers (void)
{
  // If both are zero, return zero
  if (this->header_ == 0 && this->trailer_ == 0)
    return 0;
  else
    {
      // Something is valid

      // If header is valid, set the fields
      if (this->header_ != 0)
        {
          this->transmit_buffers_.Head = this->header_->rd_ptr ();
#if defined(ACE_WIN64)
          this->transmit_buffers_.HeadLength =
            ACE_static_cast (DWORD, this->header_bytes_);
#else
          this->transmit_buffers_.HeadLength = this->header_bytes_;
#endif /* ACE_WIN64 */
        }
      else
        {
          this->transmit_buffers_.Head = 0;
          this->transmit_buffers_.HeadLength = 0;
        }

      // If trailer is valid, set the fields
      if (this->trailer_ != 0)
        {
          this->transmit_buffers_.Tail = this->trailer_->rd_ptr ();
#if defined(ACE_WIN64)
          this->transmit_buffers_.TailLength =
            ACE_static_cast (DWORD, this->trailer_bytes_);
#else
          this->transmit_buffers_.TailLength = this->trailer_bytes_;
#endif /* ACE_WIN64 */
        }
      else
        {
          this->transmit_buffers_.Tail = 0;
          this->transmit_buffers_.TailLength = 0;
        }

      // Return the transmit buffers
      return &this->transmit_buffers_;
    }
}
int
ACEXML_Transcoder::ucs42utf8 (ACEXML_UCS4 src,
                              ACEXML_UTF8 *dst,
                              size_t len)
{
  if (src < 0x10000)
    {
      int retv = ACEXML_Transcoder::utf162utf8
                 (ACE_static_cast (ACEXML_UTF16, src),
                  dst, len);
      return (retv == ACEXML_IS_SURROGATE ? ACEXML_NON_UNICODE : retv);
    }
  else if (src >= 0x100000 && src < 0x110000)
    {
      if (len < 4)
        return ACEXML_DESTINATION_TOO_SHORT;

      if (dst == 0)
        return ACEXML_INVALID_ARGS;

      *dst = 0xf0 | (src / 0x40000);
      *(dst+1) = 0x80 | ((src % 0x40000) / 0x1000);
      *(dst+2) = 0x80 | ((src % 0x1000) / 0x40);
      *(dst+3) = 0x80 | (src % 0x40);
      return 4;
    }
  return ACEXML_NON_UNICODE;
}
int
ACEXML_Transcoder::ucs42utf16 (ACEXML_UCS4 src,
                               ACEXML_UTF16 *dst,
                               size_t len)
{
  if (dst == 0)
    return ACEXML_INVALID_ARGS;

  if (src < 0x10000)
    {
      if (len < 1)
        return ACEXML_DESTINATION_TOO_SHORT;

      if (src >= 0xD800 && src < 0xE000)
        return ACEXML_NON_UNICODE;     // Surrogates are not valid unicode value

      *dst = ACE_static_cast (ACEXML_UTF16, src);
      return 1;
    }
  else if (src >= 0x100000 && src < 0x110000)
    // Scalar values are encoded into surrogates
    {
      if (len < 2)
        return ACEXML_DESTINATION_TOO_SHORT;

      *dst = 0xD800 | (src / 0x400);
      *(dst+1) = 0xDC00 | (src % 0x400);
      return 2;
    }

  return ACEXML_NON_UNICODE;
}
int
Request_Handler::handle_input (ACE_HANDLE fd)
{
  ACE_TCHAR buffer[BUFSIZ];
  ACE_TCHAR len = 0;
  ssize_t result = this->peer ().recv (&len, sizeof (ACE_TCHAR));

  if (result > 0
      && this->peer ().recv_n (buffer, len * sizeof (ACE_TCHAR))
      == ACE_static_cast (ssize_t, len * sizeof (ACE_TCHAR)))
    {
      ++this->nr_msgs_rcvd_;

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) svr input; fd: 0x%x; input: %s\n"),
                  fd,
                  buffer));
      if (ACE_OS::strcmp (buffer, ACE_TEXT ("shutdown")) == 0)
        ACE_Reactor::end_event_loop ();
      return 0;
    }
  else
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%t) Request_Handler: 0x%x peer closed (0x%x)\n"),
                this, fd));
  return -1;
}
int Service_Reporter::handle_input (ACE_HANDLE) {
  ACE_SOCK_Stream peer_stream;
  acceptor_.accept (peer_stream);

  ACE_Service_Repository_Iterator iterator
    (*ACE_Service_Repository::instance (), 0);

  for (const ACE_Service_Type *st;
       iterator.next (st) != 0;
       iterator.advance ()) {
    iovec iov[3];
    iov[0].iov_base = ACE_const_cast (char *, st->name ());
    iov[0].iov_len =
      ACE_OS::strlen (st->name ()) * sizeof (ACE_TCHAR);
    const ACE_TCHAR *state = st->active () ?
           ACE_TEXT (" (active) ") : ACE_TEXT (" (paused) ");
    iov[1].iov_base = ACE_const_cast (char *, state);
    iov[1].iov_len =
      ACE_OS::strlen (state) * sizeof (ACE_TCHAR);
    ACE_TCHAR *report = 0;   // Ask info() to allocate buffer
    int len = st->type ()->info (&report, 0);
    iov[2].iov_base = ACE_static_cast (char *, report);
    iov[2].iov_len = ACE_static_cast (size_t, len);
    iov[2].iov_len *= sizeof (ACE_TCHAR);
    peer_stream.sendv_n (iov, 3);
    ACE::strdelete (report);
  }

  peer_stream.close ();
  return 0;
}
ACE_UINT32
High_Priority_Synchronized_Task:: average_context_switch_time () const
{
    return iterations_ > 0  ?  ACE_static_cast (ACE_UINT32,
            total_time_ / iterations_)
           : 0;
}
template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::reverse_i (void)
{
  ACE_TRACE ("ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::reverse_i");

  if (this->map_man_->table_ == 0)
    return -1;
  else if (this->index_ == ACE_static_cast (ssize_t, this->map_man_->total_size_))
    {
      this->index_--;
      return this->reverse_i ();
    }
  else if (this->index_ < 0)
    return 0;

  this->next_ = this->next_->prev_;
  if (this->next_ == &this->map_man_->table_[this->index_])
    {
      while (--this->index_ >= 0)
        {
          this->next_ = this->map_man_->table_[this->index_].prev_;
          if (this->next_ != &this->map_man_->table_[this->index_])
            break;
        }
    }

  return this->index_ >= 0;
}
int
ACE_SV_Semaphore_Simple::open (key_t k,
                               int flags,
                               int initial_value,
                               u_short n,
                               int perms)
{
  ACE_TRACE ("ACE_SV_Semaphore_Simple::open");
  union semun ivalue;

  if (k == IPC_PRIVATE || k == ACE_static_cast (key_t, ACE_INVALID_SEM_KEY))
    return -1;

  ivalue.val = initial_value;
  this->key_ = k;
  this->sem_number_ = n;

  this->internal_id_ = ACE_OS::semget (this->key_, n, perms | flags);

  if (this->internal_id_ == -1)
    return -1;

  if (ACE_BIT_ENABLED (flags, IPC_CREAT))
    for (int i = 0; i < n; i++)
      if (ACE_OS::semctl (this->internal_id_, i, SETVAL, ivalue) == -1)
        return -1;

  return 0;
}
Esempio n. 11
0
  int handle_output (ACE_HANDLE handle)
  {
    ACE_DEBUG ((LM_DEBUG, "Different_Handler::handle_output\n"));

    // Add for reading
    int result = ACE_Reactor::instance ()->mask_ops (this,
                                                     ACE_Event_Handler::READ_MASK,
                                                     ACE_Reactor::ADD_MASK);
    ACE_ASSERT (result != -1);

    ACE_Reactor_Mask old_masks =
      ACE_Event_Handler::WRITE_MASK |
      ACE_Event_Handler::EXCEPT_MASK;

    ACE_ASSERT (old_masks ==
                ACE_static_cast (ACE_Reactor_Mask, result));

    // Get new masks
    result = ACE_Reactor::instance ()->mask_ops (this,
                                                 ACE_Event_Handler::NULL_MASK,
                                                 ACE_Reactor::GET_MASK);
    ACE_ASSERT (result != -1);

    ACE_Reactor_Mask current_masks =
      ACE_Event_Handler::READ_MASK |
      ACE_Event_Handler::WRITE_MASK |
      ACE_Event_Handler::EXCEPT_MASK;

    ACE_ASSERT (current_masks ==
                ACE_static_cast (ACE_Reactor_Mask, result));

    // Remove for writing
    ACE_Reactor_Mask mask = ACE_Event_Handler::WRITE_MASK | ACE_Event_Handler::DONT_CALL;
    result = ACE_Reactor::instance ()->remove_handler (this,
                                                       mask);
    ACE_ASSERT (result == 0);

    // Write to the pipe; this causes handle_input to get called.
    if (!write_to_pipe_in_main)
      write_to_pipe (this->pipe_);

    return 0;
  }
Esempio n. 12
0
Tester::Tester (void)
  : seed_ (ACE_static_cast(ACE_RANDR_TYPE,ACE_OS::time (0)))
  , lowest_sequence_number_ (0)
  , next_expected_ (0)
{
  // Initialize the stack...
  this->reordering_.next (this);

  this->proxy_.set_tester (this);
}
Esempio n. 13
0
ACE_MEM_Addr::ACE_MEM_Addr (const ACE_TCHAR port_number[])
  : ACE_Addr (AF_INET, sizeof (ACE_MEM_Addr))
{
  ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
  u_short pn
    = ACE_static_cast (u_short,
                       ACE_OS::strtoul (port_number,
                                        NULL,
                                        10));
  this->initialize_local (pn);
}
Esempio n. 14
0
int
ACE_MEM_Addr::string_to_addr (const ACE_TCHAR s[])
{
  ACE_TRACE ("ACE_MEM_Addr::string_to_addr");

  u_short pn
    = ACE_static_cast (u_short,
                       ACE_OS::strtoul (s,
                                        NULL,
                                        10));
  return this->set (pn);
}
Tester::Tester (void)
    : seed_ (ACE_static_cast(ACE_RANDR_TYPE,ACE_OS::time (0)))
    , sequence_number_generator_ (0)
{
    // Initialize the stack...
    this->retransmission_.next (this);

    for (size_t i = 0; i != nproxy; ++i)
    {
        this->proxy_[i].set_tester (this);
        this->proxy_[i].joined (1);
    }
}
Esempio n. 16
0
void ErrorTraceHelper::toString (ACSErr::ErrorTrace * c, int level, std::ostringstream &oss){

  oss << "Error Trace Level : " << level << std::endl;

  char ctp[21];
  long sec_ =  ACE_static_cast(CORBA::ULongLong, c->timeStamp) / ACE_static_cast(ACE_UINT32, 10000000u) - ACE_UINT64_LITERAL(0x2D8539C80);
  long usec_ = (c->timeStamp % 10000000u) / 10;
  time_t tt(sec_);
  struct tm *utc_p = ACE_OS::gmtime(&tt);
  ACE_OS::strftime(ctp, sizeof(ctp), "%Y-%m-%dT%H:%M:%S.", utc_p);

  oss << "  " << ctp << std::setfill('0') << std::setw(3) << usec_/1000;
  oss << " in " << c->routine << " of file " << c->file <<  " at line " << c->lineNum << std::endl;
  oss << "  HostName:" << c->host << ", process:" << c->process << " Thread " << c->thread << "," << std::endl;
  oss << "  Severity=" << c->severity;
  oss << " type=" << c->errorType << " code=" << c->errorCode << " description:" << c->shortDescription << std::endl;

  for (unsigned int j=0; j<c->data.length(); j++)
      oss << "    data[" << j << "] : " <<  c->data[j].name << " = " << c->data[j].value << std::endl;

  return;
}
int send_unicast (const ACE_INET_Addr &to)
{
  const char *message = "this is the message!\n";
  ACE_INET_Addr my_addr (ACE_static_cast (u_short, 10101));
  ACE_SOCK_Dgram udp (my_addr);
  ssize_t sent = udp.send (message,
                           ACE_OS_String::strlen (message) + 1,
                           to);
  udp.close ();
  if (sent == -1)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
                       ACE_TEXT ("send")), -1);
  return 0;
}
int run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Semaphore_Test"));

#if defined (ACE_HAS_THREADS)
  parse_args (argc, argv);
  ACE_OS::srand (ACE_OS::time (0L));

#  if !defined (ACE_HAS_STHREADS) && !defined (ACE_HAS_POSIX_SEM)
  //Test timed waits.
  for (size_t i = 0; i < test_timeout_count; i++)
    if (test_timeout () != 0)
      test_result = 1;
#  endif /* ACE_HAS_STHREADS && ACE_HAS_POSIX_SEM */

  // Release the semaphore a certain number of times.
  s.release (n_release_count);

  if (ACE_Thread_Manager::instance ()->spawn_n
      (ACE_static_cast (size_t, n_workers),
       ACE_THR_FUNC (worker),
       0,
       THR_NEW_LWP) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("spawn_n")),
                      1);

  ACE_Thread_Manager::instance ()->wait ();

#  if !defined (ACE_HAS_STHREADS) && !defined (ACE_HAS_POSIX_SEM)
  size_t percent = (timeouts * 100) / (n_workers * n_iterations);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Worker threads timed out %d percent of the time\n"),
              percent));
#  endif /* ACE_HAS_STHREADS && ACE_HAS_POSIX_SEM */

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Semaphore Test successful\n")));
#else
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);
  ACE_ERROR ((LM_INFO,
              ACE_TEXT ("Threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
  ACE_END_TEST;
  return test_result;
}
key_t
ACE_SV_Semaphore_Simple::name_2_key (const char *name)
{
  ACE_TRACE ("ACE_SV_Semaphore_Simple::name_2_key");

  if (name == 0)
    {
      errno = EINVAL;
      return ACE_static_cast (key_t, ACE_INVALID_SEM_KEY);
    }

  // Basically "hash" the values in the <name>.  This won't
  // necessarily guarantee uniqueness of all keys.
  // But (IMHO) CRC32 is good enough for most purposes (Carlos)
  return (key_t) ACE::crc32 (name);
}
ssize_t
ACE_UPIPE_Stream::send (const char *buffer,
                        size_t n,
                        ACE_Time_Value *timeout)
{
  ACE_TRACE ("ACE_UPIPE_Stream::send");

  ACE_Message_Block *mb_p;
  ACE_NEW_RETURN (mb_p,
                  ACE_Message_Block (n),
                  -1);
  mb_p->copy (buffer, n);
  return
    this->stream_.put (mb_p, timeout) == -1
    ? -1
    : ACE_static_cast (ssize_t, n);
}
Esempio n. 21
0
void
PConnectionManager::destroy_connection(int index)
{
    ACE_GUARD (ACE_SYNCH_RECURSIVE_MUTEX, monitor, this->lock_);

    ACE_ASSERT(ACE_static_cast(u_int,index) < MAX_CONNECTIONS);

    PConnection * connection = this->list_connections_[index];

    if (!connection)
        return;

    this->total_snd_ += connection->get_total_snd();
    this->total_rcv_ += connection->get_total_rcv();
    this->total_w_   += connection->get_total_w();
    this->total_r_   += connection->get_total_r();

    this->factory_.destroy_protocol (connection->protocol ());
    connection->set_protocol (0);

    this->num_connections_--;
    this->list_connections_[index] = 0;


    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%t) %s=%d: DEL %s=%d S=%d(%d+%d) R=%d(%d+%d)\n"),
                this->get_name(),
                this->num_connections_,
                connection->get_name(),
                index,
                connection->get_total_snd(),
                connection->get_total_w(),
                connection->get_ref_cnt_w(),
                connection->get_total_rcv(),
                connection->get_total_r(),
                connection->get_ref_cnt_r()));

    connection->set_manager (0,-1);

    this->factory_.destroy_connection (connection) ;

    if (this->is_safe_to_delete())
        this->task().signal_main();
}
int
ACEXML_Transcoder::utf162utf8 (ACEXML_UTF16 src,
                               ACEXML_UTF8 *dst,
                               size_t len)
{
  // Check for valid argument first...

  if (dst == 0)
    return ACEXML_INVALID_ARGS;

  if (src < 0x80)
    {
      if (len < 1)
        return ACEXML_DESTINATION_TOO_SHORT;

      *dst = ACE_static_cast (ACEXML_UTF8, src);
      return 1;
    }
  else if (src < 0x800)
    {
      if (len < 2)
        return ACEXML_DESTINATION_TOO_SHORT;

      *dst = 0xc0 | (src / 0x40);
      *(dst+1) = 0x80 | (src % 0x40);
      return 2;
    }
  else
    {
      if (len < 3)
        return ACEXML_DESTINATION_TOO_SHORT;

      // Surrogates (0xD800 - 0xDFFF) are not valid unicode values
      if (src >= 0xD800 && src < 0xE000)
        return ACEXML_IS_SURROGATE;

      *dst = 0xe0 | (src / 0x1000);
      *(dst+1) = 0x80 | ((src % 0x1000) / 0x40);
      *(dst+2) = 0x80 | (src % 0x40);
      return 3;
    }
  ACE_NOTREACHED (return ACEXML_NON_UNICODE;)
    }
Esempio n. 23
0
static void
test_duplicates (size_t count)
{
  size_t duplicates = 0;
  size_t sets = 0;
  size_t clears = 0;

  ACE_Handle_Set handle_set;

  ACE_OS::srand (ACE_OS::time (0L));

  for (size_t i = 0; i < count; i++)
    {
      size_t handle =
        ACE_static_cast (size_t, ACE_OS::rand () % ACE_Handle_Set::MAXSIZE);

      if (ACE_ODD (handle))
        {
          if (handle_set.is_set ((ACE_HANDLE) handle))
            duplicates++;

          handle_set.set_bit ((ACE_HANDLE) handle);
          sets++;
        }
      else
        {
          if (handle_set.is_set ((ACE_HANDLE) handle))
            duplicates--;

          handle_set.clr_bit ((ACE_HANDLE) handle);
          clears++;
        }
    }

  ACE_ASSERT (count == sets + clears);
  ACE_ASSERT (handle_set.num_set () + duplicates == sets);
}
int
Synchronized_Suspend_Resume_Test::svc ()
{
#if ACE_DEBUG_CST > 0
    ACE_DEBUG ((LM_DEBUG, "Synchronized_Suspend_Resume_Test::svc (), entering"));

    ACE_hthread_t thread_id;
    ACE_Thread_Manager::instance ()->thr_self (thread_id);

    ACE_DEBUG ((LM_DEBUG, "; thread ID is %u\n", thread_id));
#endif /* ACE_DEBUG_CST */

    {
        Mutex_Acquire_Release_Test mutex_acquire_release_test (num_iterations);
        mutex_acquire_release_test.svc ();
        mutex_acquire_release_time_ =
            ACE_static_cast (ACE_UINT32,
                             mutex_acquire_release_test.elapsed_time () /
                             num_iterations);
#if ACE_DEBUG_CST > 0
        ACE_DEBUG ((LM_DEBUG, "mutex_acquire_release: %u nsec\n",
                    mutex_acquire_release_time_));
#endif /* ACE_DEBUG_CST */
    }

    high_.ready ();

#if ACE_DEBUG_CST > 0
    int priority, high_priority;
    ACE_OS::thr_getprio (thread_id, priority);
    ACE_OS::thr_getprio (high_.thread_id (), high_priority);
    ACE_DEBUG ((LM_DEBUG,
                "Synchronized_Suspend_Resume_Test::svc (), priority is %d, "
                ", high thread priority is %d\n",
                priority, high_priority));
#endif /* ACE_DEBUG_CST */

    // For information:  the cost of the just the loop itself below,
    // without the suspend and resume calls, on a 166 MHz Ultrasparc
    // is about 12.3 nanoseconds per iteration.

    ACE_UINT32 i;

    for (i = 0; i < iterations_; ++i)
    {
#if ACE_DEBUG_CST > 0
        if (i % (iterations_ >= 10  ?  iterations_ / 10  :  1) ==  0)
        {
            ACE_DEBUG ((LM_DEBUG,
                        "Synchronized_Suspend_Resume_Test::svc (), iteration "
                        "%d, continue high-priority thread %u\n",
                        i, high_.thread_id ()));
        }
#endif /* ACE_DEBUG_CST */

        {
            // Acquire the mutex so that the high priority thread will
            // block after we signal it via the condition variable.
            ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1);

            // Release the semaphore so that the high priority thread can
            // proceed.
            if (sem_.release () != 0)
                ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "sem_.release"), -1);

            timer_.start ();

            // Release the mutex so that the high priority thread can
            // proceed.  The ACE_GUARD_RETURN macro implicity releases
            // the mutex.
        }
    }

    high_.done ();

    // The high priority thread will be block on the semaphore, so
    // release it.
    if (sem_.release () != 0)
        ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "sem_.release"), -1);

#if ACE_DEBUG_CST > 0
    ACE_DEBUG ((LM_DEBUG,
                "Synchronized_Suspend_Resume_Test::svc: told high priority "
                "task to terminate\n"));
#endif /* ACE_DEBUG_CST */

    // Resume the thread until thr_continue fails, indicating that it has
    // finished.
    for (i = 0; i < 10000  &&  ! ACE_OS::thr_continue (high_.thread_id ());
            ++i) /* null */;

#if ACE_DEBUG_CST > 0
    ACE_DEBUG ((LM_DEBUG, "Synchronized_Suspend_Resume_Test::svc, finishing\n"));
#endif /* ACE_DEBUG_CST */

    return 0;
}
Esempio n. 25
0
int
main (int argc, char* argv[])
{
    ACE_Get_Opt get_opt (argc, argv, "n:l:pftahmxe");
    int c;
    size_t iteration = 10;
    Profiler profiler = 0;
    const char *profile_name = 0 ;

    while ((c=get_opt ()) != -1)
    {
        switch (c)
        {
        case 'n':
            iteration = ACE_OS::atoi (get_opt.optarg);
            break;
        case 'l':
            MULTIPLY_FACTOR = ACE_static_cast (size_t,
                                               ACE_OS::atoi (get_opt.optarg));
            break;
        case 'p':                       // test ACE_Process.spawn ()
            profiler = prof_ace_process;
            profile_name = "ACE_Process.spawn ()";
            break;
        case 'f':                       // test fork ()
            profiler = prof_fork;
            profile_name = "fork ()";
            break;
        case 't':                       // test native thread creation
            profiler = prof_native_thread;
            profile_name = "native threads";
            break;
        case 'a':                       // test ACE_OS::thr_create
            profiler = prof_ace_os_thread;
            profile_name = "ACE_OS::thr_create ()";
            break;
        case 'm':
            profiler = prof_tm_thread;
            profile_name = "ACE_Thread_Manager::spawn_n ()";
            break;
        case 'x':
            profiler = prof_mutex_base;
            profile_name = "ACE_Thread_Mutex Baseline";
            break;
        case 'h':                       // use high resolution timer
            ACE_High_Res_Timer::get_env_global_scale_factor ();
            break;
        case 'e':
            do_exec_after_fork = 1;
            break;
        default:
            break;
        }
    }

    if (profiler == 0)
        ACE_ERROR_RETURN ((LM_ERROR, "Usage: childbirth_time {-p|-f|-t|-a|-m|-x} [-n ###] [-L ###] [-h] [-e]\n"), 1);
    else
    {
        double time = profiler (iteration);
        if (time > 0)
            ACE_DEBUG ((LM_DEBUG,
                        "Average performance of %d iterations of %s: %.0f usec\n",
                        iteration * MULTIPLY_FACTOR, profile_name, time * 1e6));
    }
    return 0;
}
Esempio n. 26
0
int
ACE_RMCast_Reassembly_Tester::svc (void)
{
  for (int iteration = 0; iteration != 50; ++iteration)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) iteration %d\n"), iteration));
      ACE_UINT32 sequence_number = this->next_sequence_number ();
      {
        ACE_Message_Block received;

        const size_t fragment_size = 128;
        ACE_UINT32 n = 32 * fragment_size;
        ACE_Message_Block big_blob (n);
        big_blob.wr_ptr (n);

        this->initialize (&big_blob);

        // Use an ACT to store the results in <received>
        ACE_Message_Block *received_pointer = &received;
        ACE_OS::memcpy (big_blob.rd_ptr (),
                        &received_pointer,
                        sizeof(received_pointer));

        for (size_t offset = 0; offset < n; offset += fragment_size)
          {
            if (this->put_fragment (sequence_number,
                                    offset,
                                    fragment_size,
                                    &big_blob) == -1)
              {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("Error in put_fragment\n")));
                return -1;
              }
          }

        if (this->compare (&received, &big_blob) == -1)
          {
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT ("Mismatched big_blob data\n")),
                              -1);
          }
      }

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) iteration %d, first test passed\n"),
                  iteration));
      sequence_number = this->next_sequence_number ();
      {
        ACE_Message_Block received;

        const size_t fragment_size = 128;
        ACE_UINT32 n = 32 * fragment_size;
        ACE_Message_Block big_blob (n);
        big_blob.wr_ptr (n);

        this->initialize (&big_blob);

        // Use an ACT to store the results in <received>
        ACE_Message_Block *received_pointer = &received;
        ACE_OS::memcpy (big_blob.rd_ptr (),
                        &received_pointer,
                        sizeof(received_pointer));

        ACE_RANDR_TYPE seed =
          ACE_static_cast(ACE_RANDR_TYPE, ACE_OS::time (0));
        for (int i = 0; i != 100; ++i)
          {
            size_t offset = ACE_OS::rand_r (seed) % n;
            if (offset >= n)
              {
                offset = n/2;
              }
            if (this->put_fragment (sequence_number,
                                    offset,
                                    fragment_size,
                                    &big_blob) == -1)
              {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("Error in put_fragment\n")));
                return -1;
              }
          }

        for (size_t offset = 0; offset < n; offset += fragment_size)
          {
            if (this->put_fragment (sequence_number,
                                    offset,
                                    fragment_size,
                                    &big_blob) == -1)
              {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("Error in put_fragment\n")));
                return -1;
              }
          }

        if (this->compare (&received, &big_blob) == -1)
          {
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT ("Mismatched random big_blob data\n")),
                              -1);
          }
      }
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) iteration %d, random test passed\n"),
                  iteration));
    }

  return 0;
}
Esempio n. 27
0
int
ACE_Mem_Map::map_it (ACE_HANDLE handle,
                     int length_request,
                     int prot,
                     int share,
                     void *addr,
                     off_t offset,
                     LPSECURITY_ATTRIBUTES sa)
{
  ACE_TRACE ("ACE_Mem_Map::map_it");

#if defined (ACE_LACKS_AUTO_MMAP_REPLACEMENT)
  // If the system does not replace any previous mappings, then
  // unmap() before (potentially) mapping to the same location.
  int unmap_result = this->unmap ();
  if (unmap_result != 0)
    return unmap_result;
#endif /* ACE_LACKS_AUTO_MMAP_REPLACEMENT */

  this->base_addr_ = addr;
  this->handle_ = handle;

#if defined (CHORUS)
  // Chorus does not support filesize on a shared memory handle.  We
  // assume that <length_> = 0 when <ACE_Mem_Map> is initially
  // constructed (i.e., before <map_it> is called with a valid
  // <len_request>).
  long result = this->length_;

  if (result == -1)
    return -1;
#else
  long result = ACE_OS::filesize (this->handle_);
#endif /* CHORUS */

  // At this point we know <result> is not negative...
  size_t current_file_length = ACE_static_cast (size_t, result);

  // Flag to indicate if we need to extend the back store
  int extend_backing_store = 0;

  // File length requested by user
  size_t requested_file_length = 0;

  // Check <length_request>
  if (length_request == -1)
    // Set length to file_request.
    this->length_ = current_file_length - offset;
  else
    {
      // File length implicitly requested by user
      requested_file_length = length_request + offset;

      // Check to see if we need to extend the backing store
      if (requested_file_length > current_file_length)
        {
          // If the length of the mapped region is less than the
          // length of the file then we force a complete new remapping
          // by setting the descriptor to ACE_INVALID_HANDLE (closing
          // down the descriptor if necessary).
          this->close_filemapping_handle ();

          // Remember to extend the backing store
          extend_backing_store = 1;
        }

      // Set length to length_request
      this->length_ = length_request;
    }

  // Check if we need to extend the backing store.
  if (extend_backing_store)
    {
#if !defined (CHORUS)
      // Remember than write increases the size by one.
      off_t null_byte_position;
      if (requested_file_length > 0)
        // This will make the file size <requested_file_length>
        null_byte_position =
          ACE_static_cast (off_t, requested_file_length - 1);
      else
        // This will make the file size 1
        null_byte_position = 0;

      if (ACE_OS::pwrite (this->handle_,
                          "",
                          1,
                          null_byte_position) == -1)
        return -1;
#else
      // This nonsense is to make this code similar to the above code.
      size_t actual_file_length;
      if (requested_file_length > 0)
        // This will make the file size <requested_file_length>
        actual_file_length = requested_file_length;
      else
        // This will make the file size 1
        actual_file_length = 1;

      if (ACE_OS::ftruncate (this->handle_,
                             actual_file_length) == -1)
        return -1;
#endif /* !CHORUS */
    }

#if defined (__Lynx__)
  // Set flag that indicates whether PROT_WRITE has been enabled.
  write_enabled_ = ACE_BIT_ENABLED (prot, PROT_WRITE);
#endif /* __Lynx__ */

#if defined (ACE_USE_MAPPING_NAME)
  if (ACE_BIT_ENABLED (share, MAP_SHARED))
    {
# if defined(__MINGW32__)
      const int max_mapping_name_length = 32;
# else
      const int max_mapping_name_length = 31;
# endif /* __MINGW32__ */
      ACE_TCHAR file_mapping_name[max_mapping_name_length + 1];
      to_mapping_name (file_mapping_name,
                       filename_,
                       max_mapping_name_length + 1);

      this->base_addr_ = ACE_OS::mmap (this->base_addr_,
				       this->length_,
				       prot,
				       share,
				       this->handle_,
				       offset,
				       &this->file_mapping_,
				       sa,
				       file_mapping_name);
    }
  else
#endif /* ACE_USE_MAPPING_NAME */
    this->base_addr_ = ACE_OS::mmap (this->base_addr_,
                                     this->length_,
                                     prot,
                                     share,
                                     this->handle_,
                                     offset,
                                     &this->file_mapping_,
                                     sa);

  return this->base_addr_ == MAP_FAILED ? -1 : 0;
}
Esempio n. 28
0
int
ACE_MEM_Connector::connect (ACE_MEM_Stream &new_stream,
                            const ACE_INET_Addr &remote_sap,
                            ACE_Time_Value *timeout,
                            const ACE_Addr &local_sap,
                            int reuse_addr,
                            int flags,
                            int perms,
                            int protocol)
{
  ACE_TRACE ("ACE_MEM_Connector::connect");

  if (!this->address_.same_host (remote_sap))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_LIB_TEXT ("(%P|%t) MEM_Connector can't connect ")
                       ACE_LIB_TEXT ("to %s:%d which is not a local endpoint"),
                       remote_sap.get_host_name (),
                       remote_sap.get_port_number ()),
                      -1);
  else
    this->address_.set_port_number (remote_sap.get_port_number ());


  ACE_SOCK_Stream temp_stream;

  if (ACE_SOCK_Connector::connect (temp_stream,
                                   this->address_.get_local_addr (),
                                   timeout, local_sap,
                                   reuse_addr, flags, perms,
                                   PF_INET, protocol) == -1)
    ACE_ERROR_RETURN ((LM_DEBUG,
                       ACE_LIB_TEXT ("ACE_MEM_Connector::connect error connecting to socket\n")),
                      -1);


  ACE_HANDLE new_handle = temp_stream.get_handle ();
  new_stream.set_handle (new_handle);
  new_stream.disable (ACE_NONBLOCK);
  // Do not close the handle.

  // now we should setup the mmap malloc.
  ACE_TCHAR buf[MAXPATHLEN];

  // @@ Need to handle timeout here.
  ACE_INT16 server_strategy = ACE_MEM_IO::Reactive;
  // Receive the signaling strategy theserver support.
  if (ACE::recv (new_handle, &server_strategy,
                 sizeof (ACE_INT16)) == -1)
    ACE_ERROR_RETURN ((LM_DEBUG,
                       ACE_LIB_TEXT ("ACE_MEM_Connector::connect error receiving strategy\n")),
                      -1);

    // If either side don't support MT, we will not use it.
#if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
  if (! (this->preferred_strategy_ == ACE_MEM_IO::MT &&
         server_strategy == ACE_MEM_IO::MT))
#endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
    server_strategy = ACE_MEM_IO::Reactive;

  if (ACE::send (new_handle, &server_strategy,
                 sizeof (ACE_INT16)) == -1)
    ACE_ERROR_RETURN ((LM_DEBUG,
                       ACE_LIB_TEXT ("ACE_MEM_Connector::connect error sending strategy\n")),
                      -1);

  ACE_INT16 buf_len;
  // Byte-order is not a problem for this read.
  if (ACE::recv (new_handle, &buf_len, sizeof (buf_len)) == -1)
    ACE_ERROR_RETURN ((LM_DEBUG,
                       ACE_LIB_TEXT ("ACE_MEM_Connector::connect error receiving shm filename length\n")),
                      -1);

  if (ACE::recv (new_handle, buf, buf_len) == -1)
    ACE_ERROR_RETURN ((LM_DEBUG,
                       ACE_LIB_TEXT ("ACE_MEM_Connector::connect error receiving shm filename.\n")),
                      -1);

  if (new_stream.init (buf, ACE_static_cast (ACE_MEM_IO::Signal_Strategy, server_strategy),
                       &this->malloc_options_) == -1)
    return -1;

  return 0;
}
Esempio n. 29
0
    // ----------------------------------------------------------
    void
    LogSvcHandler::log(const LogRecord& lr)
    {
	//may need to make some changes to the message if the CORBA
	//logging service is down
	std::string message = lr.message;

	//if it's a trace we set the message to be "".
	if((lr.priority==LM_TRACE) &&
	   (message==FIELD_UNAVAILABLE))
	    {
	    message = "";
	    }
	
	//add a newline if the logging service is unavailable
	if(LoggingProxy::isInit()==false)
	    {
	    message = message + '\n';
	    }

	LoggingProxy::File(lr.file.c_str());
	LoggingProxy::Line(lr.line);

	//only set the logging flags if the priority is debug or trace
	if((lr.priority==LM_DEBUG)||(lr.priority==LM_TRACE))
	    {
	    LoggingProxy::Flags(LM_SOURCE_INFO | LM_RUNTIME_CONTEXT);
	    }

	//if the field is available
	if(lr.method!=FIELD_UNAVAILABLE)
	    {
	    //set the routine name.
	    LoggingProxy::Routine(lr.method.c_str());
	    }
        else
            {
	    LoggingProxy::Routine("");
            }

 	if(lr.priority == LM_SHUTDOWN)
	   message = " -- ERROR in the priority of this message, please check the source --" + message;
	//set the component/container/etc name
	LoggingProxy::SourceObject(sourceObjectName_m.c_str());
	
	//figure out the time
	long sec_ =  ACE_static_cast(CORBA::ULongLong, lr.timeStamp) / ACE_static_cast(ACE_UINT32, 10000000u) - ACE_UINT64_LITERAL(0x2D8539C80); 
        long usec_ = (lr.timeStamp % 10000000u) / 10; 
        ACE_Time_Value time(sec_, usec_); 

	//create the ACE log message
	/**
         * @todo Here there was an assignment to
	 * a local variable never used.
	 * Why was that? 
         * I have now commented it out
	 * int __ace_error = ACE_Log_Msg::last_error_adapter();
	 */
	ACE_Log_Msg::last_error_adapter();

	ACE_Log_Msg *ace___ = ACE_Log_Msg::instance();
	
	//create the ACE log record using the message
	ACE_Log_Record log_record_(acs2acePriority(lr.priority), time, 0);
	log_record_.msg_data(message.c_str());
	
	// set private flags
 	const int prohibitLocal  = getLocalLevel() == LM_SHUTDOWN || lr.priority <  getLocalLevel() ? 1 : 0;
 	const int prohibitRemote = getRemoteLevel() == LM_SHUTDOWN ||lr.priority < getRemoteLevel() ? 2 : 0;
  	LoggingProxy::PrivateFlags(prohibitLocal | prohibitRemote);
  	LoggingProxy::LogLevelLocalType(getLocalLevelType());	
  	LoggingProxy::LogLevelRemoteType(getRemoteLevelType());
	ace___->log(log_record_, 0);
    }
int
High_Priority_Synchronized_Task::svc ()
{
#if ACE_DEBUG_CST > 0
    ACE_DEBUG ((LM_DEBUG, "High_Priority_Synchronized_Task::svc (), entering"));
#endif /* ACE_DEBUG_CST */

    ACE_Thread_Manager::instance ()->thr_self (thread_id_);

    ACE_UINT32 mutex_acquire_release_time = 0;
    {
        Mutex_Acquire_Release_Test mutex_acquire_release_test (num_iterations);
        mutex_acquire_release_test.svc ();
        mutex_acquire_release_time =
            ACE_static_cast (ACE_UINT32,
                             mutex_acquire_release_test.elapsed_time () /
                             num_iterations);
#if ACE_DEBUG_CST > 0
        ACE_DEBUG ((LM_DEBUG, "mutex_acquire_release: %u nsec\n",
                    mutex_acquire_release_time));
#endif /* ACE_DEBUG_CST */
    }

    initialized_.release ();

#if ACE_DEBUG_CST > 0
    ACE_DEBUG ((LM_DEBUG, "; thread ID is %u\n", thread_id_));
#endif /* ACE_DEBUG_CST */

    for (ACE_UINT32 i = 0; ! terminate_; ++i)
    {
#if ACE_DEBUG_CST > 0
        ACE_DEBUG ((LM_DEBUG,
                    "High_Priority_Synchronized_Task::svc, wait on sem ("
                    "%u)\n", thread_id_));
#endif /* ACE_DEBUG_CST */

        if (sem_.acquire () != 0)
        {
            ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "sem_.acquire"), -1);
        }

        {
            // Block on the mutex.
            ACE_GUARD_RETURN (ACE_Thread_Mutex, guard, mutex_, -1);

            timer_.stop ();

            ++iterations_;

            ACE_hrtime_t nsec;
            timer_.elapsed_time (nsec);
            const ACE_UINT32 context_switch_time =
                ACE_U64_TO_U32 (nsec) >= mutex_acquire_release_time  ?
                ACE_U64_TO_U32 (nsec) - mutex_acquire_release_time  :  0;

            total_time_ += context_switch_time;

            // Release the mutex so that the low priority thread can
            // proceed.  The ACE_GUARD_RETURN macro implicity releases the
            // mutex.
        }

#if ACE_DEBUG_CST > 0
        ACE_DEBUG ((LM_DEBUG,
                    "High_Priority_Synchronized_Task::svc, resumed (%u)\n",
                    thread_id_));
#endif /* ACE_DEBUG_CST */
    }

#if ACE_DEBUG_CST > 0
    ACE_DEBUG ((LM_DEBUG, "High_Priority_Synchronized_Task::svc, finishing\n"));
#endif /* ACE_DEBUG_CST */

    return 0;
}