示例#1
0
int
ACE_INET_Addr::string_to_addr (const char s[], int address_family)
{
  ACE_TRACE ("ACE_INET_Addr::string_to_addr");
  int result;
  char *ip_buf = 0;
  char *ip_addr = 0;

  // Need to make a duplicate since we'll be overwriting the string.
  ACE_ALLOCATOR_RETURN (ip_buf,
                        ACE_OS::strdup (s),
                        -1);
  ip_addr = ip_buf;
  // We use strrchr because of IPv6 addresses.
  char *port_p = ACE_OS::strrchr (ip_addr, ':');
#if defined (ACE_HAS_IPV6)
  // Check for extended IPv6 format : '[' <ipv6 address> ']' ':' <port>
  if (ip_addr[0] == '[')
    {
      // find closing bracket
      char *cp_pos = ACE_OS::strchr (ip_addr, ']');
      // check for port separator after closing bracket
      // if not found leave it, error will come later
      if (cp_pos)
        {
          *cp_pos = '\0'; // blank out ']'
          ++ip_addr; // skip over '['
          if (cp_pos[1] == ':')
            port_p = cp_pos + 1;
          else
            port_p = cp_pos; // leads to error on missing port
        }
    }
#endif /* ACE_HAS_IPV6 */

  if (port_p == 0) // Assume it's a port number.
    {
      char *endp = 0;
      u_short port =
        static_cast<u_short> (ACE_OS::strtol (ip_addr, &endp, 10));
      if (*endp == '\0')    // strtol scanned the entire string - all digits
        result = this->set (port, ACE_UINT32 (INADDR_ANY));
      else // port name
        result = this->set (ip_addr, ACE_UINT32 (INADDR_ANY));
    }
  else
    {
      *port_p = '\0'; ++port_p; // skip over ':'

      char *endp = 0;
      u_short port = static_cast<u_short> (ACE_OS::strtol (port_p, &endp, 10));
      if (*endp == '\0')    // strtol scanned the entire string - all digits
        result = this->set (port, ip_addr, 1, address_family);
      else
        result = this->set (port_p, ip_addr);
    }

  ACE_OS::free (ACE_MALLOC_T (ip_buf));
  return result;
}
示例#2
0
ACE_Log_Record::ACE_Log_Record (ACE_Log_Priority lp,
                                const ACE_Time_Value &ts,
                                long p)
  : length_ (0),
    type_ (ACE_UINT32 (lp)),
    secs_ ((ACE_UINT32) ts.sec ()),
    usecs_ ((ACE_UINT32) ts.usec ()),
    pid_ (ACE_UINT32 (p))
{
  // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record");
}
示例#3
0
ACE_Log_Record::ACE_Log_Record (ACE_Log_Priority lp,
                                long ts_sec,
                                long p)
  : length_ (0),
    type_ (ACE_UINT32 (lp)),
    secs_ (ts_sec),
    usecs_ (0),
    pid_ (ACE_UINT32 (p))
{
  // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record");
}
示例#4
0
// Return the 4-byte IP address, converting it into host byte order.
ACE_UINT32
ACE_INET_Addr::get_ip_address (void) const
{
  ACE_TRACE ("ACE_INET_Addr::get_ip_address");
#if defined (ACE_HAS_IPV6)
  if (this->get_type () == AF_INET6)
    {
      if (IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr) ||
          IN6_IS_ADDR_V4COMPAT (&this->inet_addr_.in6_.sin6_addr)    )
        {
          ACE_UINT32 addr;
          // Return the last 32 bits of the address
          char *thisaddrptr = (char*)this->ip_addr_pointer ();
          thisaddrptr += 128/8 - 32/8;
          ACE_OS::memcpy (&addr, thisaddrptr, sizeof (addr));
          return ACE_NTOHL (addr);
        }

      ACE_ERROR ((LM_ERROR,
                  ACE_LIB_TEXT ("ACE_INET_Addr::get_ip_address: address is a IPv6 address not IPv4\n")));
      errno = EAFNOSUPPORT;
      return 0;
    }
#endif /* ACE_HAS_IPV6 */
  return ntohl (ACE_UINT32 (this->inet_addr_.in4_.sin_addr.s_addr));
}
示例#5
0
ACE_Log_Record::ACE_Log_Record (ACE_Log_Priority lp,
                                const ACE_Time_Value &ts,
                                long p)
  : length_ (0),
    type_ (ACE_UINT32 (lp)),
    secs_ (ts.sec ()),
    usecs_ ((ACE_UINT32) ts.usec ()),
    pid_ (ACE_UINT32 (p)),
    msg_data_ (0),
    msg_data_size_ (0)
{
  // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record");
  ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]);
  if (0 != this->msg_data_)
    {
      this->msg_data_size_ = MAXLOGMSGLEN;
      this->msg_data_[0] = '\0';
    }
}
示例#6
0
ACE_Log_Record::ACE_Log_Record (ACE_Log_Priority lp,
                                time_t ts_sec,
                                long p)
  : length_ (0),
    type_ (ACE_UINT32 (lp)),
    secs_ (ts_sec),
    usecs_ (0),
    pid_ (ACE_UINT32 (p)),
    msg_data_ (0),
    msg_data_size_ (0),
    category_(0)
{
  // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record");
  ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]);
  if (0 != this->msg_data_)
    {
      this->msg_data_size_ = MAXLOGMSGLEN;
      this->msg_data_[0] = '\0';
    }
}
示例#7
0
 bool GetProperty(const mstrings_t& properties, 
                  const ACE_TString& prop, ACE_UINT32& value)
 {
     ACE_TString tmp;
     if(GetProperty(properties, prop, tmp))
     {
         UINT_OR_RET(tmp);
         value = ACE_UINT32(string2i(tmp));
         return true;
     }
     return false;
 }
示例#8
0
int
ACE_INET_Addr::string_to_addr (const char s[])
{
  ACE_TRACE ("ACE_INET_Addr::string_to_addr");
  int result;
  char *ip_addr;

  // Need to make a duplicate since we'll be overwriting the string.
  ACE_ALLOCATOR_RETURN (ip_addr,
                        ACE_OS::strdup (s),
                        -1);
  // We use strrchr because of IPv6 addresses.
  char *port_p = ACE_OS::strrchr (ip_addr, ':');

  if (port_p == 0) // Assume it's a port number.
    {
      char *endp = 0;
      u_short port =
        static_cast<u_short> (ACE_OS::strtol (ip_addr, &endp, 10));
      if (port > 0 && *endp == '\0')
        result = this->set (port, ACE_UINT32 (INADDR_ANY));
      else // port name
        result = this->set (ip_addr, ACE_UINT32 (INADDR_ANY));
    }
  else
    {
      *port_p = '\0'; ++port_p; // skip over ':'

      char *endp = 0;
      u_short port = static_cast<u_short> (ACE_OS::strtol (port_p, &endp, 10));
      if (port > 0 && *endp == '\0')
        result = this->set (port, ip_addr);
      else
        result = this->set (port_p, ip_addr);
    }

  ACE_OS::free (ACE_MALLOC_T (ip_addr));
  return result;
}
示例#9
0
ACE_Log_Record::ACE_Log_Record (ACE_Log_Priority lp,
                                const ACE_Time_Value &ts,
                                long p)
  : length_ (0),
    type_ (ACE_UINT32 (lp)),
    secs_ (ts.sec ()),
    usecs_ ((ACE_UINT32) ts.usec ()),
    pid_ (ACE_UINT32 (p)),
    msg_data_ (0),
    msg_data_size_ (0),
    category_(0)
{
  // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record");
#if defined (ACE_HAS_ALLOC_HOOKS)
  ACE_ALLOCATOR_NORETURN (this->msg_data_, static_cast<ACE_TCHAR*> (ACE_Allocator::instance()->malloc(sizeof(ACE_TCHAR) * MAXLOGMSGLEN)));
#else
  ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]);
