void Loader::servePendingRequests(Priority minimumPriority) { if (m_isSuspendingPendingRequests) return; m_requestTimer.stop(); m_nonHTTPProtocolHost->servePendingRequests(minimumPriority); Vector<Host*> hostsToServe; m_hosts.checkConsistency(); HostMap::iterator i = m_hosts.begin(); HostMap::iterator end = m_hosts.end(); for (;i != end; ++i) hostsToServe.append(i->second.get()); for (unsigned n = 0; n < hostsToServe.size(); ++n) { Host* host = hostsToServe[n]; if (host->hasRequests()) host->servePendingRequests(minimumPriority); else if (!host->processingResource()){ AtomicString name = host->name(); m_hosts.remove(name.impl()); } } }
void AppBinding::Restart(const ValueList& args, KValueRef result) { Host* host = Host::GetInstance(); std::wstring cmdline(::UTF8ToWide(host->GetApplication()->GetExecutablePath())); STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); PROCESS_INFORMATION pi; ZeroMemory(&pi, sizeof(pi)); ::CreateProcessW(NULL, (LPWSTR) cmdline.c_str(), NULL, /*lpProcessAttributes*/ NULL, /*lpThreadAttributes*/ FALSE, /*bInheritHandles*/ NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); host->Exit(0); }
void ServerApp::Initialize() { ::printf("GatewayServer start.\n"); Network::Startup(); m_serverConfigManager.Initialize(); m_networkService.Initialize(1024, 8); const auto& gatewayConfig = m_serverConfigManager.GetGatewayConfig(); Host hostCG; hostCG.FromAddress(gatewayConfig.m_publicAddress); ListenSocketCG* listenSocketCG = new ListenSocketCG(); listenSocketCG->Retain(); listenSocketCG->SetLocalHost(hostCG); listenSocketCG->Listen(100); m_networkService.Manage(listenSocketCG); Host hostWG; hostWG.FromAddress(gatewayConfig.m_privateAddress); ListenSocketWG* listenSocketWG = new ListenSocketWG(); listenSocketWG->Retain(); listenSocketWG->SetLocalHost(hostWG); listenSocketWG->Listen(100); m_networkService.Manage(listenSocketWG); }
void Master::schedule_tasks() { log_debug("Scheduling %d tasks on %d slots...", ready_queue.size(), free_slots.size()); int scheduled = 0; TaskList deferred_tasks; while (ready_queue.size() > 0 && free_slots.size() > 0) { Task *task = ready_queue.top(); ready_queue.pop(); log_trace("Scheduling task %s", task->name.c_str()); bool match = false; for (SlotList::iterator s = free_slots.begin(); s != free_slots.end(); s++) { Slot *slot = *s; Host *host = slot->host; // If the task fits, schedule it if (host->can_run(task)) { log_trace("Matched task %s to slot %d on host %s", task->name.c_str(), slot->rank, host->name()); // Reserve the resources vector<cpu_t> bindings = host->allocate_resources(task); host->log_resources(resource_log); submit_task(task, slot->rank, bindings); s = free_slots.erase(s); // so that the s++ in the loop doesn't skip one s--; match = true; scheduled += 1; // This is to break out of the slot loop so that we can // consider the next task break; } } if (!match) { // If the task could not be scheduled, then we save it // and move on to the next one. It will be requeued later. log_trace("No slot found for task %s", task->name.c_str()); deferred_tasks.push_back(task); } } log_debug("Scheduled %d tasks and deferred %d tasks", scheduled, deferred_tasks.size()); // Requeue all the deferred tasks for (TaskList::iterator t = deferred_tasks.begin(); t != deferred_tasks.end(); t++) { ready_queue.push(*t); } }
Host Host::autoRegister() { Host newHost = Host(); newHost.setName(Host::currentHostName()); newHost.setOnline(1); newHost.commit(); newHost.updateHardwareInfo(); Service ab = Service::recordByName("Assburner"); if( ab.isRecord() ) { HostService hs = HostService(); hs.setHost(newHost); hs.setService(ab); hs.commit(); } HostGroup hg = HostGroup::recordByName("All"); if( hg.isRecord() ) { HostGroupItem hgi = HostGroupItem(); hgi.setHost(newHost); hgi.setHostGroup(hg); hgi.commit(); } return newHost; }
NetUdpSocketErr LwipNetUdpSocket::bind(const Host& me) { err_t err; if(!m_pPcb) return NETUDPSOCKET_MEM; //NetUdpSocket was not properly initialised, should destroy it & retry #if LWIP_IGMP //Multicast support enabled if(me.getIp().isMulticast()) { DBG("This is a multicast addr, joining multicast group\r\n"); m_multicastGroup = me.getIp(); ip_addr_t multicastGroupAddr = m_multicastGroup.getStruct(); err = igmp_joingroup(IP_ADDR_ANY, &multicastGroupAddr); if(err) return NETUDPSOCKET_IF; //Could not find or create group } #endif err = udp_bind( (udp_pcb*) m_pPcb, IP_ADDR_ANY, me.getPort()); //IP_ADDR_ANY : Bind the connection to all local addresses if(err) return NETUDPSOCKET_INUSE; //Setup callback udp_recv( (udp_pcb*) m_pPcb, LwipNetUdpSocket::sRecvCb, (void*) this ); return NETUDPSOCKET_OK; }
csp::WorkResult::Enum csp::Process::Evaluate( Host& host, int numArgs ) { if( LuaThread().Status() != lua::Return::YIELD && LuaThread().Status() != lua::Return::OK ) return WorkResult::FINISH; if( m_operation ) { WorkResult::Enum result = m_operation->IsFinished() ? WorkResult::FINISH : m_operation->Evaluate( host ); if( result == WorkResult::FINISH ) { lua::LuaStack luaStack = m_luaThread.GetStack(); numArgs = m_operation->PushResults( luaStack ); DeleteOperation( host ); } else return WorkResult::YIELD; } WorkResult::Enum result = Resume( numArgs ); if ( result == WorkResult::YIELD && m_operation ) host.PushEvalStep( *this ); else if ( result == WorkResult::FINISH && m_parentProcess ) { if( host.GetTopProcess() != m_parentProcess ) host.PushEvalStep( *m_parentProcess ); } return result; }
void Loader::load(DocLoader* docLoader, CachedResource* resource, bool incremental, bool skipCanLoadCheck, bool sendResourceLoadCallbacks) { ASSERT(docLoader); Request* request = new Request(docLoader, resource, incremental, skipCanLoadCheck, sendResourceLoadCallbacks); Host* host; KURL url(resource->url()); bool isHTTP = url.protocolIs("http") || url.protocolIs("https"); if (isHTTP) { AtomicString hostName = url.host(); host = m_hosts.get(hostName.impl()); if (!host) { host = new Host(hostName, maxRequestsInFlightPerHost); m_hosts.add(hostName.impl(), host); } } else host = &m_nonHTTPProtocolHost; Priority priority = determinePriority(resource); host->addRequest(request, priority); docLoader->incrementRequestCount(); if (priority > Low || !isHTTP) { // Try to request important resources immediately host->servePendingRequests(priority); } else { // Handle asynchronously so early low priority requests don't get scheduled before later high priority ones scheduleServePendingRequests(); } }
void TcpCSocket::prepare(Host const& host) { if (this->connected()) this->disconnect(); this->_s_in.sin_addr = host.getAddrN(); this->_s_in.sin_port = host.getPortN(); }
bool Leafset::remove(const Host& entry) { pf_log[W_ROUTING] << "Trying to remove an entry from the leafset: " << entry; if(entry.GetKey() == this->me.GetKey()) { pf_log[W_ROUTING] << "Trying to remove myself from the leafset ?"; return false; } HostVector::iterator it; for (it = leavesCW.begin(); it != leavesCW.end(); ++it) { if(entry.GetKey() == it->GetKey()) { pf_log[W_ROUTING] << "Entry removed."; leavesCW.erase(it); return true; } } for (it = leavesCCW.begin(); it != leavesCCW.end(); ++it) { if(entry.GetKey() == it->GetKey()) { pf_log[W_ROUTING] << "Entry removed."; leavesCCW.erase(it); return true; } } return false; }
void SyncedSDFileSystem::on_master_event(TCPSocketEvent e) { debug("MASTER: got event: %d", e); TCPSocketErr err; Host slave; TCPSocket *slave_socket; MasterNodeHandler *dispatcher; switch (e) { case TCPSOCKET_ACCEPT: debug("MASTER: accepting new connection"); err = tcp_socket_->accept(&slave, &slave_socket); if (err) { // TODO: handle errors } debug("MASTER: creating new handler"); dispatcher = new MasterNodeHandler(this, slave, slave_socket); node_handlers_.insert(pair<string, MasterNodeHandler *>(ip_to_string(slave.getIp()), dispatcher)); // dispatcher should destroy self when done or disconnected break; case TCPSOCKET_CONTIMEOUT: case TCPSOCKET_CONRST: case TCPSOCKET_CONABRT: case TCPSOCKET_ERROR: case TCPSOCKET_DISCONNECTED: // TODO: handle errors break; case TCPSOCKET_CONNECTED: case TCPSOCKET_READABLE: case TCPSOCKET_WRITEABLE: default: // these should never happen break; } }
void Handle (DHT& dht, const Host& host, const Packet& pckt) { Key k = pckt.GetArg<Key>(DHT_GET_KEY); pf_log[W_DHT] << "Get received with key " << k; if(dht.GetStorage()->hasKey(k)) { pf_log[W_DHT] << "Answer with data " << dht.GetStorage()->getInfo(k)->GetStr(); Packet get_ack(DHTGetAckType, dht.GetMe(), host.GetKey()); get_ack.SetArg(DHT_GET_ACK_KEY, k); get_ack.SetArg(DHT_GET_ACK_DATA, dht.GetStorage()->getInfo(k)); if(!dht.GetChimera()->Send(host, get_ack)) pf_log[W_DHT] << "Send get ACK message failed!"; return; } pf_log[W_DHT] << "Data not in cache, try to relay to a closest host."; if(!dht.GetChimera()->Route(pckt)) { pf_log[W_DHT] << "I'm the owner and the key is unknow, answer with GET_NACK."; Packet get_nack(DHTGetNAckType, dht.GetMe(), host.GetKey()); get_nack.SetArg(DHT_GET_NACK_KEY, k); if(!dht.GetChimera()->Send(host, get_nack)) pf_log[W_DHT] << "Send get NACK message failed!"; return; } pf_log[W_DHT] << "GET relayed."; }
// InStream::ReceiveHandler implementation virtual void onReceive(const void* data, int size) { std::string key = remoteHost.keyStr(); if (os.isValid()) { // -> already initialized std::string s((char*) data, size); printf("Received %d bytes from %s: %s\n", size, key.c_str(), s.c_str()); server.broadcastMessage(data, size); } else { // -> connect outstream if (size == sizeof(ServiceId)) { ServiceId service = *((ServiceId*) data); printf("Received client callback service id %d from %s\n", service, key.c_str()); os = remoteHost.connect(service); ready = true; sendMessage("HELLO", 6); } else { // invalid init message printf("Received invalid callback service id from %s\n", key.c_str()); is.reset(); server.removeConnection(this); delete this; return; } } is.read(this); }
// ----------------------------------- void Cookie::logDebug(const char *str, int ind) { char ipstr[64]; Host h; h.ip = ip; h.IPtoStr(ipstr); LOG_DEBUG("%s %d: %s - %s",str,ind,ipstr,id); }
bool Provider::isCompatible(const Host& host) const { // check compatibility with host const std::string& type = this->plumaGetType(); if (!host.knows(type)) return false; unsigned int lowest = host.getLowestVersion(type); unsigned int current = host.getVersion(type); unsigned int myVersion = this->getVersion(); return lowest <= myVersion && myVersion <= current; }
int gsc::tcp::client_begin(Client * newClient) { Host * parent = newClient->get_parent(); //Call the client_loop function (*parent->get_client_loop_function())(newClient); //When we fall out of the client loop, delete the client; delete(newClient); return 0; }
void runTest() { netSystem.run(TimeUtil::makeTime(1000, TimeUtil::SEC)); host1->cleanUp(); host2->cleanUp(); interface2->finalize(); interface->finalize(); netSystem.run(TimeUtil::makeTime(2000, TimeUtil::SEC)); }
void Motion::reportConfigStatus(Host& h) { for(int ax=0;ax < NUM_AXES;ax++) { h.labelnum("CS:", ax, false); h.write(' '); AXES[ax].reportConfigStatus(h); h.endl(); } }
/* BEGIN FUNCTION DEFINITION */ void Router::disconnect( Host& h) { // check that they are connected if ( is_connected_host( &h ) ) { h.setParent( NULL ); delete_host_entry( h.getAddress() ); remove_from_connected_hosts( &h ); } else cout << "Host " << h.getAddress() << " is not directly connected to Router " << address << " so this disconnection is forbidden!\n" << endl; }
static void *fetchSuite(OfxPropertySetHandle hostProps, const char *suiteName, int suiteVersion) { Property::Set* properties = reinterpret_cast<Property::Set*>(hostProps); Host* host = (Host*)properties->getPointerProperty(kOfxHostSupportHostPointer); if(host) return host->fetchSuite(suiteName,suiteVersion); else return 0; }
int Execute(HINSTANCE hInstance, int argc, const char **argv){ Host *host = new kroll::Win32Host(hInstance,argc,argv); #ifndef DEBUG // only create a debug console when not compiled in debug mode -- otherwise, it should be autocreated if (host->IsDebugMode()) { RedirectIOToConsole(); } #endif return host->Run(); }
//============================================================================== void HostFilterComponent::changeListenerCallback (void* source) { if (source == this) { closePluginEditorWindows (); } else if (source == getFilter()) { clearComponents (); rebuildComponents (); // reopen windows saved with session Host* host = getFilter()->host; for (int j = 0; j < host->getPluginsCount(); j++) { BasePlugin* plugin = host->getPluginByIndex (j); if (plugin && plugin->getIntValue (PROP_WINDOWOPEN, 0)) openPluginEditorWindow (plugin); } resized (); } else if (source == getFilter()->getTransport()) { // update transport ! CommandManager::getInstance()->commandStatusChanged (); } else if (source == &knownPluginList) { // save the plugin list every time it gets changed, so that if we're scanning // and it crashes, we've still saved the previous ones XmlElement* const savedPluginList = knownPluginList.createXml(); if (savedPluginList != 0) { ApplicationProperties::getInstance()->getUserSettings() ->setValue (T("pluginList"), savedPluginList); delete savedPluginList; ApplicationProperties::getInstance()->saveIfNeeded(); } } else { for (int i = pluginWindows.size(); --i >= 0;) { VstPluginWindow* window = pluginWindows.getUnchecked (i); if (window) window->updateParameters (); } } }
void printHosts() { printf("Hosts:\n"); for (Host::Iterator it = ep.hosts(); it.hasNext(); ) { Host h = it.next(); printf(" %s", h.keyStr().c_str()); Address addr = h.address(); if (addr.isValid()) printf(" - %s", addr.toString().c_str()); printf("\n"); } }
QString ServersComboBox::makeServerText(const Host &host) { QString name; name = host.address(); if (host.isValid()) { if (name.indexOf(':') >= 0) { name = '[' + name + ']'; } name += ':' + QString::number(host.port()); } return name; }
int main() { Host host; string url1 = "https://www.youtube.com/watch?v=so6ExplQlaY"; string url2 = "https://www.youtube.com/watch?v=k0d4wj4Cqvw"; string shorted1 = host.Shorten(url1); string shorted2 = host.Shorten(url2); cout << host.Restore(shorted1) << endl; cout << host.Restore(shorted2) << endl; }
NetTcpSocketErr LwipNetTcpSocket::connect(const Host& host) { if(!m_pPcb) return NETTCPSOCKET_MEM; //NetTcpSocket was not properly initialised, should destroy it & retry ip_addr_t ip = host.getIp().getStruct(); err_t err = tcp_connect( (tcp_pcb*) m_pPcb, &ip, host.getPort(), LwipNetTcpSocket::sConnectedCb ); if(err) return NETTCPSOCKET_MEM; return NETTCPSOCKET_OK; }
void MenuItem::HandleClickEvent(SharedKObject source) { if (this->IsCheck() && this->autoCheck) { // Execute this later on the main thread Host* host = Host::GetInstance(); host->InvokeMethodOnMainThread( this->Get("setState")->ToMethod(), ValueList(Value::NewBool(!this->GetState())), false); } this->FireEvent(Event::CLICKED); }
/** We update the routing infrastructure with the given addresses */ void Handle (Chimera& chimera, const Host&, const Packet& pckt) { addr_list address = pckt.GetArg<addr_list>(CHIMERA_PIGGY_ADDRESSES); for(addr_list::iterator it = address.begin(); it != address.end(); ++it) { Host host = hosts_list.GetHost(*it); /* After a peer failed, we wait some time before adding it back. */ if(time::dtime() - host.GetFailureTime() > Chimera::GRACEPERIOD) chimera.GetRouting()->add(host); else pf_log[W_ROUTING] << "Refused to add " << host << " to routing table"; } }
/* --------------------------------------------------------------------------- */ void Router::updateNeighborDisconnectHost(Router *r, Host &h) { // If the Host does not appear in its routeMap, end function call. if ((r->routeMap).count(h.getNumber()) == 0) { return; } (r->routeMap).erase(h.getNumber()); for (multimap<int, Router *>::iterator ri = (r->neighborRouters).begin(); ri != (r->neighborRouters).end(); ri++) { r->updateNeighborDisconnectHost(ri->second, h); } }
Host * HostPool::getHostFromHostID( int id ) { QMutexLocker locker( & mPoolLock ); QMapIterator<QString, Host *> it(mHostPool); while( it.hasNext() ) { it.next(); Host * pHost = it.value(); if( pHost->getHostID() == id ) { return pHost; } } qDebug()<<"ERROR: didnt find requested id in hostpool"; return 0; }