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


C++ LogSink::dbg方法代码示例

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


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

示例1: connect

  int DNS::connect( const std::string& host, unsigned short port, const LogSink& logInstance )
  {
    int fd = getSocket();
    if( fd < 0 )
      return fd;

    struct hostent* h;
    if( ( h = gethostbyname( host.c_str() ) ) == 0 )
    {
      cleanup();
      return -ConnDnsError;
    }

    struct sockaddr_in target;
    target.sin_family = AF_INET;
    target.sin_port = htons( port );

    if( h->h_length != sizeof( struct in_addr ) )
    {
      cleanup();
      return -ConnDnsError;
    }
    else
    {
      memcpy( &target.sin_addr, h->h_addr, sizeof( struct in_addr ) );
    }

#ifndef _WIN32_WCE
    std::ostringstream oss;
#endif

    memset( target.sin_zero, '\0', 8 );
    if( ::connect( fd, (struct sockaddr *)&target, sizeof( struct sockaddr ) ) == 0 )
    {
#ifndef _WIN32_WCE
      oss << "connecting to " << host.c_str()
          << " (" << inet_ntoa( target.sin_addr ) << ":" << port << ")";
      logInstance.dbg( LogAreaClassDns, oss.str() );
#endif
      return fd;
    }

#ifndef _WIN32_WCE
    oss << "connection to " << host.c_str()
         << " (" << inet_ntoa( target.sin_addr ) << ":" << port << ") failed";
    logInstance.dbg( LogAreaClassDns, oss.str() );
#endif

    closeSocket( fd );
    return -ConnConnectionRefused;
  }
开发者ID:RankoR,项目名称:mqutim,代码行数:51,代码来源:dns.cpp

示例2: connect

  int DNS::connect( const std::string& host, int port, const LogSink& logInstance )
  {
    struct addrinfo hints, *servinfo, *p;
    int rv = 0;
    int fd = 0;

    memset( &hints, 0, sizeof( hints ) );
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    if( ( rv = getaddrinfo( host.c_str(), util::int2string( port ).c_str(), &hints, &servinfo ) ) != 0 )
    {
      logInstance.dbg( LogAreaClassDns, "getaddrinfo() failed for " + host + "." );
      return -ConnDnsError;
    }

    for( p = servinfo; p != 0; p = p->ai_next )
    {
      if( ( fd = getSocket( p->ai_family, p->ai_socktype, p->ai_protocol, logInstance ) ) == -1 )
      {
        continue;
      }

      if( ::connect( fd, p->ai_addr, p->ai_addrlen ) == -1 )
      {
        closeSocket( fd, logInstance );
        continue;
      }

      break;
    }

    if( p == 0 )
    {
      freeaddrinfo( servinfo );
      std::string message = "Connection to " + host + ":" + util::int2string( port ) + " failed. "
#if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
      "WSAGetLastError: " + util::int2string( ::WSAGetLastError() );
#else
      "errno: " + util::int2string( errno ) + ": " + strerror( errno );
#endif
      logInstance.dbg( LogAreaClassDns, message );
      return -ConnConnectionRefused;
    }

    freeaddrinfo( servinfo );
    return fd;
  }
开发者ID:liuzhuan23,项目名称:testcode-byWinTrust,代码行数:48,代码来源:dns.cpp

示例3: getSocket

  int DNS::getSocket( int af, int socktype, int proto, const LogSink& logInstance )
  {
#if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
    SOCKET fd;
#else
    int fd;
#endif
    if( ( fd = socket( af, socktype, proto ) ) == INVALID_SOCKET )
    {
      std::string message = "getSocket( "
          + util::int2string( af ) + ", "
          + util::int2string( socktype ) + ", "
          + util::int2string( proto )
          + " ) failed. "
#if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
          "WSAGetLastError: " + util::int2string( ::WSAGetLastError() );
#else
          "errno: " + util::int2string( errno ) + ": " + strerror( errno );
#endif
      logInstance.dbg( LogAreaClassDns, message );

      cleanup( logInstance );
      return -ConnConnectionRefused;
    }

#ifdef HAVE_SETSOCKOPT
    int timeout = 5000;
    int reuseaddr = 1;
    setsockopt( fd, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof( timeout ) );
    setsockopt( fd, SOL_SOCKET, SO_REUSEADDR, (char*)&reuseaddr, sizeof( reuseaddr ) );
#endif

    return (int)fd;
  }
开发者ID:liuzhuan23,项目名称:testcode-byWinTrust,代码行数:34,代码来源:dns.cpp

示例4: cleanup

  void DNS::cleanup( const LogSink& logInstance )
  {
#if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
    if( WSACleanup() != 0 )
    {
      logInstance.dbg( LogAreaClassDns, "WSACleanup() failed. WSAGetLastError: "
          + util::int2string( ::WSAGetLastError() ) );
    }
#else
    (void)logInstance;
#endif
  }
开发者ID:liuzhuan23,项目名称:testcode-byWinTrust,代码行数:12,代码来源:dns.cpp

示例5: closeSocket

  void DNS::closeSocket( int fd, const LogSink& logInstance )
  {
#if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
    int result = closesocket( fd );
#else
    int result = close( fd );
#endif

    if( result != 0 )
    {
      std::string message = "closeSocket() failed. "
#if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
          "WSAGetLastError: " + util::int2string( ::WSAGetLastError() );
#else
          "errno: " + util::int2string( errno ) + ": " + strerror( errno );
#endif
      logInstance.dbg( LogAreaClassDns, message );
    }
  }
开发者ID:liuzhuan23,项目名称:testcode-byWinTrust,代码行数:19,代码来源:dns.cpp

示例6: resolve

 void DNS::resolve( struct addrinfo** res, const std::string& service, const std::string& proto,
                    const std::string& domain, const LogSink& logInstance )
 {
   logInstance.dbg( LogAreaClassDns, "Resolving: _" +  service + "._" + proto + "." + domain );
   struct addrinfo hints;
   if( proto == "tcp" )
     hints.ai_socktype = SOCK_STREAM;
   else if( proto == "udp" )
     hints.ai_socktype = SOCK_DGRAM;
   else
   {
     logInstance.err( LogAreaClassDns, "Unknown/Invalid protocol: " + proto );
   }
   memset( &hints, '\0', sizeof( hints ) );
   hints.ai_flags = AI_ADDRCONFIG | AI_CANONNAME;
   hints.ai_socktype = SOCK_STREAM;
   int e = getaddrinfo( domain.c_str(), service.c_str(), &hints, res );
   if( e )
     logInstance.err( LogAreaClassDns, "getaddrinfo() failed" );
 }
开发者ID:RankoR,项目名称:mqutim,代码行数:20,代码来源:dns.cpp


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