C++ ACE_INET_Addr类(方法)实例源码

下面列出了C++ ACE_INET_Addr 类(方法)源码代码实例,从而了解它的用法。

作者:EnsonRedShir    项目:Seg   
/**
 * @return bool (false means an error occurred )
 * @param  inipath Doc at RoamingServer::ReadConfig
 */
bool MapServer::ReadConfig(const std::string &inipath)
{
    StringsBasedCfg config;
    ACE_Ini_ImpExp	config_importer(config);
    ACE_Configuration_Section_Key root;
    std::string map_templates_dir;

    if(m_endpoint)
    {
        //TODO: perform shutdown, and load config ?
        ACE_DEBUG((LM_WARNING,ACE_TEXT("(%P|%t) MapServer already initialized and running\n") ));
        return true;
    }
    if (config.open () == -1)
        ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) MapServer: %p\n"), ACE_TEXT ("config")),false);
    if (config_importer.import_config (inipath.c_str()) == -1)
        ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) MapServer: Unable to open config file : %s\n"), inipath.c_str()),false);
    if(-1==config.open_section(config.root_section(),"MapServer",1,root))
        ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("(%P|%t) MapServer: Config file %s is missing [MapServer] section\n"), inipath.c_str()),false);
    if(!RoamingServer::ReadConfig(inipath))
        return false;

    config.get_addr(root,ACE_TEXT("listen_addr"),m_listen_point,ACE_INET_Addr(7002,"0.0.0.0"));
    config.get_addr(root,ACE_TEXT("location_addr"),m_location,ACE_INET_Addr(7002,"127.0.0.1"));
    config.get_addr(root,ACE_TEXT("location_addr"),m_location,ACE_INET_Addr(7002,"127.0.0.1"));
    config.get_string_value(root,ACE_TEXT("maps"),map_templates_dir,".");
    m_online = false;
    return m_manager.load_templates(map_templates_dir);
}

作者:azraell    项目:knetwor   
// constructor.
QoS_Util::QoS_Util (int argc,
                    ACE_TCHAR *argv[])
  : argc_ (argc),
    argv_ (argv),
    source_port_ (SENDER_PORT),
    protocol_ (IPPROTO_UDP),
    multicast_flag_ (0)
{
  ACE_NEW (this->mult_session_addr_,
           ACE_INET_Addr (ACE_DEFAULT_MULTICAST_PORT));

  ACE_NEW (this->dest_addr_,
           ACE_INET_Addr (ACE_DEFAULT_SERVER_PORT));
}

作者:DOCGrou    项目:ACE_TA   
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  u_short port = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT;
  ACE_TLI_Acceptor server;
  ACE_TLI_Stream new_stream;

  // Open the server and reuse the address if in use...
  if (server.open (ACE_INET_Addr (port), 1) == -1)
    ACE_OS::t_error ("server.open"), ACE_OS::exit (1);

  // Wait for a connection from a client.  This is an example of a
  // concurrent server.

  for (int count = 1; ; count++)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "thread %t, blocking for accept #%d\n",
                  count));

      if (server.accept (new_stream) == -1)
        ACE_OS::t_error ("server.accept error");

      else if (thr_mgr.spawn (ACE_THR_FUNC (read_file),
                              (void *) new_stream.get_handle (),
                              THR_DETACHED | THR_BOUND) == -1)
        ACE_OS::perror ("can't create worker thread\n");
    }

  ACE_NOTREACHED (return 0);
}

作者:binghuo36    项目:BaseLa   
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  if (parse_args (argc, argv) == -1)
    return -1;

  Sender sender;

  // Note: acceptor parameterized by the Receiver.
  ACE_Asynch_Acceptor<Receiver> acceptor;

  // If passive side
  if (host == 0)
   {
     if (acceptor.open (ACE_INET_Addr (port),
                        initial_read_size,
                        1) == -1)
       return -1;
   }
  // If active side
  else if (sender.open (host, port) == -1)
    return -1;

  int success = 1;

  while (success > 0  && !done)
    // Dispatch events via Proactor singleton.
    success = ACE_Proactor::instance ()->handle_events ();

  return 0;
}

作者:AtViru    项目:SkyFireEM   
// Constructor.
ACE_RAPI_Session::ACE_RAPI_Session (void)
{
  ACE_TRACE ("ACE_RAPI_Session::ACE_RAPI_Session");
  //this->source_port (DEFAULT_SOURCE_SENDER_PORT);
  ACE_NEW (this->src_addr_,
           ACE_INET_Addr ("0"));
}

