当前位置: 首页>>代码示例>>C++>>正文


C++ ACE_SOCK_Dgram类代码示例

本文整理汇总了C++中ACE_SOCK_Dgram的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Dgram类的具体用法?C++ ACE_SOCK_Dgram怎么用?C++ ACE_SOCK_Dgram使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ACE_SOCK_Dgram类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run_receiver

/*\brief Receive single datagram
  \note The function employes dgram_port and dgram_recv_timeout variables
  \retval -1 if not received,
  \retval 0  received a datagrams
*/
int run_receiver ()
{
  ACE_DEBUG
    ((LM_INFO,
      ACE_TEXT ("Receiving datagrams from port %d with timeout %d ms\n"),
      dgram_port, dgram_recv_timeout.msec ()));

  ACE_SOCK_Dgram socket;
  ACE_INET_Addr  remote ;
  static char    dgram_buffer[BUFSIZ];

  if (socket.open (ACE_INET_Addr (dgram_port)) != -1)
    if (socket.recv (dgram_buffer, sizeof (dgram_buffer),
                     remote, 0, &dgram_recv_timeout) > 0)
      {
        ACE_DEBUG ((LM_INFO, ACE_TEXT ("%C received\n"), dgram_buffer));
        return 0;
      }
    else
      {
        ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
                           ACE_TEXT ("Cannot receive datagrams")), -1);
      }
  else
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p: %d\n"),
                         ACE_TEXT ("Cannot open broadcast socket on port"), dgram_port), -1);
    }
}
开发者ID:esohns,项目名称:ATCD,代码行数:35,代码来源:SOCK_Dgram_Bcast_Test.cpp

示例2: ACE_GUARD_RETURN

int
DSession::open (const ACE_INET_Addr & local,
                const ACE_INET_Addr & remote)
{
  {
    ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, monitor, this->lock_, -1);

    ACE_SOCK_Dgram dgram;

    if (dgram.open(local) == -1)
      ACE_ERROR ((LM_ERROR,
              ACE_TEXT ("(%t) %s=%d open error 1\n"),
              this->get_name (),
              this->index ()));

    else if (this->stream_.open (*this, 
                                dgram.get_handle(),
                                0, // completion key,
                                this->owner_.task().get_proactor(this->index()),
                                1) == -1)
      ACE_ERROR((LM_ERROR,
              ACE_TEXT ("(%t) %s=%d open error 2\n"),
              this->get_name (),
              this->index ()));
    else
      this->on_open(local, remote);

    if (this->io_count_r_ != 0 || 
        this->io_count_w_ != 0 ||
        this->post_count_ != 0 )
      return 0;
  }
  delete this;
  return -1;
}
开发者ID:binghuo365,项目名称:BaseLab,代码行数:35,代码来源:U_Test.cpp

示例3: ACE_UNUSED_ARG

int DgramHandler::handle_timeout (const ACE_Time_Value &current_time, const void *act)
{
  ACE_UNUSED_ARG (current_time);
  ACE_UNUSED_ARG (act);
  int sendBuffer = 0;

  if (++timeoutsTriggered_ >= expectedTriggers_)
    reactor ()->cancel_timer (this, 1);

  ACE_SOCK_Dgram socket;
  if (-1 == socket.open (ACE_INET_Addr (static_cast< u_short > (0),
                                        static_cast< ACE_UINT32 > (INADDR_ANY)),
                                        ACE_PROTOCOL_FAMILY_INET, 0, 1))
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT (" (%P) %p\n"),
                ACE_TEXT ("Cannot open socket for sending Qt dgrams")));

  ACE_INET_Addr peerAddr;
  peer_.get_local_addr (peerAddr);

  if (sizeof (sendBuffer) != socket.send (&sendBuffer,
                                          sizeof (sendBuffer), peerAddr))
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT (" (%P) %p\n"),
                ACE_TEXT ("Cannot send dgram")));
  else
    ++dgramsSent_;

  socket.close ();

  return 0;
}
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:32,代码来源:QtReactor_Test.cpp

示例4: echo_dgram

// 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;
}
开发者ID:BackupTheBerlios,项目名称:pyasynchio-svn,代码行数:14,代码来源:UDP_Unicast.cpp

