perf. c++ code tidy

style. typo fixed
This commit is contained in:
lhhxxxxx
2022-07-30 18:24:31 +08:00
parent cdb2238e5b
commit a579d8b944
10 changed files with 68 additions and 43 deletions

View File

@@ -282,10 +282,10 @@ std::optional<std::vector<uchar>> asst::Controller::call_command(const std::stri
FD_SET(m_server_sock, &fdset);
constexpr int TimeoutMilliseconds = 5000;
timeval select_timeout = { TimeoutMilliseconds / 1000, (TimeoutMilliseconds % 1000) * 1000 };
select(static_cast<int>(m_server_sock) + 1, &fdset, NULL, NULL, &select_timeout);
select(static_cast<int>(m_server_sock) + 1, &fdset, nullptr, nullptr, &select_timeout);
if (FD_ISSET(m_server_sock, &fdset)) {
SOCKET client_sock = ::accept(m_server_sock, NULL, NULL);
setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&TimeoutMilliseconds, sizeof(int));
SOCKET client_sock = ::accept(m_server_sock, nullptr, nullptr);
setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<const char*>(&TimeoutMilliseconds), sizeof(int));
int recv_size = 0;
do {
recv_size = ::recv(client_sock, (char*)m_socket_buffer.get(), SocketBuffSize, NULL);
@@ -371,7 +371,7 @@ std::optional<std::vector<uchar>> asst::Controller::call_command(const std::stri
m_callback(AsstMsg::ConnectionInfo, reconnect_info, m_callback_arg);
std::this_thread::sleep_for(std::chrono::seconds(10));
auto reconnect_ret = call_command(m_adb.connect, 60 * 1000);
auto reconnect_ret = call_command(m_adb.connect, 60LL * 1000);
bool is_reconnect_success = false;
if (reconnect_ret) {
auto& reconnect_val = reconnect_ret.value();
@@ -448,7 +448,7 @@ asst::Point asst::Controller::rand_point_in_rect(const Rect& rect)
x = rect.x;
}
else {
int x_rand = std::poisson_distribution<int>(rect.width / 2)(m_rand_engine);
int x_rand = std::poisson_distribution<int>(rect.width / 2.)(m_rand_engine);
x = x_rand + rect.x;
}
@@ -457,7 +457,7 @@ asst::Point asst::Controller::rand_point_in_rect(const Rect& rect)
y = rect.y;
}
else {
int y_rand = std::poisson_distribution<int>(rect.height / 2)(m_rand_engine);
int y_rand = std::poisson_distribution<int>(rect.height / 2.)(m_rand_engine);
y = y_rand + rect.y;
}
@@ -507,7 +507,7 @@ int asst::Controller::push_cmd(const std::string& cmd)
std::unique_lock<std::mutex> lock(m_cmd_queue_mutex);
m_cmd_queue.emplace(cmd);
m_cmd_condvar.notify_one();
return int(++m_push_id);
return static_cast<int>(++m_push_id);
}
std::optional<unsigned short> asst::Controller::try_to_init_socket(const std::string& local_address, unsigned short try_port, unsigned short try_times)
@@ -751,7 +751,7 @@ bool asst::Controller::screencap(const std::string& cmd, const DecodeFunc& decod
return true;
}
else {
Log.error("convert lf and retry decode falied!");
Log.error("convert lf and retry decode failed!");
}
}
return false;
@@ -959,7 +959,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
/* connect */
{
m_adb.connect = cmd_replace(adb_cfg.connect);
auto connect_ret = call_command(m_adb.connect, 60 * 1000);
auto connect_ret = call_command(m_adb.connect, 60LL * 1000);
// 端口即使错误命令仍然会返回0TODO 对connect_result进行判断
bool is_connect_success = false;
if (connect_ret) {
@@ -1204,7 +1204,7 @@ cv::Mat asst::Controller::get_image(bool raw)
{
if (m_scale_size.first == 0 || m_scale_size.second == 0) {
Log.error("Unknown image size");
return cv::Mat();
return {};
}
// 有些模拟器adb偶尔会莫名其妙截图失败多试几次