作者:binghuo36    项目:BaseLa   
int
DOwner::start_receiver(const ACE_INET_Addr & local)
{
  ACE_GUARD_RETURN (ACE_SYNCH_RECURSIVE_MUTEX, monitor, this->lock_, 0);

  if (this->connections_ >= MAX_CONNECTIONS || flg_cancel_ != 0)
    return -1;

  for (u_int i = 0; i < MAX_CONNECTIONS; ++i)
    {
      if (this->list_connections_ [i] == 0)
        {
          ACE_NEW_RETURN (this->list_connections_[i],
                          Receiver (*this, i),
                          -1);

          this->list_connections_[i]->open(local,
                                       ACE_INET_Addr((u_short)0));
          return 0;
        }
    }

  ACE_ASSERT(0);
  return -1;
}

作者:DOCGrou    项目:ACE_TA   
int
HTTP_Connector::connect (const char * url)
{
  char host[BUFSIZ];
  u_short port;
  char path[BUFSIZ];

  if (this->parseurl (url, host, &port, path) == -1)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "HTTP_Connector, error parsing url: %s\n",
                  url));
      return -1;
    }

  HTTP_Handler hh (path);
  HTTP_Handler *hhptr = &hh;

  // First check the cache.
  if (ACE_Filecache::instance ()->find (ACE_TEXT_CHAR_TO_TCHAR (hh.filename ())) == 0)
    {
      ACE_DEBUG ((LM_DEBUG, "  ``%s'' is already cached.\n",
                  hh.filename ()));
      return 0;
    }

  return this->connector_.connect (hhptr, ACE_INET_Addr (port, host));
}

作者:binghuo36    项目:BaseLa   
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  if (parse_args (argc, argv) == -1)
    return -1;

  Sender sender;

  Receiver receiver;

  // If passive side
  if (host == 0)
    {
      if (receiver.open_addr (ACE_INET_Addr (port)) == -1)
        return -1;
    }
  // If active side
  else if (sender.open (host, port) == -1)
    return -1;

  for (int success = 1;
       success > 0  && !done;
       )
    // Dispatch events via Proactor singleton.
    success = ACE_Proactor::instance ()->handle_events ();

  return 0;
}

作者:svn2githu    项目:OpenDD   
ACE_INET_Addr
TestDriver::parse_address(const std::string& spec)
{
  std::string::size_type pos;

  if ((pos = spec.find(':')) == std::string::npos) {
    ACE_ERROR((LM_ERROR,
               "(%P|%t) Bad address (%s) - missing ':' char.\n",
               spec.c_str()));
    throw TestException();
  }

  if (pos == 0) {
    ACE_ERROR((LM_ERROR,
               "(%P|%t) Bad address (%s) - "
               "':' char can't be first char.\n",
               spec.c_str()));
    throw TestException();
  }

  if (pos == (spec.length() - 1)) {
    ACE_ERROR((LM_ERROR,
               "(%P|%t) Bad address (%s) - "
               "':' char can't be last char.\n",
               spec.c_str()));
    throw TestException();
  }

  return ACE_INET_Addr(spec.c_str());
}