#endif /* ACE_HAS_ALLOC_HOOKS */
  if (0 != this->msg_data_)
    {
      this->msg_data_size_ = MAXLOGMSGLEN;
      this->msg_data_[0] = '\0';
    }
}
示例#10
0
// Decompress using Run Length Encoding (RLE)
ACE_UINT64
ACE_RLECompressor::decompress( const void *in_ptr,
                               ACE_UINT64 in_len,
                               void *out_ptr,
                               ACE_UINT64 max_out_len )
{
    ACE_UINT64  out_len     = 0;

    const ACE_Byte *in_p    = static_cast<const ACE_Byte *>(in_ptr);
    ACE_Byte *out_p         = static_cast<ACE_Byte *>(out_ptr);

    if (in_p && out_p) while(in_len-- > 0) {

        ACE_Byte    cur_byte    = *in_p++;
        ACE_UINT32  cpy_len     = ACE_UINT32((cur_byte & ACE_CHAR_MAX) + 1);

        if (cpy_len > max_out_len) {
            return ACE_UINT64(-1); // Output Exhausted
        } else if ((cur_byte & 0x80) != 0) {  // compressed
            if (in_len-- > 0) {
                ACE_OS::memset(out_p, *in_p++, cpy_len);
            } else {
                return ACE_UINT64(-1); // Output Exhausted
            }
        } else if (in_len >= cpy_len) {
            ACE_OS::memcpy(out_p, in_p, cpy_len);
            in_p    += cpy_len;
            in_len  -= cpy_len;
        } else {
            return ACE_UINT64(-1); // Output Exhausted
        }

        out_p       += cpy_len;
        max_out_len -= cpy_len;
        out_len     += cpy_len;
    }

    return out_len;
}
示例#11
0
int run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Multihomed_INET_Addr_Test"));

  int status = 0;     // Innocent until proven guilty

  // loop variables
  size_t i, j;
  sockaddr_in *pointer;

  // The port will always be this
  u_short port = 80;

  // The primary address will always be this
  const char *primary_dotted_decimal = "138.38.180.251";

  // The secondary addresses will always be these...
  const char *secondary_dotted_decimals[] = {
    "64.219.54.121",
    "127.0.0.1",
    "21.242.14.51",
    "53.141.124.24",
    "42.12.44.9"
  };

  // ... and as you can see, there are 5 of them
  const size_t num_secondaries = 5;

  // We also need the primary address and the secondary addresses
  // in ACE_UINT32 format in host byte order
  ACE_UINT32 primary_addr32;
  ACE_UINT32 secondary_addr32[5];

  {
    struct in_addr addrv4;
    ACE_OS::memset ((void *) &addrv4, 0, sizeof addrv4);
    ACE_OS::inet_pton (AF_INET, primary_dotted_decimal, &addrv4);
    ACE_OS::memcpy (&primary_addr32, &addrv4, sizeof (primary_addr32));
    primary_addr32 = ACE_NTOHL(primary_addr32);
  }

  for (i = 0; i < num_secondaries; ++i) {
    struct in_addr addrv4;
    ACE_OS::memset ((void *) &addrv4, 0, sizeof addrv4);
    ACE_OS::inet_pton (AF_INET, secondary_dotted_decimals[i], &addrv4);
    ACE_OS::memcpy (&secondary_addr32[i], &addrv4, sizeof (primary_addr32));
    secondary_addr32[i] = ACE_NTOHL(secondary_addr32[i]);
  }

  // Test subject
  ACE_Multihomed_INET_Addr addr;

  // Array of ones (used to clear the secondary addresses of the test
  // subject)
  ACE_UINT32 array_of_threes[5] = { ACE_UINT32 (3),
                                    ACE_UINT32 (3),
                                    ACE_UINT32 (3),
                                    ACE_UINT32 (3),
                                    ACE_UINT32 (3) };

  // Array of INET_Addrs that will repeatedly be passed into the
  // get_secondary_addresses accessor of Multihomed_INET_Addr
  ACE_INET_Addr in_out[5];

  // Array of INET_Addrs against which the above array will be tested.
  ACE_INET_Addr stay_out[5];

  // Array of sockaddrs that will repeatedly be passed into the
  // get_addresses accessor of Multihomed_INET_Addr
  const size_t num_sockaddrs = 6;
  sockaddr_in in_out_sockaddr[num_sockaddrs];

  // Run the test with a varying number of secondary addresses
  for (i = 0; i <= num_secondaries; ++i)  {


    /****** Clear the in_out array and test subject ******/


    // Clear the in_out array by setting every port to 0 and every
    // address to 1
    for (j = 0; j < num_secondaries; ++j)  {
      in_out[j].set(0, ACE_UINT32 (1), 1);
    }

    // Clear the in_out_sockaddr array by setting every port to 0 and
    // every address to 1
    ACE_OS::memset(in_out_sockaddr, 0, num_sockaddrs * sizeof(sockaddr));

    // Clear the test subject by setting the port to 2 and every
    // address (both the primary and the secondaries) to 3
    addr.set (2, ACE_UINT32 (3), 1, array_of_threes, num_secondaries);

    // Check that the port is 2
    if (addr.get_port_number() != 2) {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Failed get_port_number check\n")
                  ACE_TEXT ("%d != %d\n"),
                  addr.get_port_number(),
                  2));
      status = 1;
    }

    // Check that the primary address is 3
    if (addr.get_ip_address() != ACE_UINT32 (3)) {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Failed get_ip_address check\n")
                  ACE_TEXT ("0x%x != 0x%x\n"),
                  addr.get_ip_address(),
                  ACE_UINT32 (3)));
      status = 1;
    }

    // Check that the test subject reports the correct number of
    // secondary addresses.
    size_t returned_num_secondaries = addr.get_num_secondary_addresses();
    if (returned_num_secondaries == num_secondaries) {

      // Set a stay_out element to the state that we expect to see
      // from every in_out element after the in_out array is passed to
      // the accessor of the test subject.
      stay_out[0].set(2, ACE_UINT32 (3), 1);

      // Pass the in_out array to the accessor
      addr.get_secondary_addresses(in_out, num_secondaries);

      // Check that the in_out array matches stay_out element
      for (j = 0; j < num_secondaries; ++j) {

        if (in_out[j] != stay_out[0]) {

          ACE_TCHAR in_out_string[100];
          ACE_TCHAR stay_out_string[100];

          in_out[j].addr_to_string(in_out_string, 100);
          stay_out[0].addr_to_string(stay_out_string, 100);

          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Failed get_secondary_addresses check\n")
                      ACE_TEXT ("%s != %s\n"),
                      in_out_string,
                      stay_out_string));

          status = 1;
        }
      }

      // Pass the in_out_sockaddr array to the accessor
      addr.get_addresses(in_out_sockaddr, num_secondaries + 1);

      // Check that the in_out_sockaddr array matches stay_out element
      for (j = 0, pointer = in_out_sockaddr;
           j < num_secondaries + 1;
           ++j, ++pointer) {

        if (ACE_OS::memcmp(pointer, stay_out[0].get_addr(), sizeof(sockaddr))) {

          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Failed get_addresses check\n")));

          status = 1;
        }
      }

    } else {

        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Failed get_num_secondary_addresses check\n")
                    ACE_TEXT ("%d != %d\n"),
                    returned_num_secondaries,
                    num_secondaries));
        status = 1;

    }


    /**** Test set (u_short, const char[], int, int, const char *([]), size_t) ****/


    addr.set(port,
             primary_dotted_decimal,
             1,
             AF_INET,
             secondary_dotted_decimals,
             i);

    // Check the port number
    if (addr.get_port_number() != port) {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Failed second get_port_number check\n")
                  ACE_TEXT ("%d != %d\n"),
                  addr.get_port_number(),
                  port));
      status = 1;
    }

    // Check the primary address
    if (0 != ACE_OS::strcmp (addr.get_host_addr(), primary_dotted_decimal))
      {
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("%C failed get_host_addr() check\n")
                    ACE_TEXT ("%C != %C\n"),
                    primary_dotted_decimal,
                    addr.get_host_addr (),
                    primary_dotted_decimal));
        status = 1;
      }

    // Check that the test subject reports the correct number of
    // secondary addresses.
    returned_num_secondaries = addr.get_num_secondary_addresses();
    if (returned_num_secondaries == i) {

      // Initialize the stay_out array with the secondary addresses
      for (j = 0; j < i; ++j) {
        stay_out[j].set(port, secondary_dotted_decimals[j]);
      }

      // Pass the in_out array to the accessor
      addr.get_secondary_addresses(in_out, i);

      // Check that the in_out array matches stay_out array
      for (j = 0; j < i; ++j) {

        if (in_out[j] != stay_out[j]) {

          ACE_TCHAR in_out_string[100];
          ACE_TCHAR stay_out_string[100];

          in_out[j].addr_to_string(in_out_string, 100);
          stay_out[j].addr_to_string(stay_out_string, 100);

          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Failed second get_secondary_addresses check\n")
                      ACE_TEXT ("%s != %s\n"),
                      in_out_string,
                      stay_out_string));

          status = 1;
        }
      }

      // Pass the in_out_sockaddr array to the accessor
      addr.get_addresses(in_out_sockaddr, i + 1);

      // Check that the primary address in the in_out_sockaddr array
      // matches the primary address reported by the superclass
      if (ACE_OS::memcmp(in_out_sockaddr, addr.get_addr(), sizeof(sockaddr))) {

          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Failed second get_addresses check ")
                      ACE_TEXT ("(for primary address)\n")));

          status = 1;

      }

      // Check that the secondary addresses in the in_out_sockaddr
      // array match the stay_out array
      for (j = 1, pointer = &in_out_sockaddr[1];
           j < i + 1;
           ++j, ++pointer) {

        if (ACE_OS::memcmp(pointer, stay_out[j-1].get_addr(), sizeof(sockaddr))) {

          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Failed second get_addresses check ")
                      ACE_TEXT ("(for secondary addresses)\n")));

          status = 1;
        }
      }

    } else {

      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Failed second get_num_secondary_addresses check\n")
                  ACE_TEXT ("%d != %d\n"),
                  returned_num_secondaries,
                  i));
      status = 1;
    }


    /****** Clear the in_out array and test subject AGAIN ******/


    // Clear the in_out array by setting every port to 0 and every
    // address to 1
    for (j = 0; j < num_secondaries; ++j)  {
      in_out[j].set(0, ACE_UINT32 (1), 1);
    }

    // Clear the test subject by setting the port to 2 and every
    // address (both the primary and the secondaries) to 3
    addr.set (2, ACE_UINT32 (3), 1, array_of_threes, num_secondaries);

    // Check that the port is 2
    if (addr.get_port_number() != 2) {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Failed third get_port_number check\n")
                  ACE_TEXT ("%d != %d\n"),
                  addr.get_port_number(),
                  2));
      status = 1;
    }

    // Check that the primary address is 3
    if (addr.get_ip_address() != ACE_UINT32 (3)) {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Failed third get_ip_address check\n")
                  ACE_TEXT ("0x%x != 0x%x\n"),
                  addr.get_ip_address(),
                  ACE_UINT32 (3)));
      status = 1;
    }

    // Check that the test subject reports the correct number of
    // secondary addresses.
    returned_num_secondaries = addr.get_num_secondary_addresses();
    if (returned_num_secondaries == num_secondaries) {

      // Set a stay_out element to the state that we expect to see
      // from every in_out element after the in_out array is passed to
      // the accessor of the test subject.
      stay_out[0].set(2, ACE_UINT32 (3), 1);

      // Pass the in_out array to the accessor
      addr.get_secondary_addresses(in_out, num_secondaries);

      // Check that the in_out array matches stay_out array
      for (j = 0; j < num_secondaries; ++j) {

        if (in_out[j] != stay_out[0]) {

          ACE_TCHAR in_out_string[100];
          ACE_TCHAR stay_out_string[100];

          in_out[j].addr_to_string(in_out_string, 100);
          stay_out[0].addr_to_string(stay_out_string, 100);

          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Failed third get_secondary_addresses check\n")
                      ACE_TEXT ("%s != %s\n"),
                      in_out_string,
                      stay_out_string));

          status = 1;
        }
      }

    } else {

        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Failed third get_num_secondary_addresses check\n")
                    ACE_TEXT ("%d != %d\n"),
                    returned_num_secondaries,
                    num_secondaries));
        status = 1;

    }


    /**** Test set (u_short, ACE_UINT32, int, const ACE_UINT32 *, size_t) ****/

    addr.set(port,
             primary_addr32,
             1,
             secondary_addr32,
             i);

    // Check the port number
    if (addr.get_port_number() != port) {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Failed forth get_port_number check\n")
                  ACE_TEXT ("%d != %d\n"),
                  addr.get_port_number(),
                  port));
      status = 1;
    }

    // Check the primary address
    if (0 != ACE_OS::strcmp (addr.get_host_addr(), primary_dotted_decimal))
      {
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("%C failed second get_ip_address() check\n")
                    ACE_TEXT ("%C != %C\n"),
                    primary_dotted_decimal,
                    addr.get_host_addr (),
                    primary_dotted_decimal));
        status = 1;
      }

    // Check that the test subject reports the correct number of
    // secondary addresses.
    returned_num_secondaries = addr.get_num_secondary_addresses();
    if (returned_num_secondaries == i) {

      // Initialize the stay_out array with the secondary addresses
      for (j = 0; j < i; ++j) {
        stay_out[j].set(port, secondary_addr32[j]);
      }

      // Pass the in_out array to the accessor
      addr.get_secondary_addresses(in_out, j);

      // Check that the in_out array matches stay_out array
      for (j = 0; j < i; ++j) {

        if (in_out[j] != stay_out[j]) {

          ACE_TCHAR in_out_string[100];
          ACE_TCHAR stay_out_string[100];

          in_out[j].addr_to_string(in_out_string, 100);
          stay_out[j].addr_to_string(stay_out_string, 100);

          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Failed forth get_secondary_addresses check\n")
                      ACE_TEXT ("%s != %s\n"),
                      in_out_string,
                      stay_out_string));

          status = 1;
        }
      }

    } else {

      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Failed forth get_num_secondary_addresses check\n")
                  ACE_TEXT ("%d != %d\n"),
                  returned_num_secondaries,
                  i));
      status = 1;
    }

  }

  ACE_END_TEST;
  return status;
}
示例#12
0
int run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("INET_Addr_Test"));

  int status = 0;     // Innocent until proven guilty

  // Try to set up known IP and port.
  u_short port (80);
  ACE_UINT32 const ia_any = INADDR_ANY;
  ACE_INET_Addr local_addr(port, ia_any);
  status |= check_type_consistency (local_addr);
  if (local_addr.get_port_number () != 80)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Got port %d, expecting 80\n"),
                  (int)(local_addr.get_port_number ())));
      status = 1;
    }
  if (local_addr.get_ip_address () != ia_any)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Mismatch on local IP addr\n")));
      status = 1;
    }

  // Assignment constructor
  ACE_INET_Addr local_addr2 (local_addr);
  status |= check_type_consistency (local_addr2);
  if (local_addr2.get_port_number () != 80)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Copy got port %d, expecting 80\n"),
                  (int)(local_addr2.get_port_number ())));
      status = 1;
    }
  if (local_addr2.get_ip_address () != ia_any)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Mismatch on copy local IP addr\n")));
      status = 1;
    }
  if (local_addr != local_addr2)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Copy local addr mismatch\n")));
      status = 1;
    }

  // Try to parse out a simple address:port string. Intentionally reuse
  // the ACE_INET_Addr to ensure resetting an address works.
  const char *addr_ports[] =
    {
      "127.0.0.1:80", "www.dre.vanderbilt.edu:80", 0
    };
  ACE_INET_Addr addr_port;
  for (int i = 0; addr_ports[i] != 0; ++i)
    {
      if (addr_port.set (addr_ports[i]) == 0)
        {
          status |= check_type_consistency (addr_port);
          if (addr_port.get_port_number () != 80)
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("Got port %d from %s\n"),
                          (int)(addr_port.get_port_number ()),
                          addr_ports[i]));
              status = 1;
            }
          ACE_INET_Addr check (addr_ports[i]);
          if (addr_port != check)
            {
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Reset on iter %d failed\n"), i));
              status = 1;
            }
        }
      else
        {
          // Sometimes this fails because the run-time host lacks the capability to
          // resolve a name. But it shouldn't fail on the first one, 127.0.0.1.
          if (i == 0)
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("%C: %p\n"),
                          addr_ports[i],
                          ACE_TEXT ("lookup")));
              status = 1;
            }
          else
            {
              ACE_ERROR ((LM_WARNING,
                          ACE_TEXT ("%C: %p\n"),
                          addr_ports[i],
                          ACE_TEXT ("lookup")));
            }
        }
    }

  const char *ipv4_addresses[] =
    {
      "127.0.0.1", "138.38.180.251", "64.219.54.121", "192.0.0.1", "10.0.0.1", 0
    };

  ACE_INET_Addr addr;
  status |= check_type_consistency (addr);
  char hostaddr[1024];

  for (int i=0; ipv4_addresses[i] != 0; i++)
    {
      struct in_addr addrv4;
      ACE_OS::memset ((void *) &addrv4, 0, sizeof addrv4);
      ACE_UINT32 addr32;

      ACE_OS::inet_pton (AF_INET, ipv4_addresses[i], &addrv4);

      ACE_OS::memcpy (&addr32, &addrv4, sizeof (addr32));

      status |= !(addr.set (80, ipv4_addresses[i]) == 0);
      status |= check_type_consistency (addr);

      /*
      ** Now check to make sure get_ip_address matches and get_host_addr
      ** matches.
      */
      if (addr.get_ip_address () != ACE_HTONL (addr32))
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Error: %C failed get_ip_address() check\n")
                      ACE_TEXT ("0x%x != 0x%x\n"),
                      ipv4_addresses[i],
                      addr.get_ip_address (),
                      ACE_HTONL (addr32)));
          status = 1;
        }

      if (addr.get_host_addr () != 0 &&
          ACE_OS::strcmp (addr.get_host_addr(), ipv4_addresses[i]) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%C failed get_host_addr() check\n")
                      ACE_TEXT ("%C != %C\n"),
                      ipv4_addresses[i],
                      addr.get_host_addr (),
                      ipv4_addresses[i]));
          status = 1;
        }

      // Now we check the operation of get_host_addr(char*,int)
      const char* haddr = addr.get_host_addr (&hostaddr[0], sizeof(hostaddr));
      if (haddr != 0 &&
          ACE_OS::strcmp (&hostaddr[0], haddr) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%C failed get_host_addr(char* buf,int) check\n")
                      ACE_TEXT ("buf ['%C'] != return value ['%C']\n"),
                      ipv4_addresses[i],
                      &hostaddr[0],
                      haddr));
          status = 1;
        }
      if (ACE_OS::strcmp (&hostaddr[0], ipv4_addresses[i]) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%C failed get_host_addr(char*,int) check\n")
                      ACE_TEXT ("buf ['%C'] != expected value ['%C']\n"),
                      ipv4_addresses[i],
                      &hostaddr[0],
                      ipv4_addresses[i]));
          status = 1;
        }

      // Clear out the address by setting it to 1 and check
      addr.set (0, ACE_UINT32 (1), 1);
      status |= check_type_consistency (addr);
      if (addr.get_ip_address () != 1)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to set address to 1\n")));
          status = 1;
        }

      // Now set the address using a 32 bit number and check that we get
      // the right string out of get_host_addr().
      addr.set (80, addr32, 0); // addr32 is already in network byte order
      status |= check_type_consistency(addr);

      if (addr.get_host_addr () != 0 &&
          ACE_OS::strcmp (addr.get_host_addr (), ipv4_addresses[i]) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%C failed second get_host_addr() check\n")
                      ACE_TEXT ("return value ['%C'] != expected value ['%C']\n"),
                      ipv4_addresses[i],
                      addr.get_host_addr (),
                      ipv4_addresses[i]));
          status = 1;
        }

      // Test for ACE_INET_Addr::set_addr().
      struct sockaddr_in sa4;
      sa4.sin_family = AF_INET;
      sa4.sin_addr = addrv4;
      sa4.sin_port = ACE_HTONS (8080);

      addr.set (0, ACE_UINT32 (1), 1);
      addr.set_addr (&sa4, sizeof(sa4));
      status |= check_type_consistency (addr);

      if (addr.get_port_number () != 8080)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("ACE_INET_Addr::set_addr() ")
                      ACE_TEXT ("failed to update port number.\n")));
          status = 1;
        }

      if (addr.get_ip_address () != ACE_HTONL (addr32))
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("ACE_INET_Addr::set_addr() ")
                      ACE_TEXT ("failed to update address.\n")));
          status = 1;
        }

    }

