QValidator::State ProxyAddressValidator::validate(QString &input, int &pos) const { Q_UNUSED(pos); // Validate the proxy CService serv(LookupNumeric(input.toStdString().c_str(), 9050)); proxyType addrProxy = proxyType(serv, true); if (addrProxy.IsValid()) return QValidator::Acceptable; return QValidator::Invalid; }
void QConnmanEngine::connectToId(const QString &id) { QMutexLocker locker(&mutex); QString servicePath = serviceFromId(id); QConnmanServiceInterface serv(servicePath); if(!serv.isValid()) { emit connectionError(id, QBearerEngineImpl::InterfaceLookupError); } else { serv.connect(); } }
void MethodInvoc::trigger(string port) { init(); if(_methinv_instance->running) return; Server serv(port,false,500,&service,2); _methinv_instance->server = serv; _methinv_instance->server.start(); _methinv_instance->running = true; return; }
void ComponentHandler::trigger(string port) { init(); if(_cmp_instance->running) return; Server serv(port,false,500,&service,2); _cmp_instance->server = serv; _cmp_instance->server.start(); _cmp_instance->running = true; return; }
void QConnmanEngine::disconnectFromId(const QString &id) { QMutexLocker locker(&mutex); QString servicePath = serviceFromId(id); QConnmanServiceInterface serv(servicePath); if(!serv.isValid()) { emit connectionError(id, DisconnectionError); } else { serv.disconnect(); } }
void CPartialAttributeUpdateTest::runTest(int mode) { DSI::CCommEngine engine; CPartialAttributeUpdateTestServer serv(mode); engine.add(serv); CPartialAttributeUpdateTestClient clnt(mode); engine.add(clnt); CPPUNIT_ASSERT(engine.run() == 0); }
int main(int argc, char** argv) { if (argc < 2) { std::cerr << "You must set port as program parameter" << std::endl; return 1; } TMbTCPSocket serv(atoi(argv[1])); serv.Bind(); serv.Listen(); int pid = fork(); if ( pid < 0) { std::cerr << "Can't fork new process" << std::endl; return 1; } if ( pid == 0 ) { TMbTCPSocket client = serv.Accept(); std::string ans = ""; std::cout << "Server: Get connection from " << client.getIp() << std::endl; client.Send("Hello, Neo!"); ans = client.Recv(); std::cout << "Client: " << ans << std::endl; client.Send("Follow the white rabbit!"); ans = client.Recv(); std::cout << "Client: " << ans << std::endl; client.Send("Knock knock, Neo!"); //std::cout << "OK" << std::endl; } else if ( pid > 0 ) { std::string sans = ""; TMbTCPSocket cli("127.0.0.1", atoi(argv[1])); cli.Connect(); sans = cli.Recv(); std::cout << "Server: " << sans << std::endl; cli.Send("Who are you?"); sans = cli.Recv(); std::cout << "Server: " << sans << std::endl; cli.Send("What a white rabbit?"); sans = cli.Recv(); std::cout << "Server :" << sans << std::endl; } return 0; }
int main( int argc, char** argv ) { if( argc <= 1 ) { std::cerr << "Usage: "<<argv[0]<<" PORT\n"; return -1; } try { auto s = std::make_shared<calculator>(); mace::rpc::raw::udp::server<calculator> serv( s, rpc::udp::endpoint( ip::address(), boost::lexical_cast<int>(argv[1]) ) ); mace::cmt::exec(); } catch ( ... ) { std::cerr << boost::current_exception_diagnostic_information() << std::endl; } };
void CMultiPingPongTest::runTest(Mode mode) { DSI::CCommEngine engine; CPingPongTestServer serv(mode); engine.add(serv); CPingPongTestClient clnt; engine.add(clnt); CPPUNIT_ASSERT(engine.run() == 0); CPPUNIT_ASSERT(clnt.check(mode)); }
void async_test2() { try { std::cout << "server start." << std::endl; boost::asio::io_service ios; server serv(ios); ios.run(); } catch (std::exception& e) { std::cout << e.what() << std::endl; } }
int main(int nagrv,char** argc) { const char* bind_ip= ""; unsigned short bind_port= 4001; muradin::net::io_service ios; muradin::net::tcp_server serv(bind_ip,bind_port,ios,1); LOG_INFO.stream() <<" runing "; LOG_INFO.stream() <<bind_ip << " : " << bind_port ; serv.set_conn_callback(on_conn); serv.set_read_callback(on_msg); serv.set_write_callback(on_msg_complete); serv.set_error_callback(on_err); serv.ready(); ios.run(); }
int main(int ac, char *av[]) { std::vector<std::string> args; for (int acc = 0; acc < ac; ++acc) args.push_back(av[acc]); try { Server serv(args); serv.run(); } catch (std::exception& e) { std::cerr << e.what() << std::endl; } return 0; }
bool servline(socket_t sock, char * buff, size_t size, bool (*serv)(socket_t, char const *, size_t)) { if (sock==INVALID_SOCKET) return false; { int len=recv(sock, buff, size, 0); if (len==0) { // connection have been gracefully closed return false; } else if (len<0) { NANOLOG("recv failed <%d>\n", nanonet_error()); return false; } else { buff[len]='\0'; return serv(sock, buff, size); } } }
int main(int argc, char *argv[]) { char *device = NULL; int port = 666; int ch; int chan = 1; struct sstate *ss = get_ss(); memset(ss, 0, sizeof(*ss)); ss->ss_clients.c_next = ss->ss_clients.c_prev = &ss->ss_clients; while ((ch = getopt(argc, argv, "p:d:hc:v:")) != -1) { switch (ch) { case 'p': port = atoi(optarg); break; case 'd': device = optarg; break; case 'v': ss->ss_level = atoi(optarg); break; case 'c': chan = atoi(optarg); break; case 'h': default: usage(argv[0]); break; } } signal(SIGPIPE, sighandler); if (!device || chan <= 0) usage(argv[0]); serv(ss, device, port, chan); exit(0); }
int main(int argc,char *argv[]) { if (!AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0)) { cerr << "Can't initialise MFC !" << endl; return -1; } service serv(argv[0]); int ret; if ((ret = serv.options(argc,argv)) <= 0) return ret; serv.run(argc,argv); return 0; }
std::string CNetAddr::ToStringIP() const { CService serv(*this, 0); struct sockaddr_storage sockaddr; socklen_t socklen = sizeof(sockaddr); if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) { char name[1025] = ""; if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), NULL, 0, NI_NUMERICHOST)) return std::string(name); } if (IsIPv4()) return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0)); else return strprintf("%x:%x:%x:%x:%x:%x:%x:%x", GetByte(15) << 8 | GetByte(14), GetByte(13) << 8 | GetByte(12), GetByte(11) << 8 | GetByte(10), GetByte(9) << 8 | GetByte(8), GetByte(7) << 8 | GetByte(6), GetByte(5) << 8 | GetByte(4), GetByte(3) << 8 | GetByte(2), GetByte(1) << 8 | GetByte(0)); }
void MainWindow::proceed() { QFile file("../ClientPro/token"); if (file.open(QIODevice::WriteOnly)) { file.write(token.toStdString().c_str(),token.length()); file.close(); } QFile serv("../ClientPro/address"); if (serv.open(QIODevice::WriteOnly)) { QString data = ui->ipLine->text() + ":" + ui->portLine->text(); serv.write(data.toStdString().c_str(), data.length()); serv.close(); } NotesForm *n = new NotesForm(); n->show(); this->close(); }
NS_IMETHODIMP mozSpellChecker::SetCurrentDictionary(const nsAString &aDictionary) { if(!mSpellCheckingEngine) return NS_ERROR_NULL_POINTER; nsresult res; res = mSpellCheckingEngine->SetDictionary(PromiseFlatString(aDictionary).get()); if(NS_FAILED(res)){ NS_WARNING("Dictionary load failed"); return res; } nsXPIDLString language; nsCOMPtr<mozISpellI18NManager> serv(do_GetService("@mozilla.org/spellchecker/i18nmanager;1", &res)); if(serv && NS_SUCCEEDED(res)){ res = serv->GetUtil(language.get(),getter_AddRefs(mConverter)); } return res; }
NS_IMETHODIMP mozSpellChecker::SetCurrentDictionary(const nsAString &aDictionary) { // Calls to mozISpellCheckingEngine::SetDictionary might destroy us nsRefPtr<mozSpellChecker> kungFuDeathGrip = this; mSpellCheckingEngine = nullptr; if (aDictionary.IsEmpty()) { return NS_OK; } nsresult rv; nsCOMArray<mozISpellCheckingEngine> spellCheckingEngines; rv = GetEngineList(&spellCheckingEngines); NS_ENSURE_SUCCESS(rv, rv); for (int32_t i = 0; i < spellCheckingEngines.Count(); i++) { // We must set mSpellCheckingEngine before we call SetDictionary, since // SetDictionary calls back to this spell checker to check if the // dictionary was set mSpellCheckingEngine = spellCheckingEngines[i]; rv = mSpellCheckingEngine->SetDictionary(PromiseFlatString(aDictionary).get()); if (NS_SUCCEEDED(rv)) { nsCOMPtr<mozIPersonalDictionary> personalDictionary = do_GetService("@mozilla.org/spellchecker/personaldictionary;1"); mSpellCheckingEngine->SetPersonalDictionary(personalDictionary.get()); nsXPIDLString language; nsCOMPtr<mozISpellI18NManager> serv(do_GetService("@mozilla.org/spellchecker/i18nmanager;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); return serv->GetUtil(language.get(),getter_AddRefs(mConverter)); } } mSpellCheckingEngine = nullptr; // We could not find any engine with the requested dictionary return NS_ERROR_NOT_AVAILABLE; }
QNetworkSession::State QConnmanEngine::sessionStateForId(const QString &id) { QMutexLocker locker(&mutex); QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) return QNetworkSession::Invalid; if (!ptr->isValid) { return QNetworkSession::Invalid; } QString service = serviceFromId(id); QConnmanServiceInterface serv(service); QString servState = serv.getState(); if(serv.isFavorite() && (servState == QLatin1String("idle") || servState == QLatin1String("failure"))) { return QNetworkSession::Disconnected; } if(servState == QLatin1String("association") || servState == QLatin1String("configuration") || servState == QLatin1String("login")) { return QNetworkSession::Connecting; } if(servState == QLatin1String("ready") || servState == QLatin1String("online")) { return QNetworkSession::Connected; } if ((ptr->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { return QNetworkSession::Disconnected; } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { return QNetworkSession::NotAvailable; } else if ((ptr->state & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) { return QNetworkSession::NotAvailable; } return QNetworkSession::Invalid; }
socket_t single_accept(socket_t sock, bool (*serv)(socket_t)) { bool r; if (sock==INVALID_SOCKET) return sock; do { struct sockaddr_in addr; socklen_t len=sizeof(addr); socket_t acc=accept(sock, (struct sockaddr*)&addr, &len); if (acc==INVALID_SOCKET) { NANOLOG("accept failed <%d>\n", nanonet_error()); r=false; } else { char * hostport = getnameinfo_as_string((struct sockaddr const*)&addr, len); NANOLOG("accept [%s] <- [%s:%d]\n", hostport , inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); free(hostport); r=serv(acc); } close_socket_t(acc); } while (r); // end if serv is fail return sock; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->setWindowIcon(QIcon("../ClientPro/icon.png")); QFile serv("../ClientPro/address"); if (serv.open(QIODevice::ReadOnly)) { QString s = QString(serv.readAll()); ui->ipLine->setText(s.split(":").first()); ui->portLine->setText(s.split(":").last()); } QFile file("../ClientPro/token"); if (file.open(QIODevice::ReadOnly)) { QString s = QString(file.readAll()); token=s; file.close(); } checktoken(); this->setFixedSize(301,200); }
nsresult SetupMapping() { nsresult rv; nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIProtocolHandler> ph; rv = serv->GetProtocolHandler("res", getter_AddRefs(ph)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIResProtocolHandler> resPH = do_QueryInterface(ph, &rv); if (NS_FAILED(rv)) return rv; rv = resPH->AppendSubstitution("foo", "file://y|/"); if (NS_FAILED(rv)) return rv; rv = resPH->AppendSubstitution("foo", "file://y|/mozilla/dist/win32_D.OBJ/bin/"); if (NS_FAILED(rv)) return rv; return rv; }
std::string CNetAddr::ToStringIP() const { if (IsTor()) return EncodeBase32(&ip[6], 10) + ".onion"; if (IsInternal()) return EncodeBase32(ip + sizeof(g_internal_prefix), sizeof(ip) - sizeof(g_internal_prefix)) + ".internal"; CService serv(*this, 0); struct sockaddr_storage sockaddr; socklen_t socklen = sizeof(sockaddr); if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) { char name[1025] = ""; if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), nullptr, 0, NI_NUMERICHOST)) return std::string(name); } if (IsIPv4()) return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0)); else return strprintf("%x:%x:%x:%x:%x:%x:%x:%x", GetByte(15) << 8 | GetByte(14), GetByte(13) << 8 | GetByte(12), GetByte(11) << 8 | GetByte(10), GetByte(9) << 8 | GetByte(8), GetByte(7) << 8 | GetByte(6), GetByte(5) << 8 | GetByte(4), GetByte(3) << 8 | GetByte(2), GetByte(1) << 8 | GetByte(0)); }
void QConnmanEngine::disconnectFromId(const QString &id) { QMutexLocker locker(&mutex); QString servicePath = serviceFromId(id); QConnmanServiceInterface serv(servicePath); if(!serv.isValid()) { emit connectionError(id, DisconnectionError); } else { if(serv.getType() != QLatin1String("cellular")) { serv.disconnect(); } else { QOfonoManagerInterface ofonoManager(0); QString modemPath = ofonoManager.currentModem().path(); QOfonoDataConnectionManagerInterface dc(modemPath,0); foreach(const QDBusObjectPath dcPath,dc.getPrimaryContexts()) { if(dcPath.path().contains(servicePath.section(QLatin1Char('_'),-1))) { QOfonoPrimaryDataContextInterface primaryContext(dcPath.path(),0); primaryContext.setActive(false); } } } } }
NS_IMETHODIMP mozSpellChecker::SetCurrentDictionary(const nsAString &aDictionary) { nsresult rv; nsCString *contractId; if (!mDictionariesMap.Get(aDictionary, &contractId)){ NS_WARNING("Dictionary not found"); return NS_ERROR_NOT_AVAILABLE; } if (!mCurrentEngineContractId || !mCurrentEngineContractId->Equals(*contractId)){ mSpellCheckingEngine = do_GetService(contractId->get(), &rv); if (NS_FAILED(rv)) return rv; mCurrentEngineContractId = contractId; } nsresult res; res = mSpellCheckingEngine->SetDictionary(PromiseFlatString(aDictionary).get()); if(NS_FAILED(res)){ NS_WARNING("Dictionary load failed"); return res; } mSpellCheckingEngine->SetPersonalDictionary(mPersonalDictionary); nsXPIDLString language; nsCOMPtr<mozISpellI18NManager> serv(do_GetService("@mozilla.org/spellchecker/i18nmanager;1", &res)); if(serv && NS_SUCCEEDED(res)){ res = serv->GetUtil(language.get(),getter_AddRefs(mConverter)); } return res; }
void QConnmanEngine::connectToId(const QString &id) { QMutexLocker locker(&mutex); QString servicePath = serviceFromId(id); QConnmanServiceInterface serv(servicePath); if(!serv.isValid()) { emit connectionError(id, QBearerEngineImpl::InterfaceLookupError); } else { if(serv.getType() != "cellular") { serv.connect(); } else { QOfonoManagerInterface ofonoManager(0); QString modemPath = ofonoManager.currentModem().path(); QOfonoDataConnectionManagerInterface dc(modemPath,0); foreach(const QDBusObjectPath dcPath,dc.getPrimaryContexts()) { if(dcPath.path().contains(servicePath.section("_",-1))) { QOfonoPrimaryDataContextInterface primaryContext(dcPath.path(),0); primaryContext.setActive(true); } } } } }
nsresult TestMCTransport(const char *filename) { nsresult rv = NS_OK; nsCOMPtr<nsITransport> transport; #ifdef USE_CREATE_INSTANCE transport = do_CreateInstance( "@mozilla.org/network/memory-cache-transport;1", &rv); if (NS_FAILED(rv)) return rv; #else nsCOMPtr<nsICacheService> serv(do_GetService(kCacheServiceCID, &rv)); if (NS_FAILED(rv)) return rv; rv = serv->CreateSession("TestMCTransport", nsICache::STORE_IN_MEMORY, true, &session); if (NS_FAILED(rv)) return rv; rv = session->OpenCacheEntry(nsDependentCString(filename), nsICache::ACCESS_READ_WRITE, nsICache::BLOCKING, &desc); if (NS_FAILED(rv)) return rv; rv = desc->MarkValid(); if (NS_FAILED(rv)) return rv; rv = desc->GetTransport(getter_AddRefs(transport)); if (NS_FAILED(rv)) return rv; #endif nsCOMPtr<nsIOutputStream> os; rv = transport->OpenOutputStream(0, (PRUint32) -1, 0, getter_AddRefs(os)); if (NS_FAILED(rv)) return rv; char *out = PR_smprintf("%s.out", filename); nsCOMPtr<nsIStreamListener> listener = new TestListener(out); if (!listener) return NS_ERROR_OUT_OF_MEMORY; nsCOMPtr<nsIRequest> req; rv = transport->AsyncRead(listener, nullptr, 0, (PRUint32) -1, 0, getter_AddRefs(req)); if (NS_FAILED(rv)) return rv; FILE *file = fopen(filename, "r"); if (!file) return NS_ERROR_FILE_NOT_FOUND; char buf[256]; PRUint32 count, total=0; while ((count = fread(buf, 1, sizeof(buf), file)) > 0) { printf("writing %u bytes\n", count); total += count; rv = os->Write(buf, count, &count); if (NS_FAILED(rv)) return rv; // process an event PLEvent *event = nullptr; gEventQ->GetEvent(&event); if (event) gEventQ->HandleEvent(event); } printf("wrote %u bytes\n", total); return rv; }
int recv(unsigned short port, char *buffer, int maxlen, Address *sender, int timeout) { // make a one use server and listen once UDPServer serv(port); return serv.recv(buffer, maxlen, sender, timeout); }
int main(int argc, char* argv[]) { TelnetServer serv(66887); serv.start_server(); }