作者:esohn    项目:ATC   
/*\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);
    }
}

作者:DOCGrou    项目:ACE_TA   
int HandlersRegister::registerDgramHandlers ()
{
  int i;

  // open dgram handlers for all ports
  for (i = 0; i < HandlersNo; ++i)
    if (-1 == DgramHandlers_[ i ]->open (
                                         ACE_INET_Addr (i + BaseDgramPort,
                                                        ACE_TEXT ("127.0.0.1"),
                                                        ACE_PROTOCOL_FAMILY_INET)))
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT (" (%P) %p\n"),
                         ACE_TEXT ("Cannot open dgram handler")),
                        -1);

  // register dgram handlers
  for (i = 0; i < HandlersNo; ++i)
    if (-1 == reactor_->register_handler (DgramHandlers_[ i ],
                                          ACE_Event_Handler::READ_MASK))
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT (" (%P) %p\n"),
                         ACE_TEXT ("Cannot register dgram handler")),
                        -1);
  return 0;
}

作者:DOCGrou    项目:ACE_TA   
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;
}

作者:asdlei0    项目:AC   
int
TeraSS_Acceptor::init (int argc, ACE_TCHAR *argv[])
{
  ACE_Get_Opt opt (argc, argv, ACE_TEXT("p:"));

  unsigned short p = 0;

  int c;
  while ((c = opt ()) != -1)
    switch (c)
      {
      case 'p':
        p = (unsigned short) ACE_OS::atoi (opt.optarg);
        break;
      default:
        break;
      }

  if (p == 0)
    p = 5555;

  if (this->open (ACE_INET_Addr (p)) == -1)
    {
      ACE_DEBUG ((LM_DEBUG, "%p\n", "ACE_Acceptor::open"));
      return -1;
    }

  return 0;
}

作者:CCJ    项目:AC   
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  if (argc < 2)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Usage: %s filename ")
                       ACE_TEXT ("[server-host port-number]\n"),
                       argv[0]),
                      1);

  const ACE_TCHAR *filename  = argv[1];
  const ACE_TCHAR *host_name = argc < 3 ? ACE_DEFAULT_SERVER_HOST : argv[2];
  u_short port = argc < 4 ? ACE_DEFAULT_SERVER_PORT : ACE_OS::atoi (argv[3]);

  ACE_TLI_Stream client;
  ACE_TLI_Connector con;
  int fd;
  char buf[BUFSIZ];

  if (con.connect (client, ACE_INET_Addr (port, host_name)) == -1)
    ACE_OS::t_error ((char *) host_name), ACE_OS::exit (1);

  if ((fd = ACE_OS::open (filename, O_RDONLY)) == -1)
    ACE_OS::perror (filename), ACE_OS::exit (1);

  for (int n; (n = ACE_OS::read (fd, buf, sizeof buf)) > 0; )
    if (client.send_n (buf, n) != n)
      ACE_OS::t_error ("client.send error");

  if (client.close () == -1)
    ACE_OS::t_error ("cli_close"), ACE_OS::exit (1);

  return 0;
}

作者:BackupTheBerlio    项目:pyasynchio-sv   
int
HTTP_Server::asynch_thread_pool (void)
{
// This only works on Win32
#if defined (ACE_WIN32)
    // Create the appropriate acceptor for this concurrency strategy and
    // an appropriate handler for this I/O strategy
    ACE_Asynch_Acceptor<Asynch_HTTP_Handler_Factory> acceptor;

    // Tell the acceptor to listen on this->port_, which makes an
    // asynchronous I/O request to the OS.
    if (acceptor.open (ACE_INET_Addr (this->port_),
                       HTTP_Handler::MAX_REQUEST_SIZE + 1) == -1)
        ACE_ERROR_RETURN ((LM_ERROR, "%p\n",
                           "ACE_Asynch_Acceptor::open"), -1);

    // Create the thread pool.
    // Register threads with the proactor and thread manager.
    Asynch_Thread_Pool_Task t (*ACE_Proactor::instance (),
                               this->tm_);

    // The proactor threads are waiting on the I/O Completion Port.

    // Wait for the threads to finish.
    return this->tm_.wait ();
#endif /* ACE_WIN32 */
    return -1;
}

作者:arun1129    项目:ACE-Code-Examples-Cp   
int
Log_Wrapper::open (const int port, const char *mcast_addr)
{
  struct hostent *host_info;
  ACE_utsname host_data;

  if (ACE_OS::uname (&host_data) < 0)
    return -1;

  if ((host_info = ACE_OS::gethostbyname (host_data.nodename)) == 0)
    return -1;
  else
    ACE_OS::memcpy ((char *) &this->log_msg_.host,
                    (char *) host_info->h_addr,
                    host_info->h_length);

  // This starts out initialized to all zeros!
  server_ = ACE_INET_Addr (port, mcast_addr);

  if (logger_.subscribe (server_) == -1)
    ACE_OS::perror("can't subscribe to multicast group"), ACE_OS::exit(1);

  // success.
  return 0;
}