#if defined (ACE_HAS_IPV6)
  if (ACE::ipv6_enabled ())
    {
      const char *ipv6_addresses[] = {
        "1080::8:800:200c:417a", // unicast address
        "ff01::101",             // multicast address
        "::1",                   // loopback address
        "::",                    // unspecified addresses
        0
      };

      for (int i=0; ipv6_addresses[i] != 0; i++)
        {
          ACE_INET_Addr addr (80, ipv6_addresses[i]);
          status |= check_type_consistency (addr);

          if (0 != ACE_OS::strcmp (addr.get_host_addr (), ipv6_addresses[i]))
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("IPv6 get_host_addr failed: %C != %C\n"),
                          addr.get_host_addr (),
                          ipv6_addresses[i]));
              status = 1;
            }
        }

      const char *ipv6_names[] = {
        "naboo.dre.vanderbilt.edu",
        "v6.ipv6-test.com",
        0
      };
      for (int i=0; ipv6_names[i] != 0; i++)
        {
          ACE_INET_Addr addr (80, ipv6_names[i]);
          status |= check_type_consistency (addr);

          if (0 != ACE_OS::strcmp (addr.get_host_name (), ipv6_names[i]))
            {
              // Alias? Check lookup on the reverse.
              ACE_INET_Addr alias_check;
              if (alias_check.set (80, addr.get_host_name ()) == 0)
                {
                  if (addr != alias_check)
                    ACE_ERROR ((LM_WARNING,
                                ACE_TEXT ("IPv6 name mismatch: %s (%s) != %s\n"),
                                addr.get_host_name (),
                                addr.get_host_addr (),
                                ipv6_names[i]));
                }
              else
                {
                  ACE_ERROR ((LM_WARNING,
                              ACE_TEXT ("IPv6 reverse lookup mismatch: %s (%s) != %s\n"),
                              addr.get_host_name (),
                              addr.get_host_addr (),
                              ipv6_names[i]));
                }
            }
        }
    }
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("IPv6 tests done\n")));
#else
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE_HAS_IPV6 not set; no IPv6 tests run\n")));
#endif

  struct Address loopback_addresses[] =
    { {"127.0.0.1", true}, {"127.1.2.3", true}
      , {"127.0.0.0", true}, {"127.255.255.255", true}
      , {"126.255.255.255", false}, {"128.0.0.0", false}, {0, true}
    };

  for (int i=0; loopback_addresses[i].name != 0; i++)
    {
      struct in_addr addrv4;
      ACE_UINT32 addr32 = 0;

      ACE_OS::inet_pton (AF_INET, loopback_addresses[i].name, &addrv4);

      ACE_OS::memcpy (&addr32, &addrv4, sizeof (addr32));

      addr.set (80, loopback_addresses[i].name);

      if (addr.is_loopback() != loopback_addresses[i].loopback)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("ACE_INET_Addr::is_loopback() ")
                      ACE_TEXT ("failed to distinguish loopback address. %C\n")
                      , loopback_addresses[i].name));
          status = 1;
        }
    }

  if (addr.string_to_addr ("127.0.0.1:72000", AF_INET) != -1)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("ACE_INET_Addr::string_to_addr() ")
                  ACE_TEXT ("failed to detect port number overflow\n")));
      status = 1;
    }

  if (!test_tao_use ())
    status = 1;

  if (!test_multiple ())
    status = 1;

  if (!test_port_assignment ())
    status = 1;

  ACE_INET_Addr a1 (80, "127.0.0.1");
  ACE_INET_Addr a2 = a1;
  if (a1 != a2)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Address equality check failed after assignment\n")));
      status = 1;
    }

  ACE_END_TEST;

  return status;
}
// Method to read file and populate object.
int
ACE_Ini_ImpExp::import_config (const ACE_TCHAR* filename)
{
  if (0 == filename)
    {
      errno = EINVAL;
      return -1;
    }
  FILE* in = ACE_OS::fopen (filename, ACE_TEXT ("r"));
  if (!in)
    return -1;

  // BlizzLikeCore addition: Try read utf8 header and skip it if exist for support utf8 format file
  ACE_UINT32 utf8header = 0;
  fgets((char*)&utf8header, 4, in);                         // Try read header
  if (utf8header != ACE_UINT32(0x00BFBBEF))                 // If not found
      fseek(in, 0, SEEK_SET);                               // Reset read position
  // BlizzLikeCore addition - end

  // @@ Make this a dynamic size!
  ACE_TCHAR buffer[4096];
  ACE_Configuration_Section_Key section;
  while (ACE_OS::fgets (buffer, sizeof buffer, in))
    {
      ACE_TCHAR *line = this->squish (buffer);
      // Check for a comment and blank line
      if (line[0] == ACE_TEXT (';')  ||
          line[0] == ACE_TEXT ('#')  ||
          line[0] == '\0')
        continue;

      if (line[0] == ACE_TEXT ('['))
        {
          // We have a new section here, strip out the section name
          ACE_TCHAR* end = ACE_OS::strrchr (line, ACE_TEXT (']'));
          if (!end)
            {
              ACE_OS::fclose (in);
              return -3;
            }
          *end = 0;

          if (config_.expand_path (config_.root_section (),
                                   line + 1,
                                   section,
                                   1))
            {
              ACE_OS::fclose (in);
              return -3;
            }

          continue;
        }

      // We have a line; name ends at equal sign.
      ACE_TCHAR *end = ACE_OS::strchr (line, ACE_TEXT ('='));
      if (end == 0)                            // No '='
        {
          ACE_OS::fclose (in);
          return -3;
        }
      *end++ = '\0';
      ACE_TCHAR *name = this->squish (line);
#if 0
      if (ACE_OS::strlen (name) == 0)          // No name; just an '='
        {
          ACE_OS::fclose (in);
          return -3;
        }
#endif
      // Now find the start of the value
      ACE_TCHAR *value = this->squish (end);
      size_t value_len = ACE_OS::strlen (value);
      if (value_len > 0)
        {
          // ACE 5.2 (and maybe earlier) exported strings may be enclosed
          // in quotes. If string is quote-delimited, strip the quotes.
          // Newer exported files don't have quote delimiters.
          if (value[0] == ACE_TEXT ('"') &&
              value[value_len - 1] == ACE_TEXT ('"'))
            {
              // Strip quotes off both ends.
              value[value_len - 1] = '\0';
              ++value;
            }
        }

      if (config_.set_string_value (section, name, value))
        {
          ACE_OS::fclose (in);
          return -4;
        }
    }             // end while fgets

  if (ferror (in))
    {
      ACE_OS::fclose (in);
      return -1;
    }

  ACE_OS::fclose (in);
  return 0;
}
示例#14
0
int run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);

  ACE_START_TEST (ACE_TEXT ("INET_Addr_Test"));

  int status = 0;     // Innocent until proven guilty

  const char *ipv4_addresses[] =
    {
      "127.0.0.1", "138.38.180.251", "64.219.54.121", "192.0.0.1", "10.0.0.1", 0
    };

  ACE_INET_Addr addr;
  status |= check_type_consistency (addr);
  char hostaddr[1024];

  for (int i=0; ipv4_addresses[i] != 0; i++)
    {
      struct in_addr addrv4;
      ACE_UINT32 addr32;

      ACE_OS::inet_pton (AF_INET, ipv4_addresses[i], &addrv4);

      ACE_OS::memcpy (&addr32, &addrv4, sizeof (addr32));

      addr.set (80, ipv4_addresses[i]);
      status |= check_type_consistency (addr);

      /*
      ** Now check to make sure get_ip_address matches and get_host_addr
      ** matches.
      */
      if (addr.get_ip_address () != ACE_HTONL (addr32))
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Error: %s failed get_ip_address() check\n")
                      ACE_TEXT ("0x%x != 0x%x\n"),
                      ipv4_addresses[i],
                      addr.get_ip_address (),
                      addr32));
          status = 1;
        }

      if (addr.get_host_addr () != 0 &&
          ACE_OS::strcmp (addr.get_host_addr(), ipv4_addresses[i]) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%s failed get_host_addr() check\n")
                      ACE_TEXT ("%s != %s\n"),
                      ipv4_addresses[i],
                      addr.get_host_addr (),
                      ipv4_addresses[i]));
          status = 1;
        }

      // Now we check the operation of get_host_addr(char*,int)
      const char* haddr = addr.get_host_addr (&hostaddr[0], sizeof(hostaddr));
      if (haddr != 0 &&
          ACE_OS::strcmp (&hostaddr[0], haddr) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%s failed get_host_addr(char* buf,int) check\n")
                      ACE_TEXT ("buf ['%s'] != return value ['%s']\n"),
                      ipv4_addresses[i],
                      &hostaddr[0],
                      haddr));
          status = 1;
        }
      if (ACE_OS::strcmp (&hostaddr[0], ipv4_addresses[i]) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%s failed get_host_addr(char*,int) check\n")
                      ACE_TEXT ("buf ['%s'] != expected value ['%s']\n"),
                      ipv4_addresses[i],
                      &hostaddr[0],
                      ipv4_addresses[i]));
          status = 1;
        }

      // Clear out the address by setting it to 1 and check
      addr.set (0, ACE_UINT32 (1), 1);
      status |= check_type_consistency (addr);
      if (addr.get_ip_address () != 1)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to set address to 1\n")));
          status = 1;
        }

      // Now set the address using a 32 bit number and check that we get
      // the right string out of get_host_addr().
      addr.set (80, addr32, 0); // addr32 is already in network byte order
      status |= check_type_consistency(addr);

      if (addr.get_host_addr () != 0 &&
          ACE_OS::strcmp (addr.get_host_addr (), ipv4_addresses[i]) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%s failed second get_host_addr() check\n")
                      ACE_TEXT ("return value ['%s'] != expected value ['%s']\n"),
                      ipv4_addresses[i],
                      addr.get_host_addr (),
                      ipv4_addresses[i]));
          status = 1;
        }

      // Test for ACE_INET_Addr::set_addr().
      struct sockaddr_in sa4;
      sa4.sin_family = AF_INET;
      sa4.sin_addr = addrv4;
      sa4.sin_port = ACE_HTONS (8080);

      addr.set (0, ACE_UINT32 (1), 1);
      addr.set_addr (&sa4, sizeof(sa4));
      status |= check_type_consistency (addr);

      if (addr.get_port_number () != 8080)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("ACE_INET_Addr::set_addr() ")
                      ACE_TEXT ("failed to update port number.\n")));
          status = 1;
        }

      if (addr.get_ip_address () != ACE_HTONL (addr32))
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("ACE_INET_Addr::set_addr() ")
                      ACE_TEXT ("failed to update address.\n")));
          status = 1;
        }

    }