示例5: send_unicast

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;
}
开发者ID:BackupTheBerlios,项目名称:pyasynchio-svn,代码行数:14,代码来源:UDP_Unicast.cpp

示例6: send_dgram

int send_dgram (ACE_SOCK_Dgram &socket, ACE_INET_Addr addr, int done = 0)
{

  // Send each message twice, once to the right port, and once to the "wrong"
  // port.  This helps generate noise and lets us see if port filtering is
  // working properly.
  const char *address = addr.get_host_addr ();
  int port = addr.get_port_number ();

  for (int i = 0; i < 2; ++i)
    {
      char buf[MAX_STRING_SIZE];
      if (done)
        buf[0] = 0;
      else
        ACE_OS::sprintf (buf, "%s/%d", address, port);

      if (socket.send (buf, ACE_OS::strlen (buf),addr) == -1)
        ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Send to %C, %p\n"),
                           address,
                           ACE_TEXT ("send_dgram - error calling send on ")
                           ACE_TEXT ("ACE_SOCK_Dgram.")), -1);
      addr.set_port_number (++port);
    }
  return 0;
}
开发者ID:CCJY,项目名称:ACE,代码行数:26,代码来源:Multicast_Test.cpp

示例7: run_main

int
run_main (int argc, ACE_TCHAR *argv[])
{
    parse_args (argc, argv);

    // Child process code.
    if (child_nr >= 0)
    {
        ACE_TCHAR lognm[MAXPATHLEN];
        int mypid (ACE_OS::getpid ());
        ACE_OS::sprintf(lognm,
                        ACE_TEXT ("RW_Process_Mutex_Test-child-%d"),
                        (int)mypid);
        ACE_START_TEST (lognm);
        if (child_nr == 0)
            writer ();
        else
            reader (child_nr);
        ACE_END_LOG;
    }
    else
    {
        ACE_START_TEST (ACE_TEXT ("RW_Process_Mutex_Test"));
        // Although it should be safe for each process to construct and
        // destruct the rw lock, this can disturb other process still
        // using the lock. This is not really correct, and should be
        // looked at, but it gets things moving.
        // Also see Process_Mutex_Test.cpp for similar issue.
        ACE_RW_Process_Mutex mutex (mutex_name.c_str ());
        // Make sure the constructor succeeded
        if (ACE_LOG_MSG->op_status () != 0)
        {
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("Parent, mutex %s %p\n"),
                        mutex_name.c_str (),
                        ACE_TEXT ("ctor")));
        }
#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
        static const ACE_TCHAR* format = ACE_TEXT ("%ls -c %d -p %u -n %ls");
#else
        static const ACE_TCHAR* format = ACE_TEXT ("%s -c %d -p %u -n %s");
#endif /* !ACE_WIN32 && ACE_USES_WCHAR */

        // The parent process reads time ranges sent from the children via
        // UDP. Grab an unused UDP port to tell the children to send to.
        ACE_INET_Addr me;
        ACE_SOCK_Dgram sock;
        if (sock.open (ACE_Addr::sap_any, PF_INET) == -1)
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT ("Socket %p\n"),
                               ACE_TEXT ("open")),
                              -1);
        sock.get_local_addr (me);
        ACE_TCHAR me_str[80];
        me.addr_to_string (me_str, 80);
        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Receiving on %s\n"), me_str));

        // Spawn 1 writer and 3 reader processes that will contend for the
        // lock.
        Child writer;
        Child readers[Nr_Processes - 1];
        int i;

        for (i = 0; i < Nr_Processes; i++)
        {
            Child *child = (i == 0 ? &writer : &readers[i-1]);
            ACE_Process_Options options;
            options.command_line (format,
                                  argc > 0 ? argv[0] : ACE_TEXT ("RW_Process_Mutex_Test"),
                                  i,
                                  (unsigned int)me.get_port_number (),
                                  mutex_name.c_str ());
            if (child->spawn (options) == -1)
            {
                ACE_ERROR_RETURN ((LM_ERROR,
                                   ACE_TEXT ("spawn of child %d %p\n"),
                                   i,
                                   ACE_TEXT ("failed")),
                                  -1);
            }
            else
            {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("Child process %d has pid = %d.\n"),
                            i,
                            (int)(child->getpid ())));
            }
        }

        // Keep reading time ranges reported from the children until all the
        // children have exited. Alternate between checking for a range and
        // checking for exits.
        int processes = Nr_Processes;
        Child *children[Nr_Processes];
        for (i = 0; i < Nr_Processes; i++)
            children[i] = (i == 0 ? &writer : &readers[i-1]);

        Range_Report report;
        ACE_Time_Value poll (0);
        ACE_INET_Addr from;
