diff --git a/README.md b/README.md index 0bcf03b..e8145a3 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,16 @@ - `client`从`server`下载文件,如果本地有重复则覆盖。 - 工作方式为`client A`端提交待传输的文件列表到`server`,`client B`端从`server`获取有哪些客户机提交的哪些任务,可以从中下载。 +# 开发 + mark == 0 表示,请求下载端的数据。 mark == 1 表示,服务客户端数据。 +传输的内容统一使用`UTF-8`编码,`Linux`平台下不动,`Win`平台下转为`GBK`编码。 + +`win`平台下,统一源码为`UTF-8`编码,编译结果为`GBK`编码。 + # 其他 基本可以用了,开发暂时就先到这里,如果要优化或者有需要的的话,有几个大点需要处理。 diff --git a/client/client.cpp b/client/client.cpp index 83f8604..38d41b6 100644 --- a/client/client.cpp +++ b/client/client.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace fs = std::filesystem; constexpr int g_SendPoolNum = 1; @@ -109,6 +110,11 @@ bool CClient::up_task(const std::string& cmd) logger_->warn("{} msg empty.", __FUNCTION__); return false; } + +#ifdef _WIN32 + msg = CCodec::GBKTou8(msg); +#endif + std::shared_ptr buf = std::make_shared(); buf->type_ = TYPE_UP_LIST; buf->data_ = new char[msg.size() + 1]; @@ -140,7 +146,7 @@ bool CClient::down_one_file(const std::string& id, const std::string& file) buf->data_ = new char[file.size() + 1]; buf->len_ = std::snprintf(buf->data_, file.size() + 1, "%s", file.data()); if (!send_frame(buf.get())) { - logger_->error("{} request open file [{}] send failed.", __FUNCTION__); + logger_->error("{} request open file [{}] send failed.", __FUNCTION__, file); down_->cur_remote_id_.clear(); down_->cur_remote_file_.clear(); return false; @@ -214,6 +220,10 @@ void CClient::handle_frame(CFrameBuffer* buf) if (real.empty()) { continue; } + +#ifdef _WIN32 + real = CCodec::u8ToGBK(real); +#endif if (real.find("[") == std::string::npos) { logger_->info("FILE ==> {}", real); task_list_[index]->files.push_back(real); diff --git a/ofen b/ofen index b130012..ab87624 160000 --- a/ofen +++ b/ofen @@ -1 +1 @@ -Subproject commit b130012e5b6e9aeeed0ff9084ea524c67c726dd7 +Subproject commit ab87624a333e385e08abb82ac623bce8da798539 diff --git a/server/server.cpp b/server/server.cpp index 4e23171..c4a887b 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -1,5 +1,6 @@ #include "server.h" #include +#include using namespace ofen; @@ -100,7 +101,7 @@ void CTcpServer::handle_frame() std::this_thread::sleep_for(std::chrono::milliseconds(100)); continue; } - + switch (buf->type_) { case TYPE_GET_LIST: { logger_->info("[{}] GetList.", buf->fid_); @@ -115,11 +116,17 @@ void CTcpServer::handle_frame() break; } case TYPE_UP_LIST: { - logger_->info("[{}] UpList. {}", buf->fid_, std::string(buf->data_, buf->len_)); + std::string files_path = std::string(buf->data_, buf->len_); +#ifdef _WIN32 + std::string turn_files_path = CCodec::u8ToGBK(files_path); +#else + std::string turn_files_path(files_path); +#endif + logger_->info("[{}] UpList. {}", buf->fid_, turn_files_path); std::lock_guard lock(cli_mut_); if (client_map_.count(buf->fid_)) { auto& cli = client_map_[buf->fid_]; - cli->task_ = std::string(buf->data_, buf->len_); + cli->task_ = files_path; cli->time_ = OfUtil::now_time(); } break;