#if defined (ACE_HAS_IPV6)
  if (ACE::ipv6_enabled ())
    {
      const char *ipv6_addresses[] = {
        "1080::8:800:200c:417a", // unicast address
        "ff01::101",             // multicast address
        "::1",                   // loopback address
        "::",                    // unspecified addresses
        0
      };

      for (int i=0; ipv6_addresses[i] != 0; i++)
        {
          ACE_INET_Addr addr (80, ipv6_addresses[i]);
          status |= check_type_consistency (addr);

          if (0 != ACE_OS::strcmp (addr.get_host_addr (), ipv6_addresses[i]))
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("IPv6 get_host_addr failed: %s != %s\n"),
                          addr.get_host_addr (),
                          ipv6_addresses[i]));
              status = 1;
            }
        }
    }

#endif

  struct Address loopback_addresses[] =
    { {"127.0.0.1", true}, {"127.1.2.3", true}
      , {"127.0.0.0", true}, {"127.255.255.255", true}
      , {"126.255.255.255", false}, {"128.0.0.0", false}, {0, true}
    };

  for (int i=0; loopback_addresses[i].name != 0; i++)
    {
      struct in_addr addrv4;
      ACE_UINT32 addr32 = 0;

      ACE_OS::inet_pton (AF_INET, loopback_addresses[i].name, &addrv4);

      ACE_OS::memcpy (&addr32, &addrv4, sizeof (addr32));

      addr.set (80, loopback_addresses[i].name);

      if (addr.is_loopback() != loopback_addresses[i].loopback)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("ACE_INET_Addr::is_loopback() ")
                      ACE_TEXT ("failed to distinguish loopback address. %s\n")
                      , loopback_addresses[i].name));
          status = 1;
        }
    }

  ACE_END_TEST;

  return status;
}
示例#15
0
int
ACE_SOCK_Acceptor::shared_open (const ACE_Addr &local_sap,
                                int protocol_family,
                                int backlog)
{
  ACE_TRACE ("ACE_SOCK_Acceptor::shared_open");
  int error = 0;

#if defined (ACE_HAS_IPV6)
  if (protocol_family == PF_INET6)
    {
      sockaddr_in6 local_inet6_addr;
      ACE_OS::memset (reinterpret_cast<void *> (&local_inet6_addr),
                      0,
                      sizeof local_inet6_addr);

      if (local_sap == ACE_Addr::sap_any)
        {
          local_inet6_addr.sin6_family = AF_INET6;
          local_inet6_addr.sin6_port = 0;
          local_inet6_addr.sin6_addr = in6addr_any;
        }
      else
        local_inet6_addr = *reinterpret_cast<sockaddr_in6 *> (local_sap.get_addr ());

      // We probably don't need a bind_port written here.
      // There are currently no supported OS's that define
      // ACE_LACKS_WILDCARD_BIND.
      if (ACE_OS::bind (this->get_handle (),
                        reinterpret_cast<sockaddr *> (&local_inet6_addr),
                        sizeof local_inet6_addr) == -1)
        error = 1;
    }
  else
#endif
  if (protocol_family == PF_INET)
    {
      sockaddr_in local_inet_addr;
      ACE_OS::memset (reinterpret_cast<void *> (&local_inet_addr),
                      0,
                      sizeof local_inet_addr);

      if (local_sap == ACE_Addr::sap_any)
        {
          local_inet_addr.sin_port = 0;
        }
      else
        local_inet_addr = *reinterpret_cast<sockaddr_in *> (local_sap.get_addr ());
      if (local_inet_addr.sin_port == 0)
        {
          if (ACE::bind_port (this->get_handle (),
                              ACE_NTOHL (ACE_UINT32 (local_inet_addr.sin_addr.s_addr))) == -1)
            error = 1;
        }
      else if (ACE_OS::bind (this->get_handle (),
                             reinterpret_cast<sockaddr *> (&local_inet_addr),
                             sizeof local_inet_addr) == -1)
        error = 1;
    }
  else if (ACE_OS::bind (this->get_handle (),
                         (sockaddr *) local_sap.get_addr (),
                         local_sap.get_size ()) == -1)
    error = 1;

  if (error != 0
      || ACE_OS::listen (this->get_handle (),
                         backlog) == -1)
    {
      ACE_Errno_Guard g (errno);    // Preserve across close() below.
      error = 1;
      this->close ();
    }

  return error ? -1 : 0;
}
示例#16
0
文件: client.cpp 项目: CCJY/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int c_breath = 4;
  int c_depth = 4;
  int o_breath = 4;
  ACE_TCHAR *ns1ref = 0;
  ACE_TCHAR *ns2ref = 0;

  ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("b:d:o:p:q:"));
  int c;
  int i;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'b':
        i = ACE_OS::atoi(get_opts.opt_arg ());
        if (i<2)
        {
          ACE_ERROR((LM_ERROR,
                     ACE_TEXT ("Invalid breath, must be 2 or more\n")));
          ACE_OS::exit(1);
        }
        c_breath = i;
        break;
      case 'd':
        i = ACE_OS::atoi(get_opts.opt_arg ());
        if (i<2)
        {
          ACE_ERROR((LM_ERROR,
                     ACE_TEXT ("Invalid depth, must be 2 or more\n")));
          ACE_OS::exit(1);
        }
        c_depth = i;
        break;
      case 'o':
        i = ACE_OS::atoi(get_opts.opt_arg ());
        if (i<2)
        {
          ACE_ERROR((LM_ERROR,
                     ACE_TEXT ("Invalid breath, must be 2 or more\n")));
          ACE_OS::exit(1);
        }
        o_breath = i;
        break;
      case 'p':
        ns1ref = get_opts.opt_arg ();
        break;
      case 'q':
        ns2ref = get_opts.opt_arg ();
        break;
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Argument %c \n usage:  %s")
                           ACE_TEXT (" [-b <breath of context tree>]")
                           ACE_TEXT (" [-d <depth of context tree>]")
                           ACE_TEXT (" [-o <breath of object tree>]")
                           ACE_TEXT (" -p <ior of first name server>")
                           ACE_TEXT (" -q <ior of second name server>")
                           ACE_TEXT ("\n")),
                          -1);
      }

  CosNaming::NamingContext_var root_context_1;
  CosNaming::NamingContext_var root_context_2;

  try
  {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    // ior's are specified for the name servers through a commandline
    // option or a file.

    // Resolve the first name server

    CORBA::Object_var ns1obj = orb->string_to_object (
                            ACE_TEXT_ALWAYS_CHAR (ns1ref));

    if (CORBA::is_nil (ns1obj.in ()))
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT ("invalid ior <%s>\n"),
                               ns1ref),
                              -1);
    root_context_1 = CosNaming::NamingContext::_narrow (ns1obj.in ());

    // Resolve the second name server

    CORBA::Object_var ns2obj = orb->string_to_object (
                            ACE_TEXT_ALWAYS_CHAR (ns2ref));

    if (CORBA::is_nil (ns2obj.in ()))
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT ("invalid ior <%s>\n"),
                               ns2ref),
                              -1);
    root_context_2 = CosNaming::NamingContext::_narrow (ns2obj.in ());

  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception (ACE_TEXT ("Unable to resolve name servers"));
    return -1;
  }

  // Create a bunch of objects in one context
  // Note: strings to the naming service must be char, not wchar
  try
  {
    // Bind one context level under root.
    CosNaming::Name level1;
    level1.length (1);
    level1[0].id = CORBA::string_dup ("level1_context");
    CosNaming::NamingContext_var level1_context;
    level1_context = root_context_1->bind_new_context (level1);

    for (i=0; i<o_breath; i++)
    {
      // Instantiate a dummy object and bind it under the new context.
      My_Test_Object *impl1 = new My_Test_Object (i+1);
      Test_Object_var obj1 = impl1->_this ();
      impl1->_remove_ref ();

      level1.length (2);
      char wide_name[16];
      ACE_OS::sprintf(wide_name, "obj_%d", i);
      level1[1].id = CORBA::string_dup (wide_name);
      root_context_1->bind (level1, obj1.in ());
    }

  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception (ACE_TEXT ("Unable to create a lot of objects"));
    return -1;
  }

  // Create a deep context tree
  try
  {
    CosNaming::NamingContext_var next_context = root_context_1;
    for (i=0; i<c_depth; i++)
    {
      // Bind level1 context under root.
      CosNaming::Name deep;
      deep.length (1);
      char deep_name[16];
      ACE_OS::sprintf(deep_name, "deep_%d", i);
      deep[0].id = CORBA::string_dup (deep_name);
      CosNaming::NamingContext_var deep_context;
      deep_context = next_context->bind_new_context (deep);
      next_context = deep_context;
    }
  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception (ACE_TEXT ("Unable to create deep context"));
    return -1;
  }

  // Create a wide context tree
  try
  {
    for (i=0; i<c_breath; i++)
    {
      // Bind all level of context under root.
      CosNaming::Name wide;
      wide.length (1);
      char wide_name[16];
      ACE_OS::sprintf(wide_name, "wide_%d", i);
      wide[0].id = CORBA::string_dup (wide_name);
      CosNaming::NamingContext_var wide_context;
      wide_context = root_context_1->bind_new_context (wide);
    }
  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception (ACE_TEXT ("Unable to create wide context"));
    return -1;
  }

  // Delete three selected things, one from each tree
  try
  {
    // Remove the second to last object from the Naming Context
    CosNaming::Name wide1;
    wide1.length (2);
    wide1[0].id = CORBA::string_dup ("level1_context");
    char wide_name[16];
    ACE_OS::sprintf(wide_name, "obj_%d", o_breath-2);
    wide1[1].id = CORBA::string_dup (wide_name);
    root_context_1->unbind (wide1);

    // Remove the second to last context from the wide root Naming Context
    CosNaming::Name wide2;
    wide2.length (1);
    ACE_OS::sprintf(wide_name, "wide_%d", c_breath-2);
    wide2[0].id = CORBA::string_dup (wide_name);
    CORBA::Object_var result_obj_ref = root_context_1->resolve (wide2);
    CosNaming::NamingContext_var result_object =
      CosNaming::NamingContext::_narrow (result_obj_ref.in ());
    if (CORBA::is_nil (result_object.in ()))
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Problems with resolving wide context ")
                         ACE_TEXT ("- nil object ref.\n")),
                         -1);
    result_object->destroy();
    root_context_1->unbind (wide2);

    // Remove the last context from the deep Naming Context
    CosNaming::Name deep;
    deep.length (c_depth);
    char deep_name[16];
    for (i=0; i<c_depth; i++)
    {
      ACE_OS::sprintf(deep_name, "deep_%d", i);
      deep[i].id = CORBA::string_dup (deep_name);
    }
    result_obj_ref = root_context_1->resolve (deep);
    result_object =
      CosNaming::NamingContext::_narrow (result_obj_ref.in ());
    if (CORBA::is_nil (result_object.in ()))
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Problems with resolving deep context ")
                         ACE_TEXT ("- nil object ref.\n")),
                         -1);
    result_object->destroy();
    root_context_1->unbind (deep);

  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception (ACE_TEXT ("Unable to delete objects"));
    return -1;
  }

  // Now use the other name server to access 3 objects next to the
  // deleted objects and the 3 deleted objects
  try
  {
    // Access the last object from the Naming Context
    CosNaming::Name wide;
    wide.length (2);
    wide[0].id = CORBA::string_dup ("level1_context");
    char wide_name[16];
    ACE_OS::sprintf(wide_name, "obj_%d", o_breath-1);
    wide[1].id = CORBA::string_dup (wide_name);
    CORBA::Object_var result_obj_ref = root_context_2->resolve (wide);
    Test_Object_var result_object = Test_Object::_narrow (result_obj_ref.in ());
    if (CORBA::is_nil (result_object.in ()))
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Problems with resolving object from ")
                         ACE_TEXT ("redundant server - nil object ref.\n")),
                         -1);
  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception (
      ACE_TEXT (
        "Unable to resolve object from redundant server"));
    return -1;
  }

  try
  {
    // Access the deleted second to last object from the Naming Context
    CosNaming::Name wide;
    wide.length (2);
    wide[0].id = CORBA::string_dup ("level1_context");
    char wide_name[16];
    ACE_OS::sprintf(wide_name, "obj_%d", o_breath-2);
    wide[1].id = CORBA::string_dup (wide_name);
    CORBA::Object_var result_obj_ref = root_context_2->resolve (wide);
    ACE_ERROR_RETURN ((LM_ERROR,
                    ACE_TEXT ("Problems with resolving object from ")
                    ACE_TEXT ("redundant server - deleted object found.\n")),
                    -1);
  }
  catch (const CORBA::Exception&)
  {
    //expect exception since the context was deleted
  }

  try
  {
    // Access the last context from the wide Naming Context
    CosNaming::Name wide;
    wide.length (1);
    char wide_name[16];
    ACE_OS::sprintf(wide_name, "wide_%d", c_breath-1);
    wide[0].id = CORBA::string_dup (wide_name);
    CORBA::Object_var result_obj_ref = root_context_2->resolve (wide);
    CosNaming::NamingContext_var result_object =
      CosNaming::NamingContext::_narrow (result_obj_ref.in ());
    if (CORBA::is_nil (result_object.in ()))
      ACE_ERROR_RETURN ((LM_ERROR,
                      ACE_TEXT ("Problems with resolving wide context from ")
                      ACE_TEXT ("redundant server - nil object ref.\n")),
                      -1);
  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception (
      ACE_TEXT (
        "Unable to resolve wide context from redundant server"));
    return -1;
  }

  try
  {
    // Access the deleted second to last object from the Naming Context
    CosNaming::Name wide;
    wide.length (2);
    char wide_name[16];
    ACE_OS::sprintf(wide_name, "wide_%d", c_breath-2);
    wide[0].id = CORBA::string_dup (wide_name);
    CORBA::Object_var result_obj_ref = root_context_2->resolve (wide);
    ACE_ERROR_RETURN ((LM_ERROR,
                    ACE_TEXT ("Problems with resolving wide context from ")
                    ACE_TEXT ("redundant server - deleted object found.\n")),
                    -1);
  }
  catch (const CORBA::Exception&)
  {
    //expect exception since the context was deleted
  }

  try
  {
    // Access the deleted last context from the deep Naming Context
    CosNaming::Name deep;
    deep.length (c_depth);
    char deep_name[16];
    for (i=0; i<c_depth; i++)
    {
      ACE_OS::sprintf(deep_name, "deep_%d", i);
      deep[i].id = CORBA::string_dup (deep_name);
    }
    CORBA::Object_var result_obj_ref = root_context_1->resolve (deep);
    ACE_ERROR_RETURN ((LM_ERROR,
                    ACE_TEXT ("Problems with resolving deep context from ")
                    ACE_TEXT ("redundant server - deleted object found.\n")),
                    -1);
  }
  catch (const CORBA::Exception&)
  {
    //expect exception since the context was deleted
  }

  try
  {
    // Access the second to last object from the Naming Context
    CosNaming::Name deep;
    deep.length (c_depth-1);
    char deep_name[16];
    for (i=0; i<c_depth-1; i++)
    {
      ACE_OS::sprintf(deep_name, "deep_%d", i);
      deep[i].id = CORBA::string_dup (deep_name);
    }
    CORBA::Object_var result_obj_ref = root_context_1->resolve (deep);
    CosNaming::NamingContext_var result_object =
      CosNaming::NamingContext::_narrow (result_obj_ref.in ());
    if (CORBA::is_nil (result_object.in ()))
      ACE_ERROR_RETURN ((LM_ERROR,
                      ACE_TEXT ("Problems with resolving deep context from ")
                      ACE_TEXT ("redundant server - nil object ref.\n")),
                      -1);


  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception (
      ACE_TEXT (
        "Unable to resolve deep context from redundant server"));
    return -1;
  }

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Redundancy test OK\n")));

  // Test performance of binding a bunch of objects in one context
  try
  {
    // Bind one context level under root.
    CosNaming::Name level1;
    level1.length (1);
    level1[0].id = CORBA::string_dup ("perf_context");
    CosNaming::NamingContext_var perf_context;
    perf_context = root_context_1->bind_new_context (level1);

    // Instantiate a dummy object and bind it under the new context.
    My_Test_Object *impl1 = new My_Test_Object (i+1);
    Test_Object_var obj1 = impl1->_this ();
    impl1->_remove_ref ();

    int test_runs = 100;
    ACE_High_Res_Timer::global_scale_factor_type gsf =
      ACE_High_Res_Timer::global_scale_factor ();

    ACE_hrtime_t start = ACE_OS::gethrtime ();

    // Test how long it takes to bind
    for (i=0; i<test_runs; i++)
    {
      level1.length (1);
      char wide_name[16];
      ACE_OS::sprintf(wide_name, "obj_%d", i);
      level1[0].id = CORBA::string_dup (wide_name);
      perf_context->bind (level1, obj1.in ());
    }

    ACE_hrtime_t elapsed_time = ACE_OS::gethrtime () - start;
    // convert to microseconds
    ACE_UINT32 usecs = ACE_UINT32(elapsed_time / gsf);
    double secs = usecs / 1000000.0;

    ACE_DEBUG ((LM_DEBUG,
                "Bound %i objects in %.2f secs\n",
                test_runs, secs));

    // Test how long it takes to resolve
    start = ACE_OS::gethrtime ();
    for (i=0; i<test_runs; i++)
    {
      level1.length (1);
      char wide_name[16];
      ACE_OS::sprintf(wide_name, "obj_%d", i);
      level1[0].id = CORBA::string_dup (wide_name);
      CORBA::Object_var result_obj_ref = perf_context->resolve (level1);
    }

    elapsed_time = ACE_OS::gethrtime () - start;
    // convert to microseconds
    usecs = ACE_UINT32(elapsed_time / gsf);
    secs = ((ACE_INT32) usecs) / 1000000.0;

    ACE_DEBUG ((LM_DEBUG,
                "Resolved %i objects in %.2f secs\n",
                test_runs, secs));

    // Test how long it takes to unbind
    start = ACE_OS::gethrtime ();
    for (i=0; i<test_runs; i++)
    {
      level1.length (1);
      char wide_name[16];
      ACE_OS::sprintf(wide_name, "obj_%d", i);
      level1[0].id = CORBA::string_dup (wide_name);
      perf_context->unbind (level1);
    }

    elapsed_time = ACE_OS::gethrtime () - start;
    // convert to microseconds
    usecs = ACE_UINT32(elapsed_time / gsf);
    secs = ((ACE_INT32) usecs) / 1000000.0;

    ACE_DEBUG ((LM_DEBUG,
                "Unbound %i objects in %.2f secs\n",
                test_runs, secs));
  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception (ACE_TEXT ("ERROR: Exception during performance test.\n"));
    return -1;
  }

  // All tests have passed up to this point
  return 0;

}
示例#17
0
int
Thread_Task::svc (void)
{
  // if debugging, dump the priority that we're actually at.
  if (TAO_debug_level > 0)
    {

      // Get the priority of the current thread.
      RTCORBA::Priority prio =
        ACTIVITY::instance()->current ()->the_priority ();

      if (prio == this->task_priority_)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%t) actual prio of %d equals desired priority\n"),
                    prio));
      else
        {
          ACE_DEBUG ((LM_ERROR,
                      ACE_TEXT ("(%t) actual prio = %d, desired priority_ = %d!\n"),
                      prio,
                      this->task_priority_));
        }
    }

  if (TAO_debug_level > 0)
    ACE_DEBUG ((LM_DEBUG, "Thread_Task (%t) - wait\n"));

  // First, wait for other threads.
  this->barrier_->wait ();

  // first thread here inits the Base_Time.
  task_stats_->base_time (BASE_TIME::instance ()->base_time_);

  // now wait till the phase_ period expires.
  ACE_OS::sleep (ACE_Time_Value (0, phase_));

  ACE_High_Res_Timer::global_scale_factor_type gsf =
    ACE_High_Res_Timer::global_scale_factor ();

  ACE_hrtime_t before, after;

  for (int i = 0; i < iter_ ; ++i)
    {
      before = ACE_OS::gethrtime ();

      job_->work (load_);

      after = ACE_OS::gethrtime ();

      task_stats_->sample (before, after);

      if (period_ != 0) // blast mode, no sleep.
        {
          // convert to microseconds
          ACE_UINT32 elapsed_microseconds = ACE_UINT32((after - before) / gsf);

#if defined (ACE_WIN32)
          elapsed_microseconds*=1000; // convert to uSec on Win32
#endif /* ACE_WIN32 */

          // did we miss any deadlines?

          int const missed =
            elapsed_microseconds > period_ ? elapsed_microseconds/period_ : 0;

          long sleep_time = (missed + 1)*period_ ;
          sleep_time -= elapsed_microseconds;

          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG, "(%t) sleep time = %d\n", sleep_time));

          ACE_Time_Value t_sleep (0, sleep_time);
          ACE_OS::sleep (t_sleep);
        } /* period != 0 */
    } /* for */

  task_stats_->end_time (ACE_OS::gethrtime ());

  job_->shutdown (); // tell the job that we're done.

  ACTIVITY::instance ()->task_ended (this);

  return 0;
}
示例#18
0
int
ACE_SOCK_Acceptor::shared_open (const ACE_Addr &local_sap,
                                int protocol_family,
                                int backlog)
{
  ACE_TRACE ("ACE_SOCK_Acceptor::shared_open");
  int error = 0;

#if defined (ACE_HAS_IPV6)
  if (protocol_family == PF_INET6)
    {
      sockaddr_in6 local_inet6_addr;
      ACE_OS::memset (reinterpret_cast<void *> (&local_inet6_addr),
                      0,
                      sizeof local_inet6_addr);

      if (local_sap == ACE_Addr::sap_any)
        {
          local_inet6_addr.sin6_family = AF_INET6;
          local_inet6_addr.sin6_port = 0;
          local_inet6_addr.sin6_addr = in6addr_any;
        }
      else
        local_inet6_addr = *reinterpret_cast<sockaddr_in6 *> (local_sap.get_addr ());

# if defined (ACE_WIN32)
      // on windows vista and later, Winsock can support dual stack sockets
      // but this must be explicitly set prior to the bind. Since this
      // behavior is the default on *nix platforms, it should be benigh to
      // just do it here. On older platforms the setsockopt will fail, but
      // that should be OK.
      int zero = 0;
      ACE_OS::setsockopt (this->get_handle (),
                          IPPROTO_IPV6,
                          IPV6_V6ONLY,
                          (char *)&zero,
                          sizeof (zero));
# endif /* ACE_WIN32 */
      // We probably don't need a bind_port written here.
      // There are currently no supported OS's that define
      // ACE_LACKS_WILDCARD_BIND.
      if (ACE_OS::bind (this->get_handle (),
                        reinterpret_cast<sockaddr *> (&local_inet6_addr),
                        sizeof local_inet6_addr) == -1)
        error = 1;
    }
  else
#endif
  if (protocol_family == PF_INET)
    {
      sockaddr_in local_inet_addr;
      ACE_OS::memset (reinterpret_cast<void *> (&local_inet_addr),
                      0,
                      sizeof local_inet_addr);

      if (local_sap == ACE_Addr::sap_any)
        {
          local_inet_addr.sin_port = 0;
        }
      else
        local_inet_addr = *reinterpret_cast<sockaddr_in *> (local_sap.get_addr ());
      if (local_inet_addr.sin_port == 0)
        {
          if (ACE::bind_port (this->get_handle (),
                              ACE_NTOHL (ACE_UINT32 (local_inet_addr.sin_addr.s_addr))) == -1)
            error = 1;
        }
      else if (ACE_OS::bind (this->get_handle (),
                             reinterpret_cast<sockaddr *> (&local_inet_addr),
                             sizeof local_inet_addr) == -1)
        error = 1;
    }
  else if (ACE_OS::bind (this->get_handle (),
                         (sockaddr *) local_sap.get_addr (),
                         local_sap.get_size ()) == -1)
    error = 1;

  if (error != 0
      || ACE_OS::listen (this->get_handle (),
                         backlog) == -1)
    {
      ACE_Errno_Guard g (errno);    // Preserve across close() below.
      error = 1;
      this->close ();
    }

  return error ? -1 : 0;
}
示例#19
0
int
ACE_SOCK_Dgram_Bcast::mk_broadcast (const ACE_TCHAR *host_name)
{
  ACE_TRACE ("ACE_SOCK_Dgram_Bcast::mk_broadcast");

  int one = 1;

  if (ACE_OS::setsockopt (this->get_handle (),
                          SOL_SOCKET,
                          SO_BROADCAST,
                          (char *) &one,
                          sizeof one) == -1)
    ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%p\n"),
                      ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: setsockopt failed")),
                      -1);