作者:nykm    项目:ykt4sungar   
void KSGLoopDeviceListenScheduler::Run()
	{
		int ret;
		_s_LoopReactor.owner(ACE_OS::thr_self());
		LoopSvrAcceptor acceptor;
		if(_s_interface.LoadDLLFunc())
		{
			ACE_DEBUG((LM_ERROR,"加载本地设备接口失败"));
			return;
		}
		
		int port = 9001;
#ifndef _DEBUG
		// TODO: 正式环境从后台中读取参数
		ACE_DEBUG((LM_NOTICE,"请设置侦听端口"));

#endif
		if(acceptor.open(ACE_INET_Addr(port),&_s_LoopReactor))
		{
			ACE_DEBUG((LM_ERROR,"Loop设备侦听失败,端口[%d]",port));
		}
		else if((ret = _s_interface.Initialize()))
		{
			ACE_DEBUG((LM_ERROR,"初始化Loop接口失败,返回错误[%d]",ret));
		}
		else
		{
			ACE_DEBUG((LM_INFO,"Loop设备开始侦听,线程号[%d]",ACE_OS::thr_self()));
			try
			{
				while(true)
				{
					ACE_Time_Value tv(5);
					_s_LoopReactor.handle_events(tv);
					Notify();
					if(IsTerminated())
					{
						while(!_s_LoopReactor.reactor_event_loop_done())
							_s_LoopReactor.end_reactor_event_loop();
						break;
					}
				}
				ACE_DEBUG((LM_NOTICE,"停止本地侦听服务"));
				if(_s_interface.Uninitialize())
				{
					ACE_DEBUG((LM_ERROR,"调用Loop设备接口释放资源失败!"));
				}
				ACE_DEBUG((LM_INFO,"Loop设备服务线程结束"));
			}
			catch(...)
			{
				// 捕获所有异常
				ACE_DEBUG((LM_NOTICE,"Loop设备服务线程执行异常"));
			}
		}
	}

作者:binghuo36    项目:BaseLa   
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_LOG_MSG->open (argv[0]);

  parse_args (argc, argv);
  // Default is to ask the server for ``help.''
  static char buf[BUFSIZ] = "help\n";
  int n;
  ACE_SOCK_Stream   sc;
  ACE_SOCK_Connector con;

  if (con.connect (sc,
                   ACE_INET_Addr (port_number,
                                  host_name)) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n%a",
                       "connect",
                       1),
                      -1);

  if (remote_reconfigure)
    // Remotely instruct the server to reconfigure itself.
    ACE_OS::strcpy (buf, "reconfigure\n");

  // Send the command.

  if (sc.send_n (buf,
                 ACE_OS::strlen (buf) + 1) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n%a",
                       "send",
                       1), -1);

  // Next, read the response.

  while ((n = sc.recv (buf,
                       sizeof buf)) > 0)
    if (ACE_OS::write (ACE_STDOUT,
                       buf,
                       n) != n)
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n%a",
                         "write",
                         1),
                        -1);

  if (sc.close () == -1)
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n%a",
                         "close",
                         1),
                        -1);

  return 0;
}

作者:BearWar    项目:TeamTalk   
bool GetProperty(const mstrings_t& properties, const ACE_TString& prop, 
                  ACE_INET_Addr& addr)
 {
     ACE_TString str;
     if(GetProperty(properties, prop, str))
     {
         addr = ACE_INET_Addr(str.c_str());
         return true;
     }
     return false;
 }

作者:BackupTheBerlio    项目:pyasynchio-sv   
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_UNUSED_ARG (initial_read_size);

  if (parse_args (argc, argv) == -1)
    return -1;

#if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)

  ACE_WIN32_Proactor *      pImpl = new ACE_WIN32_Proactor;

#elif defined (ACE_HAS_AIO_CALLS)

  //  ACE_POSIX_AIOCB_Proactor *  pImpl = new ACE_POSIX_AIOCB_Proactor;
  ACE_POSIX_SIG_Proactor *  pImpl = new ACE_POSIX_SIG_Proactor;
#endif

  ACE_Proactor Proactor ( pImpl ,1 );

  ACE_Proactor::instance( & Proactor );


  MyTask  Task1 ;

  if (Task1.activate (THR_NEW_LWP, nThreads ) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "main"), -1);
    }

  Sender sender;
  ACE_Asynch_Acceptor<Receiver> acceptor;

  int Rc = -1 ;

  if ( host == NULL ) // Acceptor
    {
      // Simplify , initial read with  zero size
      Rc = acceptor.open (ACE_INET_Addr (port),0,1);

    }
  else
    {
      Rc = sender.open (host, port);
    }

  if ( Rc == 0 )
    {
      char c ;
      cout << "Press any key to stop and exit=>\n" << flush ;
      cin.clear ();
      cin >> c ;
    }


问题


面经


文章

微信
公众号

扫码关注公众号