//.........这里部分代码省略.........
开发者ID:jiaoyk,项目名称:ATCD,代码行数:101,代码来源:RW_Process_Mutex_Test.cpp

示例8: writer

static void
writer (void)
{
    ACE_RW_Process_Mutex mutex (mutex_name.c_str ());

    // Make sure the constructor succeeded
    if (ACE_LOG_MSG->op_status () != 0)
    {
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Writer, mutex %s %p\n"),
                    mutex_name.c_str (),
                    ACE_TEXT ("ctor")));
        return;
    }

    ACE_SOCK_Dgram sock;
    ACE_INET_Addr parent;
    parent.set (reporting_port, ACE_LOCALHOST, 1, AF_INET);
    ACE_TCHAR me_str[80];
    parent.addr_to_string (me_str, 80);
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Sending reports to %s\n"), me_str));
    if (sock.open (ACE_Addr::sap_any, PF_INET) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("UDP open")));

    Range_Report report;
    report.child_ = 0;   // We're the writer
    ACE_Time_Value start (ACE_Time_Value::zero), stop (ACE_Time_Value::zero);

    // Grab the lock
    if (-1 == mutex.acquire_write ())
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Writer first %p\n"),
                    ACE_TEXT ("acquire_write")));
    else
    {
        start = ACE_OS::gettimeofday ();
        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer acquired first time\n")));
    }

    // Now sleep, making the readers wait for the lock. Then release the lock,
    // sleep, and reacquire the lock.
    ACE_OS::sleep (2);
    stop = ACE_OS::gettimeofday ();
    if (-1 == mutex.release ())
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Writer %p\n"),
                    ACE_TEXT ("first release")));
    else
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("Writer released first time\n")));

    report.range_.set (start, stop);
    ssize_t bytes = sock.send (&report, sizeof (report), parent);
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer sent %b byte report\n"), bytes));

    ACE_OS::sleep (1);   // Ensure we don't immediately grab the lock back

    start = stop = ACE_Time_Value::zero;

    if (-1 == mutex.acquire_write ())
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Writer second %p\n"),
                    ACE_TEXT ("acquire_write")));
    else
    {
        start = ACE_OS::gettimeofday ();
        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer acquired second time\n")));
    }

    ACE_OS::sleep (2);
    stop = ACE_OS::gettimeofday ();
    if (-1 == mutex.release ())
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Writer %p\n"),
                    ACE_TEXT ("second release")));
    else
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("Writer released second time\n")));
    report.range_.set (start, stop);
    bytes = sock.send (&report, sizeof (report), parent);
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer sent %b byte report\n"), bytes));
    sock.close ();
    return;
}
开发者ID:jiaoyk,项目名称:ATCD,代码行数:84,代码来源:RW_Process_Mutex_Test.cpp

示例9: reader

/*
 * The set of readers and the writer will operate in a staggered sequence
 * of acquiring and releasing the lock. The sequence is designed to exercise
 * waiting behavior of both readers and writer, as well as allowing multiple
 * readers in, without getting tripped up by any differences in ordering
 * on different platforms which may favor writers, or vice-versa.
 * In this timeline, time on seconds is on the left, time holding the lock
 * is solid, time waiting is dots, acquire/release point is a dash, and
 * time without the lock is blank.
 *
 *   TIME        WRITER    READER1    READER2    READER3
 *     0            |
 *                  |
 *     1            |         .
 *                  |         .
 *     2            -         -          -
 *                            |          |
 *     3                      |          |          -
 *                            |          |          |
 *     4                      -          |          |
 *                                       |          |
 *     5                                 -          |
 *                                                  |
 *     6            -                               -
 *                  |
 *     7            |         .          .          .
 *                  |         .          .          .
 *     8            -         -          -          -
 *                            |          |          |
 *     9                      |          |          |
 *
 * A file is used to test the sequencing. When the writer first gets the
 * lock, it will ensure the file is not present. At the end of its time
 * holding the lock the first time, it will write a "writer 1" string to
 * the file. When it gets the lock the second time, it will write a
 * different string to the file, and just before releasing the second time
 * write a "writer 2" string to the file. The readers all check to be sure
 * that the file is present and says "writer 1" at the start and end of
 * their periods of holding the reader lock and, similarly, check for
 * "writer 2" the second time they hold the lock.
 */
