本文整理汇总了C++中HostAddress类的典型用法代码示例。如果您正苦于以下问题:C++ HostAddress类的具体用法?C++ HostAddress怎么用?C++ HostAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HostAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: noteHostBad
void HostCatcher::noteHostBad( HostAddress * inHost ) {
mLock->lock();
// make sure this host already exists in our list
char exists = false;
HostAddress *foundHost = NULL;
int numHosts = mHostVector->size();
for( int i=0; i<numHosts; i++ ) {
HostAddress *otherHost = *( mHostVector->getElement( i ) );
if( otherHost->equals( inHost ) ) {
exists = true;
// delete the host that we've found
mHostVector->deleteElement( i );
foundHost = otherHost;
// jump out of loop
i = numHosts;
}
}
if( exists ) {
delete foundHost;
//mHostVector->push_back( foundHost );
}
mLock->unlock();
}
示例2:
HostAddress * HostCatcher::getHost( ) {
mLock->lock();
int numHosts = mHostVector->size();
if( numHosts == 0 ) {
mLock->unlock();
return NULL;
}
// remove random host from queue
int index = mRandSource->getRandomBoundedInt( 0, numHosts - 1 );
HostAddress *host = *( mHostVector->getElement( index ) );
mHostVector->deleteElement( index );
// add host to end of queue
mHostVector->push_back( host );
HostAddress *hostCopy = host->copy();
mLock->unlock();
return hostCopy;
}
示例3: isListenAddressValid
static Boolean isListenAddressValid(const String value_)
{
if(value_.size() == 0 )
{
return false;
}
Boolean isIpListTrue = true;
Array<String> interfaces = DefaultPropertyOwner::parseAndGetListenAddress(
value_);
HostAddress theAddress;
for(Uint32 i = 0, m = interfaces.size(); i < m; ++i)
{
if(!theAddress.setHostAddress(interfaces[i]))
{
isIpListTrue = false;
throw InvalidListenAddressPropertyValue(
"listenAddress", interfaces[i]);
break;
}
}
return isIpListTrue;
}
示例4: gethostname
HostAddress *HostAddress::getLocalAddress() {
int bufferLength = 200;
char *buffer = new char[ bufferLength ];
gethostname( buffer, bufferLength );
char *name = stringDuplicate( buffer );
delete [] buffer;
// this class will destroy name for us
HostAddress *nameAddress = new HostAddress( name, 0 );
HostAddress *fullAddress = nameAddress->getNumericalAddress();
if( fullAddress != NULL ) {
delete nameAddress;
return fullAddress;
}
else {
return nameAddress;
}
}
示例5: handleSystemCmdMsg
void TUIServerApp::handleSystemCmdMsg(HostEvent * msg) {
HostAddress address = msg->getAddress();
SystemCmdMsg * msg2 = static_cast<SystemCmdMsg *>(msg->getPayload());
const SystemCmd & systemCmd = msg2->getPayload();
address.setPortNr(systemCmd.getPortNr());
if (systemCmd.getCmd() == SystemCmd::requestConnection) {
TFDEBUG("SystemCmdMsg::RequestConnection: " << address);
this->outHostMsgDispatcher.addDstAddress(address);
if (this->usingMulticast) {
MulticastGroupInvitationMsg * event = new MulticastGroupInvitationMsg();
event->setPayload(this->multicastGroup);
this->outEventQueue.push(event);
}
{
{
GUIDEventTypeIDVectorMsg * event = new GUIDEventTypeIDVectorMsg();
event->setPayload(this->guidEventTypeIDVector);
this->outEventQueue.push(event);
}
{
AttachedObjectsMsg * event = new AttachedObjectsMsg();
event->setPayload(this->attachedObjects);
this->outEventQueue.push(event);
}
}
} else if (systemCmd.getCmd() == SystemCmd::removeConnection) {
TFDEBUG("SystemCmdMsg::RemoveConnection: " << address);
this->outHostMsgDispatcher.removeDstAddress(address);
}
}
示例6: fromString
HostAddress HostAddress::fromString(std::string str) {
HostAddress h;
h.address_str = str;
h.parse_string();
h.initialised = true;
return h;
}
示例7: getSectionByAddr
Byte BinaryImage::readNative1(Address addr) const
{
const BinarySection *section = getSectionByAddr(addr);
if (section == nullptr || section->getHostAddr() == HostAddress::INVALID) {
LOG_WARN("Invalid read at address %1: Address is not mapped to a section", addr);
return 0xFF;
}
HostAddress host = section->getHostAddr() - section->getSourceAddr() + addr;
return *reinterpret_cast<Byte *>(host.value());
}
示例8: while
void HostCatcher::addHost( HostAddress * inHost ) {
// convert to numerical form once and for all here
// (to avoid converting over and over in equals checks below)
HostAddress *numericalAddress = inHost->getNumericalAddress();
if( numericalAddress != NULL ) {
mLock->lock();
// make sure this host doesn't already exist in our list
char exists = false;
int numHosts = mHostVector->size();
for( int i=0; i<numHosts; i++ ) {
HostAddress *otherHost = *( mHostVector->getElement( i ) );
if( otherHost->equals( numericalAddress ) ) {
exists = true;
// jump out of loop
i = numHosts;
}
}
if( !exists ) {
mHostVector->push_back( numericalAddress->copy() );
}
while( mHostVector->size() > mMaxListSize ) {
// remove first host from queue
HostAddress *host = *( mHostVector->getElement( 0 ) );
mHostVector->deleteElement( 0 );
delete host;
}
mLock->unlock();
delete numericalAddress;
}
}
示例9: Connection
Connection(ProactorFile *socket, const HostAddress &addr):
mSrcSocket(socket), mDestSocket(nullptr), mRespForwardedPos(0), mCountOfEOF(0) {
mID = format("Connection(%d,%s)", socket->getFd(), addr.toString().c_str());
LOG("Connection(%s) established ...", getID());
mSrcSocket->readLine('\n', [this](bool eof, const char *buf, int n){ onReadRequestline(eof, buf, n); });
}
示例10: memset
bool Network::UdpSocket::bind(const HostAddress& address, uint16 port) {
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = address.toIPv4Address();
addr.sin_port = htons(port);
if (::bind(_fd, (struct sockaddr*)&addr, sizeof(addr)) == -1)
return (false);
return (true);
}
示例11: ConnectToHost
bool TcpSocket::ConnectToHost(const string& hostName,
const string& port,
IBamIODevice::OpenMode mode)
{
// create new address object with requested host name
HostAddress hostAddress;
hostAddress.SetAddress(hostName);
HostInfo info;
// if host name was IP address ("x.x.x.x" or IPv6 format)
// otherwise host name was 'plain-text' ("www.foo.bar")
// we need to look up IP address(es)
if ( hostAddress.HasIPAddress() )
info.SetAddresses( vector<HostAddress>(1, hostAddress) );
else
info = HostInfo::Lookup(hostName, port);
// attempt connection on requested port
return ConnectImpl(info, port, mode);
}
示例12: printf
HostAddress *HostAddress::getLocalAddress() {
// first make sure sockets are initialized
if( !Socket::isFrameworkInitialized() ) {
// try to init the framework
int error = Socket::initSocketFramework();
if( error == -1 ) {
printf( "initializing network socket framework failed\n" );
return NULL;
}
}
int bufferLength = 200;
char *buffer = new char[ bufferLength ];
gethostname( buffer, bufferLength );
char *name = stringDuplicate( buffer );
delete [] buffer;
// this class will destroy name for us
HostAddress *nameAddress = new HostAddress( name, 0 );
HostAddress *fullAddress = nameAddress->getNumericalAddress();
delete nameAddress;
return fullAddress;
}
示例13: receiver
/*---------------------------------------------------------------------*/
void receiver(Socket* socket)
{ HostAddress peer;
TextMessage msg(1024);
try
{
do
{
socket->Receive(peer, msg);
printf("[%s] msg=%s", peer.GetHost(), msg.GetBuffer());
}
while ( strcmp(msg.GetBuffer(), "bye\n") != 0 );
}
catch (Exception& err)
{
printf("[CHILD]");
err.PrintException();
}
catch (...)
{
fprintf(stderr, "Unknown error\n");
}
exit(0);
}
示例14: address
bool RedisProxy::run(const HostAddress& addr)
{
if (isRunning()) {
return false;
}
if (m_vipEnabled) {
TcpSocket sock = TcpSocket::createTcpSocket();
Logger::log(Logger::Message, "connect to vip address(%s:%d)...", m_vipAddress, addr.port());
if (!sock.connect(HostAddress(m_vipAddress, addr.port()))) {
Logger::log(Logger::Message, "set VIP [%s,%s]...", m_vipName, m_vipAddress);
int ret = NonPortable::setVipAddress(m_vipName, m_vipAddress, 0);
Logger::log(Logger::Message, "set_vip_address return %d", ret);
} else {
m_vipSocket = sock;
m_vipEvent.set(eventLoop(), sock.socket(), EV_READ, vipHandler, this);
m_vipEvent.active();
}
}
m_monitor->proxyStarted(this);
Logger::log(Logger::Message, "Start the %s on port %d", APP_NAME, addr.port());
RedisCommand cmds[] = {
{"HASHMAPPING", 11, -1, onHashMapping, NULL},
{"ADDKEYMAPPING", 13, -1, onAddKeyMapping, NULL},
{"DELKEYMAPPING", 13, -1, onDelKeyMapping, NULL},
{"SHOWMAPPING", 11, -1, onShowMapping, NULL},
{"POOLINFO", 8, -1, onPoolInfo, NULL},
{"SHUTDOWN", 8, -1, onShutDown, this}
};
RedisCommandTable::instance()->registerCommand(cmds, sizeof(cmds)/sizeof(RedisCommand));
return TcpServer::run(addr);
}
示例15: testToString_Invalid
void testToString_Invalid() {
HostAddress testling;
CPPUNIT_ASSERT_EQUAL(std::string("0.0.0.0"), testling.toString());
}