Example #1
0
void DestinationClient::initializeAsyncMcClient() {
  FBI_ASSERT(proxy_->eventBase);

  auto pdstn = pdstn_.lock();
  assert(pdstn != nullptr);

  ConnectionOptions options(pdstn->accessPoint);
  options.noNetwork = proxy_->opts.no_network;
  options.tcpKeepAliveCount = proxy_->opts.keepalive_cnt;
  options.tcpKeepAliveIdle = proxy_->opts.keepalive_idle_s;
  options.tcpKeepAliveInterval = proxy_->opts.keepalive_interval_s;
  options.timeout = std::chrono::duration_cast<std::chrono::milliseconds>(
    std::chrono::seconds(pdstn->server_timeout.tv_sec) +
    std::chrono::microseconds(pdstn->server_timeout.tv_usec));
  if (proxy_->opts.enable_qos) {
    options.enableQoS = true;
    options.qos = pdstn->qos;
  }

  if (pdstn->use_ssl) {
    auto& opts = proxy_->opts;
    checkLogic(!opts.pem_cert_path.empty() &&
               !opts.pem_key_path.empty() &&
               !opts.pem_ca_path.empty(),
               "Some of ssl key paths are not set!");
    options.sslContextProvider = [&opts] {
      return getSSLContext(opts.pem_cert_path, opts.pem_key_path,
                           opts.pem_ca_path);
    };
  }

  asyncMcClient_ = folly::make_unique<AsyncMcClient>(*proxy_->eventBase,
                                                     std::move(options));

  auto pdstnWeakPtr = pdstn_;
  asyncMcClient_->setStatusCallbacks(
    [pdstnWeakPtr] () {
      auto pdstnPtr = pdstnWeakPtr.lock();
      if (!pdstnPtr) {
        return;
      }
      pdstnPtr->on_up();
    },
    [pdstnWeakPtr] (const apache::thrift::transport::TTransportException&) {
      auto pdstnPtr = pdstnWeakPtr.lock();
      if (!pdstnPtr) {
        return;
      }
      pdstnPtr->on_down();
    });

  if (proxy_->opts.target_max_inflight_requests > 0) {
    asyncMcClient_->setThrottle(proxy_->opts.target_max_inflight_requests,
                                proxy_->opts.target_max_pending_requests);
  }
}
Example #2
0
int executer(char order[INPUT_LENGTH])
{
	char name_newdir[INPUT_LENGTH];

	if (strcmp(order, "add") == 0)
		on_add();

	else if (strcmp(order, "addl") == 0)
		on_addl();

	else if (strcmp(order, "import") == 0) {
		scanf(" %[^\n]", name_newdir);
		on_import(name_newdir);
	}

	else if (strcmp(order, "importl") == 0) {
		scanf(" %[^\n]", name_newdir);
		on_importl(name_newdir);
	}

	else if (strcmp(order, "order") == 0)
		on_order();

	else if (strcmp(order, "del") == 0 || strcmp(order, "delete") == 0)
		on_del();

	else if (strcmp(order, "delall") == 0
		 || strcmp(order, "deleteall") == 0)
		on_delall();

	else if (strcmp(order, "help") == 0 || strcmp(order, "?") == 0)
		on_help();

	else if (strcmp(order, "showlist") == 0 || strcmp(order, "show") == 0)
		on_showlist();

	else if (strcmp(order, "play") == 0) {
		if (on_play('d', 0))
			printf
			    ("The songlist cannot be played.Please check the song list\n");
	}

	else if (strcmp(order, "playone") == 0) {
		int which;
		scanf("%d", &which);
		if (on_play('a', which))
			printf
			    ("The songlist cannot be played.Please check the song list\n");
	}

	else if (strcmp(order, "save") == 0)
		on_save_config();

	else if (strcmp(order, "up") == 0)
		on_up();

	else if (strcmp(order, "down") == 0)
		on_down();

	else if (strcmp(order, "exit") == 0
		 || strcmp(order, "quit") == 0
		 || strcmp(order, "bye") == 0 || strcmp(order, "q") == 0)
		return 1;

	else if (strcmp(order, "") == 0) {
		return 1;	//printf("\n");
	} else
		printf("%s%s\n", "Command not found:", order);
	return 0;
}