#if !defined (ACE_WIN32) && !defined(__INTERIX)
  ACE_HANDLE s = this->get_handle ();

  char buf[BUFSIZ];
  struct ifconf ifc;

  ifc.ifc_len = sizeof buf;
  ifc.ifc_buf = buf;

  // Get interface structure and initialize the addresses using UNIX
  // techniques.
  if (ACE_OS::ioctl (s,
                     SIOCGIFCONF,
                     (char *) &ifc) == -1)
    ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%p\n"),
                      ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface configuration)")),
                      ACE_INVALID_HANDLE);

  struct ifreq *ifr = ifc.ifc_req;

  struct sockaddr_in host_addr;

  // Get host ip address
  if (host_name)
    {
      hostent *hp = ACE_OS::gethostbyname (ACE_TEXT_ALWAYS_CHAR (host_name));

      if (hp == 0)
        return -1;
      else
        ACE_OS::memcpy ((char *) &host_addr.sin_addr.s_addr,
# ifdef ACE_HOSTENT_H_ADDR
                        (char *) hp->ACE_HOSTENT_H_ADDR,
# else
                        (char *) hp->h_addr,
# endif
                        hp->h_length);
    }


#if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_VXWORKS) && !defined(__APPLE__)
  for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0;
       n--, ifr++)