static void
reader (int num)
{
    // Let the writer get there first.
    ACE_OS::sleep (1);

    ACE_SOCK_Dgram sock;
    ACE_INET_Addr parent;
    parent.set (reporting_port, ACE_LOCALHOST, 1, AF_INET);
    ACE_TCHAR me_str[80];
    parent.addr_to_string (me_str, 80);
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Sending reports to %s\n"), me_str));

    if (sock.open (ACE_Addr::sap_any, PF_INET) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("UDP open")));

    Range_Report report;
    report.child_ = num;
    ACE_Time_Value start (ACE_Time_Value::zero), stop (ACE_Time_Value::zero);

    ACE_RW_Process_Mutex mutex (mutex_name.c_str ());

    // Make sure the constructor succeeded
    if (ACE_LOG_MSG->op_status () != 0)
    {
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Reader %d, mutex %s %p\n"),
                    num,
                    mutex_name.c_str (),
                    ACE_TEXT ("ctor")));
        return;
    }

    ACE_OS::sleep (num);
    // Grab the lock
    if (-1 == mutex.acquire_read ())
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Reader %d %p\n"),
                    num,
                    ACE_TEXT ("first acquire_read")));
    else
    {
        start = ACE_OS::gettimeofday ();
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("Reader %d acquired first time\n"),
                    num));
    }

    // Wait a bit, then release and report the range held.
    ACE_OS::sleep (num);

    // Release the lock then wait; in the interim, the writer should change
    // the file.
    stop = ACE_OS::gettimeofday ();
    if (-1 == mutex.release ())
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Reader %d %p\n"),
                    num,
                    ACE_TEXT ("first release")));
//.........这里部分代码省略.........
开发者ID:jiaoyk,项目名称:ATCD,代码行数:101,代码来源:RW_Process_Mutex_Test.cpp

示例10: handle_close

int DgramHandler::handle_close (ACE_HANDLE handle, ACE_Reactor_Mask close_mask)
{
  if (peer_.get_handle () != handle )
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Unknown handle %d DgramHandler::handle_close "
                          "with mask %x. My handle is %d\n"),
                handle,
                close_mask,
                peer_.get_handle ()));
  else
    peer_.close ();

  return 0;
}
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:14,代码来源:QtReactor_Test.cpp

示例11: open

int  DgramHandler::open (const ACE_INET_Addr &local,
  int protocol_family,
  int protocol,
  int reuse_addr)
{
  if (0 > peer_.open (local,
                      protocol_family,
                      protocol,
                      reuse_addr))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P) %p\n"),
                       ACE_TEXT ("Cannot oper dgram socket")),
                      -1);

  return 0;
}
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:16,代码来源:QtReactor_Test.cpp

示例12: handle_input

int DgramHandler::handle_input (ACE_HANDLE)
{
  int recvBuffer;
  ACE_INET_Addr peerAddress;

  int result = peer_.recv (&recvBuffer, sizeof (recvBuffer) , peerAddress);

  if (0 >= result)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P) %p\n"),
                       ACE_TEXT ("While reading datagram from socket"))
                      , -1);
  else
    ++dgramsReceived_;

  return 0;
}
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:17,代码来源:QtReactor_Test.cpp

示例13: get_handle

ACE_HANDLE DgramHandler::get_handle () const
{
  return peer_.get_handle ();
}
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:4,代码来源:QtReactor_Test.cpp


注:本文中的ACE_SOCK_Dgram类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。