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


C++ ACE_SOCK_Dgram::recv方法代码示例

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


在下文中一共展示了ACE_SOCK_Dgram::recv方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: mypid


//.........这里部分代码省略.........
                                  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;
        ssize_t bytes;
        while (processes > 0)
        {
            ACE_Time_Value limit (10);
            bytes = sock.recv (&report, sizeof (report), from, 0, &limit);
            if (bytes > 0)
            {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("Report from child %d; %b bytes\n"),
                            report.child_, bytes));
                if (report.child_ == 0)
                    writer.add_range (report.range_);
                else
                {
                    if (report.child_ >= 1 && report.child_ < Nr_Processes)
                        readers[report.child_ - 1].add_range (report.range_);
                    else
                        ACE_ERROR ((LM_ERROR,
                                    ACE_TEXT ("Report from out-of-range child #%d\n"),
                                    report.child_));
                }
            }
            else
            {
                if (errno == ETIME)
                    ACE_DEBUG ((LM_DEBUG,
                                ACE_TEXT ("UDP time out; check child exits\n")));
                else
                    ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("UDP recv")));
            }

            for (i = 0; i < Nr_Processes; i++)
            {
                if (children[i] == 0)
                    continue;
                ACE_exitcode child_status;
                // See if the child has exited.
开发者ID:jiaoyk,项目名称:ATCD,代码行数:67,代码来源:RW_Process_Mutex_Test.cpp


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