#else
  /*
     There are addresses longer than sizeof (struct sockaddr) eg. IPv6
     or QNX::links. In this case address does not fit into struct ifreq.
     The code below could be applied everywhere, but not every system
         provides sockaddr.sa_len field.
   */
  for (int nbytes = ifc.ifc_len; nbytes >= (int) sizeof (struct ifreq) &&
        ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
          (nbytes >= (int) sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len) : 1);
        ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
          (nbytes -= sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len,
            ifr = (struct ifreq *)
              ((caddr_t) &ifr->ifr_addr + ifr->ifr_addr.sa_len)) :
          (nbytes -= sizeof (struct ifreq), ifr++)))
#endif /* !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_VXWORKS) && !defined(__APPLE__) */
    {
#if defined (__QNX__) || defined (ACE_VXWORKS)
      // Silently skip link interfaces
      if (ifr->ifr_addr.sa_family == AF_LINK)
        continue;
#endif /* __QNX__ || ACE_VXWORKS */
      // Compare host ip address with interface ip address.
      if (host_name)
        {
          struct sockaddr_in if_addr;

          ACE_OS::memcpy (&if_addr,
                          &ifr->ifr_addr,
                          sizeof if_addr);

          if (host_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr)
            continue;
        }

      if (ifr->ifr_addr.sa_family != AF_INET)
        {
          // Note that some systems seem to generate 0 (AF_UNDEF) for
          // the sa_family, even when there are no errors!  Thus, we
          // only print an error if this is not the case, or if we're
          // in "debugging" mode.
          if (ifr->ifr_addr.sa_family != 0
              || ACE::debug ())
          ACELIB_DEBUG ((LM_DEBUG,
                      ACE_TEXT("warning %p: sa_family: %d\n"),
                      ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: Not AF_INET"),
                      ifr->ifr_addr.sa_family));
          continue;
        }

      struct ifreq flags = *ifr;
      struct ifreq if_req = *ifr;

      if (ACE_OS::ioctl (s,
                         SIOCGIFFLAGS,
                         (char *) &flags) == -1)
        {
          ACELIB_ERROR ((LM_ERROR, ACE_TEXT("%p [%s]\n"),
                     ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface flags)"),
                     flags.ifr_name));
          continue;
        }

      if (ACE_BIT_ENABLED (flags.ifr_flags,
                           IFF_UP) == 0)
        {
          ACELIB_ERROR ((LM_ERROR, ACE_TEXT("%p [%s]\n"),
                     ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: Network interface is not up"),
                     flags.ifr_name));
          continue;
        }

      if (ACE_BIT_ENABLED (flags.ifr_flags,
                           IFF_LOOPBACK))
        continue;

      if (ACE_BIT_ENABLED (flags.ifr_flags,
                           IFF_BROADCAST))
        {
          if (ACE_OS::ioctl (s,
                             SIOCGIFBRDADDR,
                             (char *) &if_req) == -1)
            ACELIB_ERROR ((LM_ERROR, ACE_TEXT("%p [%s]\n"),
                       ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get broadaddr)"),
                       flags.ifr_name));
          else
            {
              ACE_INET_Addr addr (reinterpret_cast <sockaddr_in *>
                                                   (&if_req.ifr_broadaddr),
                                  sizeof if_req.ifr_broadaddr);
              ACE_NEW_RETURN (this->if_list_,
                              ACE_Bcast_Node (addr,
                                              this->if_list_),
                              -1);
            }
        }
      else
        {
          if (host_name != 0)
            ACELIB_ERROR ((LM_ERROR, ACE_TEXT("%p [%s]\n"),
                        ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: Broadcast is not enabled for this interface."),
                        flags.ifr_name));
        }
    }
