void SocketAddress::init(const std::string& hostAndPort) { poco_assert (!hostAndPort.empty()); std::string socketHost; std::string socketPort; std::string::const_iterator it = hostAndPort.begin(); std::string::const_iterator end = hostAndPort.end(); #if defined(POCO_OS_FAMILY_UNIX) if (*it == '/') { newLocal(hostAndPort); return; } #endif if (*it == '[') { ++it; while (it != end && *it != ']') socketHost += *it++; if (it == end) throw InvalidArgumentException("Malformed IPv6 address"); ++it; } else { while (it != end && *it != ':') socketHost += *it++; } if (it != end && *it == ':') { ++it; while (it != end) socketPort += *it++; } else throw InvalidArgumentException("Missing port number"); init(socketHost, resolveService(socketPort)); }
Id FuncEmitter::allocUnnamedLocal() { ++m_activeUnnamedLocals; if (m_activeUnnamedLocals > m_numUnnamedLocals) { newLocal(); ++m_numUnnamedLocals; } return m_numLocals - m_numUnnamedLocals + (m_activeUnnamedLocals - 1); }
void FuncEmitter::allocVarId(const StringData* name) { ASSERT(name != NULL); // Unnamed locals are segregated (they all come after the named locals). ASSERT(m_numUnnamedLocals == 0); UNUSED Id id; if (m_localNames.find(name) == m_localNames.end()) { id = newLocal(); ASSERT(id == (int)m_localNames.size()); m_localNames.add(name, name); } }
SocketAddress::SocketAddress(const SocketAddress& socketAddress) { if (socketAddress.family() == IPv4) newIPv4(reinterpret_cast<const sockaddr_in*>(socketAddress.addr())); #if defined(POCO_HAVE_IPv6) else if (socketAddress.family() == IPv6) newIPv6(reinterpret_cast<const sockaddr_in6*>(socketAddress.addr())); #endif #if defined(POCO_OS_FAMILY_UNIX) else if (socketAddress.family() == UNIX_LOCAL) newLocal(reinterpret_cast<const sockaddr_un*>(socketAddress.addr())); #endif }
void SocketAddress::init(Family fam, const std::string& address) { #if defined(POCO_OS_FAMILY_UNIX) if (fam == UNIX_LOCAL) { newLocal(address); } else #endif { init(address); if (fam != family()) throw Poco::InvalidArgumentException("address does not fit family"); } }
SocketAddress::SocketAddress(const struct sockaddr* sockAddr, poco_socklen_t addressLength) { if (addressLength == sizeof(struct sockaddr_in) && sockAddr->sa_family == AF_INET) newIPv4(reinterpret_cast<const struct sockaddr_in*>(sockAddr)); #if defined(POCO_HAVE_IPv6) else if (addressLength == sizeof(struct sockaddr_in6) && sockAddr->sa_family == AF_INET6) newIPv6(reinterpret_cast<const struct sockaddr_in6*>(sockAddr)); #endif #if defined(POCO_OS_FAMILY_UNIX) else if (addressLength > 0 && addressLength <= sizeof(struct sockaddr_un) && sockAddr->sa_family == AF_UNIX) newLocal(reinterpret_cast<const sockaddr_un*>(sockAddr)); #endif else throw Poco::InvalidArgumentException("Invalid address length or family passed to SocketAddress()"); }
SocketAddress& SocketAddress::operator = (const SocketAddress& socketAddress) { if (&socketAddress != this) { destruct(); if (socketAddress.family() == IPv4) newIPv4(reinterpret_cast<const sockaddr_in*>(socketAddress.addr())); #if defined(POCO_HAVE_IPv6) else if (socketAddress.family() == IPv6) newIPv6(reinterpret_cast<const sockaddr_in6*>(socketAddress.addr())); #endif #if defined(POCO_OS_FAMILY_UNIX) else if (socketAddress.family() == UNIX_LOCAL) newLocal(reinterpret_cast<const sockaddr_un*>(socketAddress.addr())); #endif } return *this; }