コード例 #1
0
ファイル: SocketAddress.cpp プロジェクト: 12307/poco
bool SocketAddress::operator < (const SocketAddress& socketAddress) const
{
	if (family() < socketAddress.family()) return true;
	if (family() > socketAddress.family()) return false;
	if (host() < socketAddress.host()) return true;
	if (host() > socketAddress.host()) return false;
	return (port() < socketAddress.port());
}
コード例 #2
0
ファイル: address.hpp プロジェクト: flixster/mesos
 // Returns the storage size (i.e., either sizeof(sockaddr_in) or
 // sizeof(sockaddr_in6) depending on the family) of this address.
 size_t size() const
 {
   switch (family()) {
     case AF_INET:
       return sizeof(sockaddr_in);
     default:
       ABORT("Unsupported family type: " + stringify(family()));
   }
 }
コード例 #3
0
ファイル: address.cpp プロジェクト: NeelamAggarwal/cpp-driver
int Address::port() const {
  if (family() == AF_INET) {
    return htons(addr_in()->sin_port);
  } else if (family() == AF_INET6) {
    return htons(addr_in6()->sin6_port);
  } else {
    assert(false);
    return -1;
  }
}
コード例 #4
0
bool GprsCodingScheme::isFamilyCompatible(GprsCodingScheme o) const
{
	if (*this == o)
		return true;

	if (family() == FAMILY_INVALID)
		return false;

	return family() == o.family();
}
コード例 #5
0
ファイル: SocketAddress.cpp プロジェクト: Kampbell/poco
bool SocketAddress::operator < (const SocketAddress& socketAddress) const
{
	if (family() < socketAddress.family()) return true;
	if (family() > socketAddress.family()) return false;
#if defined(POCO_OS_FAMILY_UNIX)
	if (family() == UNIX_LOCAL) return toString() < socketAddress.toString();
#endif
	if (host() < socketAddress.host()) return true;
	if (host() > socketAddress.host()) return false;
	return (port() < socketAddress.port());
}
コード例 #6
0
ファイル: address.cpp プロジェクト: runt18/libsourcey
std::string Address::toString() const
{
    std::string result;
    if (family() == Address::IPv6)
        result.append("[");
    result.append(host());
    if (family() == Address::IPv6)
        result.append("]");
    result.append(":");
    result.append(util::itostr<UInt16>(port()));
    return result;
}
コード例 #7
0
ファイル: SocketAddress.cpp プロジェクト: frankencode/fluxkit
uint64_t SocketAddress::networkPrefix() const
{
    uint64_t prefix = 0;
    if (family() == AF_INET) {
        prefix = endianGate(inet4Address_.sin_addr.s_addr);
    }
    else if (family() == AF_INET6) {
        uint8_t const *a = inet6Address_.sin6_addr.s6_addr;
        for (int i = 0; i < 8; ++i) {
            prefix <<= 8;
            prefix |= a[i];
        }
    }
    return prefix;
}
コード例 #8
0
ファイル: sockinet.cpp プロジェクト: Eric-De/voiceglue
int sockinetaddr::gethostname (char *hostname, size_t hostnameLen) const
{
  hostname[0] = '\0';

  if (sin_addr.s_addr == htonl(INADDR_ANY)) {
    if (::gethostname(hostname, hostnameLen) == -1) {
      SOCK_ERROR("sockinetaddr", "gethostname");
      hostname[0] = '\0';
      return -1;
    }
    return 0;
  }

  int hostErrno;
  struct hostent hostResult;
  char hostBuffer[4096];
  hostent* hp;
  if ((my_gethostbyaddr_r((const char*) &sin_addr, sizeof(sin_addr),
			  family(), &hostResult, hostBuffer, 2048, &hp,
			  &hostErrno) != 0) ||
      (hp == 0))
  {
    sockinetaddr::herror("gethostbyaddr");
    return -1;
  }
  if ((hp->h_name) && (strlen(hp->h_name) < hostnameLen)) {
    strcpy (hostname, hp->h_name);
    return 0;
  }
  return -1;
}
コード例 #9
0
void FontManager::initBasic()
{
    if(!defaultFont)
        defaultFont = new QFont();

    fontID = QFontDatabase::addApplicationFont(":/PressStart2P.ttf");
    fontID = QFontDatabase::addApplicationFont(":/JosefinSans-Regular.ttf");
    double_pixled = false;
    //Josefin Sans
    QString family("Monospace");

    if(!QFontDatabase::applicationFontFamilies(fontID).isEmpty())
        family = QFontDatabase::applicationFontFamilies(fontID).at(0);

    defaultFont->setFamily(family);//font.setWeight(14);
    //#ifdef __APPLE__
    //  defaultFont->setPixelSize(16);
    //#else
    defaultFont->setPixelSize(16);
    //#endif
    defaultFont->setStyleStrategy(QFont::PreferBitmap);
    defaultFont->setLetterSpacing(QFont::AbsoluteSpacing, 1);
    //defaultFont = buildFont_RW(":/PressStart2P.ttf", 14);
    isInit = true;
}
コード例 #10
0
ファイル: tcpclient.cpp プロジェクト: AsamQi/libsourcey
void TCPClient::handleConnectResponse(const stun::Message& response)
{
	// If the connection is successfully established, the client will
	// receive a success response.  That response will contain a
	// CONNECTION-ID attribute.  The client MUST initiate a new TCP
	// connection to the server, utilizing the same destination transport
	// address to which the control connection was established.  This
	// connection MUST be made using a different local transport address.
	// Authentication of the client by the server MUST use the same method
	// and credentials as for the control connection.  Once established, the
	// client MUST send a ConnectionBind request over the new connection.
	// That request MUST include the CONNECTION-ID attribute, echoed from
	// the Connect Success response.  When a response to the ConnectionBind
	// request is received, if it is a success, the TCP connection on which
	// it was sent is called the client data connection corresponding to the
	// peer.
	//
	
	auto transaction = reinterpret_cast<stun::Transaction*>(response.opaque);
	auto peerAttr = transaction->request().get<stun::XorPeerAddress>();
	if (!peerAttr || (peerAttr && peerAttr->family() != 1)) {
		assert(0);
		return;
	}

	auto connAttr = response.get<stun::ConnectionID>();
	if (!connAttr) {
		assert(0);
		return;
	}

	createAndBindConnection(connAttr->value(), peerAttr->address());
}
コード例 #11
0
ファイル: endpoint.cpp プロジェクト: klupek/cppcms
std::string endpoint::ip() const
{
	switch(family()) {
	case pf_inet:
		{
#ifndef BOOSTER_WIN32
			char buf[INET_ADDRSTRLEN+1] = {0};
			char const *res = ::inet_ntop(AF_INET,&d->sa.in.sin_addr,buf,sizeof(buf));
			if(res)
				return std::string(res);
			throw_invalid();
#else
			std::ostringstream tmp;
			tmp.imbue(std::locale::classic());
			unsigned char const *p = reinterpret_cast<unsigned char const *>(&d->sa.in.sin_addr);
			tmp << int(p[0]) <<"." << int(p[1]) <<"."<<int(p[2]) <<"." << int(p[3]);
			return tmp.str();
#endif
		}
		break;
#ifndef BOOSTER_AIO_NO_PF_INET6
	case pf_inet6:
		{
			char buf[INET6_ADDRSTRLEN+1] = {0};
			char const *res = ::inet_ntop(AF_INET6,&d->sa.in6.sin6_addr,buf,sizeof(buf));
			if(res)
				return std::string(res);
			throw_invalid();
		}
		break;
#endif
	default:
		throw_invalid();
	}
}
コード例 #12
0
ファイル: test_family_collect.cpp プロジェクト: simonsysu/tfs
    TEST_F(FamilyCollectTest, get_members)
    {
      int64_t family_id = 100;
      int32_t family_aid_info = 0;
      SET_DATA_MEMBER_NUM(family_aid_info, 5);
      SET_CHECK_MEMBER_NUM(family_aid_info, 2);
      SET_MARSHALLING_TYPE(family_aid_info, 1);
      SET_MASTER_INDEX(family_aid_info, 5);
      FamilyCollect family(family_id, family_aid_info, 0);
      for (int32_t i = 0; i <7; i++)
      {
        EXPECT_EQ(family.add((100+i), 1), TFS_SUCCESS);
      }
      family.dump(TBSYS_LOG_LEVEL_DEBUG);
      std::pair<uint32_t , int32_t> members[7];
      ArrayHelper<std::pair<uint32_t , int32_t> > helper(7, members);

      family.get_members(helper);
      std::ostringstream str;
      str <<"family_id: " << family.family_id_ <<",data_member_num: " << family.get_data_member_num() << ",check_member_num: "<<
          family.get_check_member_num() << ",code_type:" << family.get_code_type() << ",master_index: " << family.get_master_index();
      str << ", data_members: ";
      int32_t i = 0;
      for (i = 0; i < family.get_data_member_num(); ++i)
      {
        str <<members[i].first <<":" << members[i].second<< ",";
      }
      str << ", check_members: ";
      const int32_t MEMBER_NUM = family.get_data_member_num() + family.get_check_member_num();
      for (; i < MEMBER_NUM; ++i)
      {
          str <<members[i].first <<":" << members[i].second<< ",";
      }
      TBSYS_LOG(DEBUG, "%s", str.str().c_str());
    }
