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


C++ ACE_SOCK_Acceptor::get_local_addr方法代码示例

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


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

示例1: addr

int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
  ACE_SOCK_Acceptor acceptor;
  ACE_INET_Addr addr(10009);
  if(acceptor.open(addr,1)){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n", "open"),1);
  }
  else if(acceptor.get_local_addr(addr) == -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n", "get_local_addr"),1);
  }

  ACE_DEBUG((LM_INFO,
	     "(%P|%t) starting server at port %d\n",addr.get_port_number()));

  ACE_Thread_Manager* mgr = ACE_Thread_Manager::instance();
  while(true){
    ACE_SOCK_Stream stream;
    if(acceptor.accept(stream) == -1){
      ACE_ERROR((LM_ERROR,
		 "%p\n","accept"));
      continue;
    }else{
      ACE_DEBUG((LM_DEBUG,
		 "(%P|%t) spawning one thread\n"));
      handle_input(mgr, commu, stream.get_handle());
    }
  }
  return 0;
}
开发者ID:jungu,项目名称:brokenseal,代码行数:31,代码来源:repo.cpp

示例2: testConnectionErrorHandling

bool testConnectionErrorHandling()
{
  // Open an acceptor to force an existing port number to be used.
  // Use 0 to indicate an available port should be selected.
  u_short portNum = 0;
  ACE_INET_Addr addr(portNum, ACE_LOCALHOST);
  ACE_SOCK_Acceptor acceptor;
  if (-1 == acceptor.open(addr)) {
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%N:%l: Failed to open acceptor to ")
                                 ACE_TEXT("obtain a used port number")), false);
  }
  acceptor.get_local_addr(addr);
  portNum = addr.get_port_number();

  OpenDDS::DCPS::TransportInst_rch inst =
    TheTransportRegistry->create_inst("tcp1", "tcp");
  OpenDDS::DCPS::TcpInst_rch tcp_inst =
    OpenDDS::DCPS::dynamic_rchandle_cast<OpenDDS::DCPS::TcpInst>(inst);

  acceptor.get_local_addr(tcp_inst->local_address_);

  OpenDDS::DCPS::TransportConfig_rch cfg =
    TheTransportRegistry->create_config("cfg");
  cfg->instances_.push_back(inst);

  TheTransportRegistry->global_config(cfg);

  SimpleTransportClient transportClient;
  transportClient.exceptionThrown = false;
  transportClient.enable();
  if (transportClient.exceptionThrown) {
    ACE_DEBUG ((LM_INFO, ACE_TEXT("%N:%l: Expected exception thrown. ")
                ACE_TEXT("Any previous error messages about transport ")
                ACE_TEXT("configuration can be ignored.\n")));
    return true;
  } else {
    ACE_ERROR ((LM_ERROR, ACE_TEXT("(%N:%l: ERROR: Exception was expected to ")
                          ACE_TEXT("be thrown but was not.\n")));
    return false;
  }
}
开发者ID:AndroidDev77,项目名称:OpenDDS,代码行数:41,代码来源:main.cpp

示例3: listener

 CloudBus::CloudBus(int port, const char* addr)
   : mtx_("CLOUDBUSMTX")
   , mtx_node_list_("CLOUDBUSMTXNODELIST")
   , node_list_condition_(mtx_node_list_)
   , uuid_(boost::uuids::random_generator()())
   , connected_(false)      
 {
   node_info_.port = gadgetron_port_;
   set_compute_capability(1);
   node_info_.uuid = boost::uuids::to_string(uuid_);
   ACE_SOCK_Acceptor listener (ACE_Addr::sap_any);
   ACE_INET_Addr local_addr;
   listener.get_local_addr (local_addr);
   node_info_.address = std::string(local_addr.get_host_name());
 }
开发者ID:wycivil08,项目名称:gadgetron,代码行数:15,代码来源:CloudBus.cpp

示例4: sv_addr

int
Pipe::open (void)
{
  ACE_INET_Addr my_addr;
  ACE_SOCK_Acceptor acceptor;
  ACE_SOCK_Connector connector;
  ACE_SOCK_Stream reader;
  ACE_SOCK_Stream writer;
  int result = 0;

  // Bind listener to any port and then find out what the port was.
  if (acceptor.open (ACE_Addr::sap_any) == -1
      || acceptor.get_local_addr (my_addr) == -1)
    result = -1;
  else
    {
      int af = my_addr.get_type ();
      const ACE_TCHAR *local = ACE_LOCALHOST;
#if defined (ACE_HAS_IPV6)
      if (af == AF_INET6)
        local = ACE_IPV6_LOCALHOST;
#endif /* ACE_HAS_IPV6 */
      ACE_INET_Addr sv_addr (my_addr.get_port_number (),
                             local,
                             af);

      // Establish a connection within the same process.
      if (connector.connect (writer, sv_addr) == -1)
        result = -1;
      else if (acceptor.accept (reader) == -1)
        {
          writer.close ();
          result = -1;
        }
    }

  // Close down the acceptor endpoint since we don't need it anymore.
  acceptor.close ();
  if (result == -1)
    return -1;

  this->handles_[0] = reader.get_handle ();
  this->handles_[1] = writer.get_handle ();

  return 0;
}
开发者ID:helixum,项目名称:wow-cata,代码行数:46,代码来源:MT_Reference_Counted_Event_Handler_Test.cpp

