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


C++ SocketAddress::Lookup方法代码示例

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


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

示例1: Create

bool
SocketDescriptor::CreateConnectUDP(const char *host, const char *port)
{
  const int socktype = SOCK_DGRAM;

  SocketAddress address;
  if (!address.Lookup(host, port, socktype))
    return false;

  return Create(address.GetFamily(), socktype, 0) && Connect(address);
}
开发者ID:MindMil,项目名称:XCSoar,代码行数:11,代码来源:SocketDescriptor.cpp

示例2: Set

bool
TCPClientPort::Connect(const char *host, unsigned port)
{
  NarrowString<32> service;
  service.UnsafeFormat("%u", port);

  SocketAddress address;
  if (!address.Lookup(host, service, AF_INET))
    return false;

  SocketDescriptor s;
  if (!s.CreateTCP())
    return false;

#ifdef HAVE_POSIX
  s.SetNonBlocking();
#endif

  if (s.Connect(address)) {
#ifdef HAVE_POSIX
    s.SetBlocking();
#endif
    Set(std::move(s));
    return true;
  }

#ifdef HAVE_POSIX
  if (errno == EINPROGRESS) {
    connecting = std::move(s);
    io_thread->LockAdd(connecting.Get(), Poll::WRITE, *this);
    return true;
  }
#endif

  return false;
}
开发者ID:DRIZO,项目名称:xcsoar,代码行数:36,代码来源:TCPClientPort.cpp

示例3: args

int
main(int argc, char *argv[])
{
  Args args(argc, argv, "HOST KEY");
  const char *host = args.ExpectNext();
  const char *key = args.ExpectNext();

  SocketAddress address;
  if (!address.Lookup(host, "5597", SOCK_DGRAM)) {
    fprintf(stderr, "Failed to look up: %s\n", host);
    return EXIT_FAILURE;
  }

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
  InitialiseIOThread();
#endif

  SkyLinesTracking::Client client;

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
  client.SetIOThread(io_thread);

  Handler handler;
  client.SetHandler(&handler);
#endif

  client.SetKey(ParseUint64(key, NULL, 16));
  if (!client.Open(address)) {
    fprintf(stderr, "Failed to create client\n");
    return EXIT_FAILURE;
  }

  if (args.IsEmpty() || StringIsEqual(args.PeekNext(), "fix")) {
    NMEAInfo basic;
    basic.Reset();
    basic.UpdateClock();
    basic.time = fixed(1);
    basic.time_available.Update(basic.clock);

    return client.SendFix(basic) ? EXIT_SUCCESS : EXIT_FAILURE;
  } else if (StringIsEqual(args.PeekNext(), "ping")) {
    client.SendPing(1);

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
    handler.Wait();
#endif
  } else if (StringIsEqual(args.PeekNext(), "traffic")) {
    client.SendTrafficRequest(true, true);

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
    handler.Wait();
#endif
  } else {
    DebugReplay *replay = CreateDebugReplay(args);
    if (replay == NULL)
      return EXIT_FAILURE;

    while (replay->Next()) {
      client.SendFix(replay->Basic());
      usleep(100000);
    }
  }

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
  client.Close();
  DeinitialiseIOThread();
#endif

  return EXIT_SUCCESS;
}
开发者ID:MindMil,项目名称:XCSoar,代码行数:70,代码来源:RunSkyLinesTracking.cpp


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