コード例 #13
0
ファイル: SocketAddress.cpp プロジェクト: frankencode/fluxkit
int SocketAddress::addrLen() const
{
    int len = 0;
    if (family() == AF_INET)
        len = sizeof(sockaddr_in);
    else if (family() == AF_INET6)
        len = sizeof(sockaddr_in6);
    else if (family() == AF_LOCAL)
        len = sizeof(sockaddr_un);
    else {
        len = sizeof(sockaddr_in);
        if (len < int(sizeof(sockaddr_in6))) len = sizeof(sockaddr_in6);
        if (len < int(sizeof(sockaddr_un))) len = sizeof(sockaddr_un);
    }
    return len;
}
コード例 #14
0
ファイル: devip-posix.c プロジェクト: 0intro/vx32
int
so_socket(int type, unsigned char *addr)
{
	int fd, one;

	switch(type) {
	default:
		error("bad protocol type");
	case S_TCP:
		type = SOCK_STREAM;
		break;
	case S_UDP:
		type = SOCK_DGRAM;
		break;
	}

	fd = socket(family(addr), type, 0);
	if(fd < 0)
		oserror();

	one = 1;
	if(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&one, sizeof(one)) > 0){
		oserrstr();
		print("setsockopt: %r");
	}

	return fd;
}
コード例 #15
0
ファイル: devip-posix.c プロジェクト: 0intro/vx32
void
so_bind(int fd, int su, unsigned short port, unsigned char *addr)
{
	int i, one;
	struct sockaddr_storage ss;

	one = 1;
	if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&one, sizeof(one)) < 0){
		oserrstr();
		print("setsockopt: %r");
	}

	if(su) {
		for(i = 600; i < 1024; i++) {
			memset(&ss, 0, sizeof(ss));
			ss.ss_family = family(addr);

			switch(ss.ss_family){
			case AF_INET:
				((struct sockaddr_in*)&ss)->sin_port = i;
				break;
			case AF_INET6:
				((struct sockaddr_in6*)&ss)->sin6_port = i;
				break;
			}

			if(bind(fd, (struct sockaddr*)&ss, addrlen(&ss)) >= 0)	
				return;
		}
		oserror();
	}

	memset(&ss, 0, sizeof(ss));
	ss.ss_family = family(addr);

	switch(ss.ss_family){
	case AF_INET:
		hnputs(&((struct sockaddr_in*)&ss)->sin_port, port);
		break;
	case AF_INET6:
		hnputs(&((struct sockaddr_in6*)&ss)->sin6_port, port);
		break;
	}

	if(bind(fd, (struct sockaddr*)&ss, addrlen(&ss)) < 0)
		oserror();
}
コード例 #16
0
ファイル: IPAddress.cpp プロジェクト: RobertoMalatesta/of-1
IPAddress IPAddress::operator ~ () const
{
	if (family() == IPv4)
	{
		IPv4AddressImpl self(this->pImpl()->addr());
		return IPAddress((~self).addr(), sizeof(struct in_addr));
	}
#if defined(POCO_HAVE_IPv6)
	else if (family() == IPv6)
	{
		const IPv6AddressImpl self(pImpl()->addr(), pImpl()->scope());
        const IPv6AddressImpl r = ~self;
		return IPAddress(r.addr(), sizeof(struct in6_addr), r.scope());
	}
#endif
	else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
}
コード例 #17
0
ファイル: ip_resolver.cpp プロジェクト: ming-hai/libzmq
socklen_t zmq::ip_addr_t::sockaddr_len () const
{
    if (family () == AF_INET6) {
        return sizeof (ipv6);
    } else {
        return sizeof (ipv4);
    }
}
コード例 #18
0
ファイル: ip_resolver.cpp プロジェクト: ming-hai/libzmq
void zmq::ip_addr_t::set_port (uint16_t port)
{
    if (family () == AF_INET6) {
        ipv6.sin6_port = htons (port);
    } else {
        ipv4.sin_port = htons (port);
    }
}
コード例 #19
0
ファイル: address.cpp プロジェクト: NeelamAggarwal/cpp-driver
int Address::compare(const Address& a) const {
  if (family() != a.family()) {
    return family() < a.family() ? -1 : 1;
  }
  if (family() == AF_INET) {
    if (addr_in()->sin_addr.s_addr != a.addr_in()->sin_addr.s_addr) {
      return addr_in()->sin_addr.s_addr < a.addr_in()->sin_addr.s_addr ? -1 : 1;
    }
  } else if (family() == AF_INET6) {
    return memcmp(&(addr_in6()->sin6_addr), &(a.addr_in6()->sin6_addr),
                  sizeof(addr_in6()->sin6_addr));
  } else {
    assert(false);
    return -1;
  }
  return 0;
}
コード例 #20
0
ファイル: ip_resolver.cpp プロジェクト: ming-hai/libzmq
uint16_t zmq::ip_addr_t::port () const
{
    if (family () == AF_INET6) {
        return ntohs (ipv6.sin6_port);
    } else {
        return ntohs (ipv4.sin_port);
    }
}
コード例 #21
0
ファイル: Font.cpp プロジェクト: mikedougherty/webkit
Font::Font(const FontDescription& fd, short letterSpacing, short wordSpacing) 
    : m_fontDescription(fd)
    , m_letterSpacing(letterSpacing)
    , m_wordSpacing(wordSpacing)
    , m_isPlatformFont(false)
    , m_needsTranscoding(fontTranscoder().needsTranscoding(family().family().string()))
{
}
コード例 #22
0
TEST(WrapObjects, Insert)
{
    VkInstance instance = VK_NULL_HANDLE;
    VkResult result = vkCreateInstance(VK::InstanceCreateInfo(), VK_NULL_HANDLE, &instance);
    ASSERT_EQ(result, VK_SUCCESS);

    uint32_t physicalCount = 0;
    result = vkEnumeratePhysicalDevices(instance, &physicalCount, nullptr);
    ASSERT_EQ(result, VK_SUCCESS);
    ASSERT_GT(physicalCount, 0u);

    std::unique_ptr<VkPhysicalDevice[]> physical(new VkPhysicalDevice[physicalCount]);
    result = vkEnumeratePhysicalDevices(instance, &physicalCount, physical.get());
    ASSERT_EQ(result, VK_SUCCESS);
    ASSERT_GT(physicalCount, 0u);

    for(uint32_t p = 0; p < physicalCount; ++p)
    {
        uint32_t familyCount = 0;
        vkGetPhysicalDeviceQueueFamilyProperties(physical[p], &familyCount, nullptr);
        ASSERT_EQ(result, VK_SUCCESS);
        ASSERT_GT(familyCount, 0u);

        std::unique_ptr<VkQueueFamilyProperties[]> family(new VkQueueFamilyProperties[familyCount]);
        vkGetPhysicalDeviceQueueFamilyProperties(physical[p], &familyCount, family.get());
        ASSERT_EQ(result, VK_SUCCESS);
        ASSERT_GT(familyCount, 0u);

        for(uint32_t q = 0; q < familyCount; ++q)
        {
            if(~family[q].queueFlags & VK_QUEUE_GRAPHICS_BIT)
            {
                continue;
            }

            float const priorities[] = {0.0f}; // Temporary required due to MSVC bug.
            VkDeviceQueueCreateInfo const queueInfo[1]
            {
                VK::DeviceQueueCreateInfo().
                    queueFamilyIndex(q).
                    queueCount(1).
                    pQueuePriorities(priorities)
            };

            auto const deviceInfo = VK::DeviceCreateInfo().
                queueCreateInfoCount(1).
                pQueueCreateInfos(queueInfo);

            VkDevice device;
            result = vkCreateDevice(physical[p], deviceInfo, nullptr, &device);
            ASSERT_EQ(result, VK_SUCCESS);

            vkDestroyDevice(device, nullptr);
        }
    }

    vkDestroyInstance(instance, nullptr);
}
コード例 #23
0
nsresult
nsSystemFontsGTK2::GetSystemFontInfo(GtkWidget *aWidget, nsString *aFontName,
                                     gfxFontStyle *aFontStyle) const
{
#ifdef MOZ_PANGO
    GtkSettings *settings = gtk_widget_get_settings(aWidget);

    aFontStyle->style       = FONT_STYLE_NORMAL;

    gchar *fontname;
    g_object_get(settings, "gtk-font-name", &fontname, NULL);

    PangoFontDescription *desc;
    desc = pango_font_description_from_string(fontname);

    aFontStyle->systemFont = PR_TRUE;

    g_free(fontname);

    NS_NAMED_LITERAL_STRING(quote, "\"");
    NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
    *aFontName = quote + family + quote;

    aFontStyle->weight = pango_font_description_get_weight(desc);

    // FIXME: Set aFontStyle->stretch correctly!
    aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;

    float size = float(pango_font_description_get_size(desc)) / PANGO_SCALE;

    // |size| is now either pixels or pango-points (not Mozilla-points!)

    if (!MOZ_pango_font_description_get_size_is_absolute(desc)) {
        // |size| is in pango-points, so convert to pixels.
        size *= float(gfxPlatformGtk::GetDPI()) / POINTS_PER_INCH_FLOAT;
    }

    // |size| is now pixels

    aFontStyle->size = size;
  
    pango_font_description_free(desc);

#else
    /* FIXME: DFB FT2 Hardcoding the system font info for now.. */
    aFontStyle->style       = FONT_STYLE_NORMAL;
    aFontStyle->systemFont = PR_TRUE;

    NS_NAMED_LITERAL_STRING(fontname, "\"Sans\"");
    *aFontName = fontname;
    aFontStyle->weight = 400;
    aFontStyle->size = 40/3;

#endif

    return NS_OK;
}
コード例 #24
0
ファイル: Font.cpp プロジェクト: mikedougherty/webkit
Font::Font(const Font& other)
    : m_fontDescription(other.m_fontDescription)
    , m_fontList(other.m_fontList)
    , m_letterSpacing(other.m_letterSpacing)
    , m_wordSpacing(other.m_wordSpacing)
    , m_isPlatformFont(other.m_isPlatformFont)
    , m_needsTranscoding(fontTranscoder().needsTranscoding(family().family().string()))
{
}
コード例 #25
0
void QtNativeFont::commit() const
{
    d->font.setFamily(family());
    d->font.setPointSizeF(size());
    d->font.setStyle(style() == Italic? QFont::StyleItalic : QFont::StyleNormal);
    d->font.setWeight(weight());

    d->metrics.reset(new QFontMetrics(d->font));
}
コード例 #26
0
ファイル: address.cpp プロジェクト: NeelamAggarwal/cpp-driver
uint8_t Address::to_inet(uint8_t* data) const {
  if (family() == AF_INET) {
    memcpy(data, &addr_in()->sin_addr, 4);
    return 4;
  } else {
    memcpy(data, &addr_in6()->sin6_addr, 16);
    return 16;
  }
}
コード例 #27
0
void CElcNonWndButton::Draw(PVOID pvGraphics)
{
	if (!pvGraphics)
		return;

	Rect rect(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height());

	// draw background image 
	if (m_background.background.pImage) {
		thePainter.DrawImage(pvGraphics,
			&m_background.background,
			&rect,
			m_state,
			1,
			NULL);
	}

	// draw icon
	if (m_icon.pImage) {
		thePainter.DrawImage(pvGraphics,
			&m_icon,
			&rect,
			m_state,
			1,
			NULL);
	}

	if (!m_strText.IsEmpty()) {
		LOGFONT lf = {0};
		m_ftText.GetLogFont(&lf);

		FontFamily family(lf.lfFaceName);
		Font ftText(&family, 9);

		StringFormat stringfmt;
		stringfmt.SetAlignment(StringAlignmentCenter);
		stringfmt.SetLineAlignment(StringAlignmentCenter);
		stringfmt.SetHotkeyPrefix(HotkeyPrefixHide);

		Color crText;
		crText.SetFromCOLORREF(m_background.crTextNormal);

		RectF rcText;
		rcText.X = (REAL)m_rect.left;
		rcText.Y = (REAL)m_rect.top + 4;
		rcText.Width = (REAL)m_rect.Width();
		rcText.Height = (REAL)m_rect.Height();

		((Graphics *)pvGraphics)->DrawString(m_strText, 
			-1, 
			&ftText, 
			rcText, 
			&stringfmt, 
			&SolidBrush(crText));
	}
}
コード例 #28
0
ファイル: Font.cpp プロジェクト: mikedougherty/webkit
Font::Font(const FontPlatformData& fontData, bool isPrinterFont)
    : m_fontList(FontFallbackList::create())
    , m_letterSpacing(0)
    , m_wordSpacing(0)
    , m_isPlatformFont(true)
    , m_needsTranscoding(fontTranscoder().needsTranscoding(family().family().string()))
{
    m_fontDescription.setUsePrinterFont(isPrinterFont);
    m_fontList->setPlatformFont(fontData);
}
コード例 #29
0
ファイル: address.cpp プロジェクト: NeelamAggarwal/cpp-driver
std::string Address::to_string(bool with_port) const {
  std::stringstream ss;
  char host[INET6_ADDRSTRLEN + 1] = {'\0'};
  if (family() == AF_INET) {
    uv_ip4_name(const_cast<struct sockaddr_in*>(addr_in()), host,
                INET_ADDRSTRLEN);
    ss << host;
    if (with_port) ss << ":" << port();
  } else if (family() == AF_INET6) {
    uv_ip6_name(const_cast<struct sockaddr_in6*>(addr_in6()), host,
                INET6_ADDRSTRLEN);
    if (with_port) ss << "[";
    ss << host;
    if (with_port) ss << "]:" << port();
  } else {
    assert(false);
  }
  return ss.str();
}
コード例 #30
0
ファイル: FontManager.cpp プロジェクト: mariuz/haiku
FontFamily*
FontManager::_FindFamily(const char* name) const
{
	if (name == NULL)
		return NULL;

	FontFamily family(name, 0);
	return const_cast<FontFamily*>(fFamilies.BinarySearch(family,
		compare_font_families));
}