#else
  ACE_UNUSED_ARG (host_name);

  ACE_INET_Addr addr (u_short (0),
                      ACE_UINT32 (INADDR_BROADCAST));
  ACE_NEW_RETURN (this->if_list_,
                  ACE_Bcast_Node (addr,
                                  this->if_list_),
                  -1);
#endif /* !ACE_WIN32 && !__INTERIX */
  if (this->if_list_ == 0)
    {
      errno = ENXIO;
      return -1;
    }
  else
    return 0;
}
示例#20
0
文件: test_i.cpp 项目: asdlei00/ACE
CORBA::Long
Simple_Server_i::test_method (CORBA::Long exec_duration)
{
  ACE_hthread_t thr_handle;
  ACE_Thread::self (thr_handle);
  int prio;
  int guid;
  RTScheduling::Current::IdType_var id = this->current_->id ();

  ACE_OS::memcpy (&guid,
                  id->get_buffer (),
                  sizeof (id->length ()));

  ACE_High_Res_Timer timer;
  ACE_Time_Value elapsed_time;

  ACE_DEBUG ((LM_DEBUG, "Request in thread %t\n"));

  if (ACE_Thread::getprio (thr_handle, prio) == -1)
    {
      if (errno == ENOTSUP)
        {
          ACE_DEBUG((LM_DEBUG,
                     ACE_TEXT ("getprio not supported on this platform\n")));
          return 0;
        }

      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("getprio failed")),
                        -1);
    }

  ACE_DEBUG ((LM_DEBUG,
              "Request in thread %t, prio = %d,"
              "exec duration = %u\n", prio, exec_duration));

  static CORBA::ULong prime_number = 9619899;

  ACE_Time_Value compute_count_down_time (exec_duration, 0);
  ACE_Countdown_Time compute_count_down (&compute_count_down_time);

  //Applicable only for CV based implementations
  //yield every 1 sec
  ACE_Time_Value yield_interval (1,0);

  ACE_Time_Value yield_count_down_time (yield_interval);
  ACE_Countdown_Time yield_count_down (&yield_count_down_time);

  timer.start ();
  int j=0;
  while (compute_count_down_time > ACE_Time_Value::zero)
    {
      ACE::is_prime (prime_number,
                     2,
                     prime_number / 2);

      ++j;

#ifdef KOKYU_DSRT_LOGGING
      if (j%1000 == 0)
        {
          ACE_DEBUG ((LM_DEBUG,
            "(%t|%T) loop # = %d, load = %usec\n", j, exec_duration));
        }
#endif
      if (j%1000 == 0)
        {
          ACE_Time_Value run_time = ACE_OS::gettimeofday ();
          task_stats_.sample (ACE_UINT32 (run_time.msec ()), guid);
        }

      compute_count_down.update ();

      if (enable_yield_)
        {
          yield_count_down.update ();
          if (yield_count_down_time <= ACE_Time_Value::zero)
            {
              CORBA::Policy_var sched_param_policy =
                current_->scheduling_parameter();

              const char * name = 0;

              CORBA::Policy_ptr implicit_sched_param = 0;
              current_->update_scheduling_segment (name,
                                                   sched_param_policy.in (),
                                                   implicit_sched_param);
              yield_count_down_time = yield_interval;
              yield_count_down.start ();
            }
        }
    }

  timer.stop ();
  timer.elapsed_time (elapsed_time);

  ACE_DEBUG ((LM_DEBUG,
              "Request processing in thread %t done, "
              "prio = %d, load = %d, elapsed time = %umsec\n",
              prio, exec_duration, elapsed_time.msec () ));

  return exec_duration;
}