`string host` C++ Examples
60 C++ code examples are found related to "string host".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: SynSocketWrapper.cpp From BattleServer with The Unlicense | 6 votes |
SocketClient::SocketClient(const std::string& host, int port) : Socket() { std::string error; hostent *he; if ((he = gethostbyname(host.c_str())) == 0) { error = strerror(errno); throw error; } sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr = *((in_addr *)he->h_addr); memset(&(addr.sin_zero), 0, 8); if (::connect(s_, (sockaddr *) &addr, sizeof(sockaddr))) { error = strerror(WSAGetLastError()); throw error; } }
Example 2
Source File: topology_manager.cc From apollo_ros_bridge with Apache License 2.0 | 6 votes |
bool TopologyManager::ParseParticipantName(const std::string& participant_name, std::string* host_name, int* process_id) { // participant_name format: host_name+process_id auto pos = participant_name.find('+'); if (pos == std::string::npos) { ADEBUG << "participant_name [" << participant_name << "] format mismatch."; return false; } *host_name = participant_name.substr(0, pos); std::string pid_str = participant_name.substr(pos + 1); try { *process_id = std::stoi(pid_str); } catch (const std::exception& e) { AERROR << "invalid process_id:" << e.what(); return false; } return true; }
Example 3
Source File: node_manager.cc From apollo_ros_bridge with Apache License 2.0 | 6 votes |
void NodeManager::OnTopoModuleLeave(const std::string& host_name, int process_id) { RETURN_IF(!is_discovery_started_.load()); RoleAttributes attr; attr.set_host_name(host_name); attr.set_process_id(process_id); std::vector<RolePtr> nodes_to_remove; nodes_.Search(attr, &nodes_to_remove); for (auto& node : nodes_to_remove) { nodes_.Remove(node->attributes().node_id()); } ChangeMsg msg; for (auto& node : nodes_to_remove) { Convert(node->attributes(), RoleType::ROLE_NODE, OperateType::OPT_LEAVE, &msg); Notify(msg); } }
Example 4
Source File: jwt_authenticator.cc From proxy with Apache License 2.0 | 6 votes |
void ExtractUriHostPath(const std::string &uri, std::string *host, std::string *path) { // Example: // uri = "https://example.com/certs" // pos : ^ // pos1 : ^ // host = "example.com" // path = "/certs" auto pos = uri.find("://"); pos = pos == std::string::npos ? 0 : pos + 3; // Start position of host auto pos1 = uri.find("/", pos); if (pos1 == std::string::npos) { // If uri doesn't have "/", the whole string is treated as host. *host = uri.substr(pos); *path = "/"; } else {
Example 5
Source File: context.cc From proxy with Apache License 2.0 | 6 votes |
void extractServiceName(const std::string& host, const std::string& destination_namespace, std::string* service_name) { auto name_pos = host.find_first_of(".:"); if (name_pos == std::string::npos) { // host is already a short service name. return it directly. *service_name = host; return; } if (host[name_pos] == ':') { // host is `short_service:port`, return short_service name. *service_name = host.substr(0, name_pos); return; } auto namespace_pos = host.find_first_of(".:", name_pos + 1); std::string service_namespace = ""; if (namespace_pos == std::string::npos) { service_namespace = host.substr(name_pos + 1); } else {
Example 6
Source File: MinerManager.cpp From conceal-core with MIT License | 6 votes |
bool MinerManager::submitBlock(const Block& minedBlock, const std::string& daemonHost, uint16_t daemonPort) { try { HttpClient client(m_dispatcher, daemonHost, daemonPort); COMMAND_RPC_SUBMITBLOCK::request request; request.emplace_back(Common::toHex(toBinaryArray(minedBlock))); COMMAND_RPC_SUBMITBLOCK::response response; System::EventLock lk(m_httpEvent); JsonRpc::invokeJsonRpcCommand(client, "submitblock", request, response); m_logger(Logging::INFO) << "Block has been successfully submitted. Block hash: " << Common::podToHex(get_block_hash(minedBlock)); return true; } catch (std::exception& e) { m_logger(Logging::WARNING) << "Couldn't submit block: " << Common::podToHex(get_block_hash(minedBlock)) << ", reason: " << e.what(); return false; } }
Example 7
Source File: Connection.cpp From open-dis-cpp with BSD 2-Clause "Simplified" License | 6 votes |
void Connection::Connect(unsigned int port, const std::string& host, bool listening) { bool success = SDL_Init(0) != -1 && SDLNet_Init() != -1; if (!success) { HandleError(); return; } if (SDLNet_ResolveHost(&mAddr, host.c_str(), port) == -1 ) { std::ostringstream strm; strm << "Can't get address for : " + host + ". " << "Error:" << SDLNet_GetError() << "\n. System: " << SDL_GetError(); LOG_ERROR( strm.str() ); } if (listening) { mSocket = SDLNet_UDP_Open(port); } else {
Example 8
Source File: qnode.cpp From ROS_QT_GUI with MIT License | 6 votes |
bool QNode::init(const std::string &master_url, const std::string &host_url) { std::map<std::string,std::string> remappings; remappings["__master"] = master_url; remappings["__hostname"] = host_url; ros::init(remappings,"test_gui"); if (!ros::master::check()) { return false; } ros::start(); // explicitly needed since our nodehandle is going out of scope. ros::NodeHandle n; ros::NodeHandle nSub; // Add your ros communications here. chatter_publisher = n.advertise<std_msgs::String>("testgui_chat", 1000); chatter_subscriber = nSub.subscribe("testgui_chat", 100, &QNode::RecvTopicCallback, this); start(); return true; }
Example 9
Source File: autodetectproxy_unittest.cc From WebRTC-APM-for-Android with Apache License 2.0 | 6 votes |
bool Create(const std::string& user_agent, const std::string& path, const std::string& host, uint16_t port, bool secure, bool startnow) { auto_detect_proxy_ = new AutoDetectProxy(user_agent); EXPECT_TRUE(auto_detect_proxy_ != NULL); if (!auto_detect_proxy_) { return false; } Url<char> host_url(path, host, port); host_url.set_secure(secure); auto_detect_proxy_->set_server_url(host_url.url()); auto_detect_proxy_->SignalWorkDone.connect( this, &AutoDetectProxyTest::OnWorkDone); if (startnow) { auto_detect_proxy_->Start(); } return true; }
Example 10
Source File: netbase.cpp From Phore-old with MIT License | 6 votes |
void SplitHostPort(std::string in, int& portOut, std::string& hostOut) { size_t colon = in.find_last_of(':'); // if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator bool fHaveColon = colon != in.npos; bool fBracketed = fHaveColon && (in[0] == '[' && in[colon - 1] == ']'); // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is safe bool fMultiColon = fHaveColon && (in.find_last_of(':', colon - 1) != in.npos); if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) { int32_t n; if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) { in = in.substr(0, colon); portOut = n; } } if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']') hostOut = in.substr(1, in.size() - 2); else
Example 11
Source File: blocking_tcp_client.cpp From GrinPlusPlus with MIT License | 6 votes |
void connect(const std::string& host, const std::string& service, std::chrono::steady_clock::duration timeout) { // Resolve the host name and service to a list of endpoints. auto endpoints = tcp::resolver(io_context_).resolve(host, service); // Start the asynchronous operation itself. The lambda that is used as a // callback will update the error variable when the operation completes. // The blocking_udp_client.cpp example shows how you can use std::bind // rather than a lambda. std::error_code error; asio::async_connect(socket_, endpoints, [&](const std::error_code& result_error, const tcp::endpoint& /*result_endpoint*/) { error = result_error; }); // Run the operation until it completes, or until the timeout. run(timeout); // Determine whether a connection was successfully established. if (error) throw std::system_error(error); }
Example 12
Source File: blocking_tcp_client.cpp From GrinPlusPlus with MIT License | 6 votes |
void connect(const std::string& host, const std::string& service, asio::chrono::steady_clock::duration timeout) { // Resolve the host name and service to a list of endpoints. tcp::resolver::results_type endpoints = tcp::resolver(io_context_).resolve(host, service); // Start the asynchronous operation itself. The boost::lambda function // object is used as a callback and will update the ec variable when the // operation completes. The blocking_udp_client.cpp example shows how you // can use boost::bind rather than boost::lambda. asio::error_code ec; asio::async_connect(socket_, endpoints, var(ec) = _1); // Run the operation until it completes, or until the timeout. run(timeout); // Determine whether a connection was successfully established. if (ec) throw asio::system_error(ec); }
Example 13
Source File: HostResolver.cpp From aws-crt-cpp with Apache License 2.0 | 6 votes |
void DefaultHostResolver::s_onHostResolved( struct aws_host_resolver *, const struct aws_string *hostName, int errCode, const struct aws_array_list *hostAddresses, void *userData) { DefaultHostResolveArgs *args = static_cast<DefaultHostResolveArgs *>(userData); size_t len = aws_array_list_length(hostAddresses); Vector<HostAddress> addresses; for (size_t i = 0; i < len; ++i) { HostAddress *address_ptr = NULL; aws_array_list_get_at_ptr(hostAddresses, reinterpret_cast<void **>(&address_ptr), i); addresses.push_back(*address_ptr); } String host(aws_string_c_str(hostName), hostName->len); args->onResolved(*args->resolver, addresses, errCode); aws_string_destroy(args->host); Delete(args, args->allocator); }
Example 14
Source File: HostResolver.cpp From aws-crt-cpp with Apache License 2.0 | 6 votes |
bool DefaultHostResolver::ResolveHost(const String &host, const OnHostResolved &onResolved) noexcept { DefaultHostResolveArgs *args = New<DefaultHostResolveArgs>(m_allocator); if (!args) { return false; } args->host = aws_string_new_from_array( m_allocator, reinterpret_cast<const uint8_t *>(host.data()), host.length()); args->onResolved = onResolved; args->resolver = this; args->allocator = m_allocator; if (!args->host || aws_host_resolver_resolve_host(&m_resolver, args->host, s_onHostResolved, &m_config, args)) { Delete(args, m_allocator); return false; } return true; }
Example 15
Source File: netbase.cpp From Electra with MIT License | 6 votes |
void SplitHostPort(std::string in, int &portOut, std::string &hostOut) { size_t colon = in.find_last_of(':'); // if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator bool fHaveColon = colon != in.npos; bool fBracketed = fHaveColon && (in[0]=='[' && in[colon-1]==']'); // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is safe bool fMultiColon = fHaveColon && (in.find_last_of(':',colon-1) != in.npos); if (fHaveColon && (colon==0 || fBracketed || !fMultiColon)) { char *endp = NULL; int n = strtol(in.c_str() + colon + 1, &endp, 10); if (endp && *endp == 0 && n >= 0) { in = in.substr(0, colon); if (n > 0 && n < 0x10000) portOut = n; } } if (in.size()>0 && in[0] == '[' && in[in.size()-1] == ']') hostOut = in.substr(1, in.size()-2); else
Example 16
Source File: mec_kontroldevice.cpp From MEC with GNU General Public License v3.0 | 6 votes |
void KontrolDevice::newClient( Kontrol::ChangeSource src, const std::string &host, unsigned port, unsigned keepalive) { for (auto client : clients_) { if (client->isThisHost(host, port)) { return; } } std::string id = "client.osc:" + host + ":" + std::to_string(port); auto client = std::make_shared<Kontrol::OSCBroadcaster>(src, keepalive, true); if (client->connect(host, port)) { LOG_0("KontrolDevice::new client " << client->host() << " : " << client->port() << " KA = " << keepalive); // client->sendPing(listenPort_); client->ping(src, host, port, keepalive); clients_.push_back((client)); model_->addCallback(id, client); } }
Example 17
Source File: OSCBroadcaster.cpp From MEC with GNU General Public License v3.0 | 6 votes |
bool OSCBroadcaster::connect(const std::string &host, unsigned port) { stop(); try { host_ = host; port_ = port; socket_ = std::shared_ptr<UdpTransmitSocket>(new UdpTransmitSocket(IpEndpointName(host.c_str(), port_))); } catch (const std::runtime_error &e) { port_ = 0; socket_.reset(); return false; } running_ = true; #ifdef __COBALT__ pthread_t ph = writer_thread_.native_handle(); pthread_create(&ph, 0,osc_broadcaster_write_thread_func,this); #else writer_thread_ = std::thread(osc_broadcaster_write_thread_func, this); #endif return true; }
Example 18
Source File: io.cc From tts-tutorial with Apache License 2.0 | 6 votes |
int parse_url(const EST_String &url, EST_String &protocol, EST_String &host, EST_String &port, EST_String &path) { EST_String bitpath; int start_of_bracket[EST_Regex_max_subexpressions]; int end_of_bracket[EST_Regex_max_subexpressions]; if (url.matches(RxFILEURL,0,start_of_bracket, end_of_bracket)) { protocol = "file"; host = ""; port = ""; path = url.after("file:"); return TRUE; } else if
Example 19
Source File: utilstrencodings.cpp From btcpool with MIT License | 6 votes |
void SplitHostPort(std::string in, int &portOut, std::string &hostOut) { size_t colon = in.find_last_of(':'); // if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator bool fHaveColon = colon != in.npos; bool fBracketed = fHaveColon && (in[0]=='[' && in[colon-1]==']'); // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is safe bool fMultiColon = fHaveColon && (in.find_last_of(':',colon-1) != in.npos); if (fHaveColon && (colon==0 || fBracketed || !fMultiColon)) { int32_t n; if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) { in = in.substr(0, colon); portOut = n; } } if (in.size()>0 && in[0] == '[' && in[in.size()-1] == ']') hostOut = in.substr(1, in.size()-2); else
Example 20
Source File: CoreUtils.cpp From Qv2ray with GNU General Public License v3.0 | 6 votes |
bool GetOutboundInfo(const OUTBOUND &out, QString *host, int *port, QString *protocol) { // Set initial values. *host = QObject::tr("N/A"); *port = 0; *protocol = out["protocol"].toString(QObject::tr("N/A")).toLower(); if (*protocol == "vmess") { auto Server = StructFromJsonString<VMessServerObject>(JsonToString(out["settings"].toObject()["vnext"].toArray().first().toObject())); *host = Server.address; *port = Server.port; return true; } else if
Example 21
Source File: asio_common.cc From reading-and-annotate-nghttp2 with GNU General Public License v3.0 | 6 votes |
boost::system::error_code host_service_from_uri(boost::system::error_code &ec, std::string &scheme, std::string &host, std::string &service, const std::string &uri) { ec.clear(); http_parser_url u{}; if (http_parser_parse_url(uri.c_str(), uri.size(), 0, &u) != 0) { ec = make_error_code(boost::system::errc::invalid_argument); return ec; } if ((u.field_set & (1 << UF_SCHEMA)) == 0 || (u.field_set & (1 << UF_HOST)) == 0) { ec = make_error_code(boost::system::errc::invalid_argument); return ec; } http2::copy_url_component(scheme, &u, UF_SCHEMA, uri.c_str()); http2::copy_url_component(host, &u, UF_HOST, uri.c_str()); if (u.field_set & (1 << UF_PORT)) { http2::copy_url_component(service, &u, UF_PORT, uri.c_str()); } else {
Example 22
Source File: netbase.cpp From Metrix with MIT License | 6 votes |
void SplitHostPort(std::string in, int& portOut, std::string& hostOut) { size_t colon = in.find_last_of(':'); //! if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator bool fHaveColon = colon != in.npos; bool fBracketed = fHaveColon && (in[0] == '[' && in[colon - 1] == ']'); //! if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is safe bool fMultiColon = fHaveColon && (in.find_last_of(':', colon - 1) != in.npos); if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) { int32_t n; if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) { in = in.substr(0, colon); portOut = n; } } if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']') hostOut = in.substr(1, in.size() - 2); else
Example 23
Source File: run_assistant_file.cc From assistant-sdk-cpp with Apache License 2.0 | 6 votes |
CreateChannel(const std::string& host) { std::ifstream file("robots.pem"); std::stringstream buffer; buffer << file.rdbuf(); std::string roots_pem = buffer.str(); if (verbose) { std::clog << "assistant_sdk robots_pem: " << roots_pem << std::endl; } ::grpc::SslCredentialsOptions ssl_opts = {roots_pem, "", ""}; auto creds = ::grpc::SslCredentials(ssl_opts); std::string server = host + ":443"; if (verbose) { std::clog << "assistant_sdk CreateCustomChannel(" << server << ", creds, arg)" << std::endl << std::endl; } ::grpc::ChannelArguments channel_args; return CreateCustomChannel(server, creds, channel_args); }
Example 24
Source File: asyncio_utils.cpp From scout_ros with BSD 3-Clause "New" or "Revised" License | 6 votes |
void url_parse_host(std::string host, std::string &host_out, int &port_out, const std::string def_host, const int def_port) { std::string port; auto sep_it = std::find(host.begin(), host.end(), ':'); if (sep_it == host.end()) { // host if (!host.empty()) { host_out = host; port_out = def_port; } else { host_out = def_host; port_out = def_port; } return; }
Example 25
Source File: HTTPClient.cpp From nifi-minifi-cpp with Apache License 2.0 | 6 votes |
void parse_url(const std::string *url, std::string *host, int *port, std::string *protocol, std::string *path, std::string *query) { int temp_port = -1; parse_url(url, host, &temp_port, protocol); if (host->empty() || protocol->empty()) { return; } size_t base_len = host->size() + protocol->size(); if (temp_port != -1) { *port = temp_port; base_len += std::to_string(temp_port).size() + 1; // +1 for the : } auto query_loc = url->find_first_of("?", base_len); if (query_loc < url->size()) { *path = url->substr(base_len + 1, query_loc - base_len - 1); *query = url->substr(query_loc + 1, url->size() - query_loc - 1); } else {
Example 26
Source File: thrift_router.cpp From rocksplicator with Apache License 2.0 | 6 votes |
bool parseHost(const std::string& str, common::detail::Host* host, const std::string& segment, const std::string& local_group) { std::vector<std::string> tokens; folly::split(":", str, tokens); if (tokens.size() < 2 || tokens.size() > 3) { return false; } try { uint16_t port = atoi(tokens[1].c_str()); host->addr.setFromIpPort(tokens[0], port); } catch (...) { return false; } auto group = (tokens.size() == 3 ? tokens[2] : ""); host->groups_prefix_lengths[segment] = std::distance(group.begin(), std::mismatch(group.begin(), group.end(), local_group.begin(), local_group.end()).first); return true; }
Example 27
Source File: UrlTools.cpp From parsicoin with GNU Lesser General Public License v3.0 | 6 votes |
bool parseUrlAddress(const std::string& url, std::string& host, uint16_t& port, std::string& path, bool& ssl) { bool res = true; host.clear(); path.clear(); ssl = false; port = 0; boost::regex uri_exp("^(https://|http://|)(([a-z|A-Z|0-9]|[a-z|A-Z|0-9]-[a-z|A-Z|0-9]|[a-z|A-Z|0-9]\\.)+)(:[0-9]{1,5}|)(/([\\w|-]+/)+|/|)$"); boost::cmatch reg_res; if (boost::regex_match(url.c_str(), reg_res, uri_exp)) { if (reg_res.length(4) > 0) { int port_src = 0; if (sscanf(reg_res.str(4).c_str() + 1, "%d", &port_src) == 1) { if (port_src > 0 && port_src <= 0xFFFF) port = (uint16_t) port_src; } } else { if (strcmp(reg_res.str(1).c_str(), "http://") == 0) port = HTTP_PORT; else if (strcmp(reg_res.str(1).c_str(), "https://") == 0) port = HTTPS_PORT; else
Example 28
Source File: netbase.cpp From bitcoin-cored with MIT License | 6 votes |
void SplitHostPort(std::string in, int &portOut, std::string &hostOut) { size_t colon = in.find_last_of(':'); // if a : is found, and it either follows a [...], or no other : is in the // string, treat it as port separator bool fHaveColon = colon != in.npos; // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is // safe bool fBracketed = fHaveColon && (in[0] == '[' && in[colon - 1] == ']'); bool fMultiColon = fHaveColon && (in.find_last_of(':', colon - 1) != in.npos); if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) { char *endp = nullptr; int n = strtol(in.c_str() + colon + 1, &endp, 10); if (endp && *endp == 0 && n >= 0) { in = in.substr(0, colon); if (n > 0 && n < 0x10000) portOut = n; } } if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']') hostOut = in.substr(1, in.size() - 2); else
Example 29
Source File: image_io.cpp From cupoch with MIT License | 6 votes |
bool WriteImage(const std::string &filename, const HostImage &image, int quality /* = 90*/) { std::string filename_ext = utility::filesystem::GetFileExtensionInLowerCase(filename); if (filename_ext.empty()) { utility::LogWarning( "Write geometry::Image failed: unknown file extension."); return false; } auto map_itr = file_extension_to_host_image_write_function.find(filename_ext); if (map_itr == file_extension_to_host_image_write_function.end()) { utility::LogWarning( "Write geometry::Image failed: unknown file extension."); return false; } return map_itr->second(filename, image, quality); }
Example 30
Source File: postgres_options_test.cpp From iroha with Apache License 2.0 | 6 votes |
static void checkPgOpts(const PostgresOptions &pg_opt, const std::string &host, const std::string &port, const std::string &user, const std::string &password, const std::string &working_dbname, const std::string &maintenance_dbname) { checkConnString(pg_opt.workingConnectionString(), host, port, user, password, working_dbname); checkConnString(pg_opt.maintenanceConnectionString(), host, port, user, password, maintenance_dbname); }
Example 31
Source File: lasthost.cpp From dreamland_code with GNU General Public License v3.0 | 5 votes |
const DLString &XMLAttributeLastHost::getMatchingHost(const DLString &hostPrefix) const { Hosts::const_iterator h; for (h = hosts.begin(); h != hosts.end(); h++) if (hostPrefix.strPrefix(h->first)) return h->first; return DLString::emptyString; }
Example 32
Source File: lasthost.cpp From dreamland_code with GNU General Public License v3.0 | 5 votes |
bool XMLAttributeLastHost::isUnique(const DLString &playerName, const DLString &host) { for (auto &p: PCharacterManager::getPCM()) { if (playerName != p.first) { XMLAttributeLastHost::Pointer attr = p.second->getAttributes().findAttr<XMLAttributeLastHost>("lasthost"); if (attr && attr->hasHost(host)) return false; } } return true; }
Example 33
Source File: softwarecontaineragentadaptor.cpp From softwarecontainer with GNU Lesser General Public License v2.1 | 5 votes |
void SoftwareContainerAgentAdaptor::BindMount( const gint32 containerID, const std::string pathInHost, const std::string PathInContainer, const bool readOnly, SoftwareContainerAgentMessageHelper msg) { m_agent.bindMount(containerID, pathInHost, PathInContainer, readOnly); msg.returnValue(); }