示例5: accept_connections

	int accept_connections(){
		if (peer_acceptor_.get_local_addr(server_addr_) == -1){
			ACE_ERROR_RETURN((LM_ERROR, "%p\n", "Error in get_local_addr"), 1);
		}
		ACE_DEBUG((LM_DEBUG, "Starting server at port %d\n", server_addr_.get_port_number()));
		while (1){
			ACE_Time_Value timeout(ACE_DEFAULT_TIMEOUT);
			if (peer_acceptor_.accept(new_stream_, &client_addr_, &timeout)){
				ACE_ERROR((LM_ERROR, "%p\n", "accept"));
				continue;
			}
			else{
				ACE_DEBUG((LM_DEBUG, "Connection established with remote %s:%d\n",
					client_addr_.get_host_name(), client_addr_.get_port_number()));
				handle_connection();
			}

		}
	}
开发者ID:suiye223,项目名称:ace-linux,代码行数:19,代码来源:server.cpp

示例6: local_any

int
ACE_Pipe::open (int buffer_size)
{
  ACE_TRACE ("ACE_Pipe::open");

#if defined (ACE_LACKS_SOCKETPAIR)
  ACE_INET_Addr my_addr;
  ACE_SOCK_Acceptor acceptor;
  ACE_SOCK_Connector connector;
  ACE_SOCK_Stream reader;
  ACE_SOCK_Stream writer;
  int result = 0;
# if defined (ACE_WIN32)
  ACE_INET_Addr local_any  (static_cast<u_short> (0), ACE_LOCALHOST);
# else
  ACE_Addr local_any = ACE_Addr::sap_any;
# endif /* ACE_WIN32 */

  // Bind listener to any port and then find out what the port was.
  if (acceptor.open (local_any) == -1
      || acceptor.get_local_addr (my_addr) == -1)
    result = -1;
  else
    {
      ACE_INET_Addr sv_addr (my_addr.get_port_number (),
                             ACE_LOCALHOST);

      // Establish a connection within the same process.
      if (connector.connect (writer, sv_addr) == -1)
        result = -1;
      else if (acceptor.accept (reader) == -1)
        {
          writer.close ();
          result = -1;
        }
    }

  // Close down the acceptor endpoint since we don't need it anymore.
  acceptor.close ();
  if (result == -1)
    return -1;

  this->handles_[0] = reader.get_handle ();
  this->handles_[1] = writer.get_handle ();

# if !defined (ACE_LACKS_TCP_NODELAY)
  int one = 1;

  // Make sure that the TCP stack doesn't try to buffer small writes.
  // Since this communication is purely local to the host it doesn't
  // affect network performance.

  if (writer.set_option (ACE_IPPROTO_TCP,
                         TCP_NODELAY,
                         &one,
                         sizeof one) == -1)
    {
      this->close ();
      return -1;
    }
# endif /* ! ACE_LACKS_TCP_NODELAY */

# if defined (ACE_LACKS_SO_RCVBUF) && defined (ACE_LACKS_SO_SNDBUF)
    ACE_UNUSED_ARG (buffer_size);
# endif
# if !defined (ACE_LACKS_SO_RCVBUF)
  if (reader.set_option (SOL_SOCKET,
                         SO_RCVBUF,
                         reinterpret_cast <void *> (&buffer_size),
                         sizeof (buffer_size)) == -1
      && errno != ENOTSUP)
    {
      this->close ();
      return -1;
    }
# endif /* !ACE_LACKS_SO_RCVBUF */
# if !defined (ACE_LACKS_SO_SNDBUF)
  if (writer.set_option (SOL_SOCKET,
                         SO_SNDBUF,
                         reinterpret_cast <void *> (&buffer_size),
                         sizeof (buffer_size)) == -1
           && errno != ENOTSUP)
    {
      this->close ();
      return -1;
    }
# endif /* !ACE_LACKS_SO_SNDBUF */

#elif defined (ACE_HAS_STREAM_PIPES) || defined (__QNX__)
  ACE_UNUSED_ARG (buffer_size);
  if (ACE_OS::pipe (this->handles_) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("pipe")),
                      -1);

#if !defined(__QNX__)
  int arg = RMSGN;

  // Enable "msg no discard" mode, which ensures that record
//.........这里部分代码省略.........
开发者ID:08keelr,项目名称:TrinityCore,代码行数:101,代码来源:Pipe.cpp


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