Beispiel #1
0
		std::size_t setServerInfos(K const servers, ::TDF_SERVER_INFO out[MAXSERVER])
			throw(std::string)
		{
			if (servers == K_NIL) throw std::string("null servers");
			if (servers->t != XT) throw std::string("not a table");

			std::vector<std::string> const cols = q::qList2String(kK(servers->k)[0]);
			if (cols.size() != 4) throw std::string("invalid server info table");

			K const table = kK(servers->k)[1];
			assert(table->t == 0);
			assert(table->n == 4);

			assert(kK(table)[0]->t >= 0);
			assert(kK(table)[0]->n >= 0);
			std::size_t const count = static_cast<std::size_t>(kK(table)[0]->n);
			if (count > MAXSERVER) {
				throw std::string("too many servers");
			}

			std::vector<std::string> hosts, uids, pwds;
			std::vector<long long> ports;
			for (std::size_t c = 0; c < table->n; ++c) {
				if (cols[c] == "host") {
					hosts = q::qList2String(kK(table)[c]);
				}
				else if (cols[c] == "port") {
					ports = q::qList2Dec(kK(table)[c]);
				}
				else if (cols[c] == "username") {
					uids = q::qList2String(kK(table)[c]);
				}
				else if (cols[c] == "password") {
					pwds = q::qList2String(kK(table)[c]);
				}
				else {
					throw cols[c];
				}
			}

			for (std::size_t i = 0; i < count; ++i) {
				setServerInfo(hosts[i], out[i].szIp, "host/IP", i);
				setServerInfo(uids[i], out[i].szUser, "username", i);
				setServerInfo(pwds[i], out[i].szPwd, "password", i);
				if (ports[i] >= std::pow(10, _countof(out[i].szPort))) {
					std::ostringstream buffer;
					buffer << "port number [" << i << "] too long";
					throw buffer.str();
				}
				else {
					std::memset(out[i].szPort, '\0', _countof(out[i].szPort));
					std::snprintf(out[i].szPort, _countof(out[i].szPort), "%ld", ports[i]);
				}
			}
			return count;
		}
Beispiel #2
0
 explicit RPCServer(std::shared_ptr<SatelliteServerInfo> info) {
   m_server = ServerFactoryRegistry::createServer
     (RuntimeOption::ServerType, RuntimeOption::ServerIP, info->getPort(),
      info->getThreadCount());
   m_server->setRequestHandlerFactory([info] {
       auto handler = make_unique<RPCRequestHandler>(
         info->getTimeoutSeconds().count(), true);
     handler->setServerInfo(info);
     return handler;
   });
 }