codec:处理编码已解决显示中文乱码问题。
This commit is contained in:
parent
e5cc1056b9
commit
8b23f75383
@ -8,10 +8,16 @@
|
|||||||
- `client`从`server`下载文件,如果本地有重复则覆盖。
|
- `client`从`server`下载文件,如果本地有重复则覆盖。
|
||||||
- 工作方式为`client A`端提交待传输的文件列表到`server`,`client B`端从`server`获取有哪些客户机提交的哪些任务,可以从中下载。
|
- 工作方式为`client A`端提交待传输的文件列表到`server`,`client B`端从`server`获取有哪些客户机提交的哪些任务,可以从中下载。
|
||||||
|
|
||||||
|
# 开发
|
||||||
|
|
||||||
mark == 0 表示,请求下载端的数据。
|
mark == 0 表示,请求下载端的数据。
|
||||||
|
|
||||||
mark == 1 表示,服务客户端数据。
|
mark == 1 表示,服务客户端数据。
|
||||||
|
|
||||||
|
传输的内容统一使用`UTF-8`编码,`Linux`平台下不动,`Win`平台下转为`GBK`编码。
|
||||||
|
|
||||||
|
`win`平台下,统一源码为`UTF-8`编码,编译结果为`GBK`编码。
|
||||||
|
|
||||||
# 其他
|
# 其他
|
||||||
|
|
||||||
基本可以用了,开发暂时就先到这里,如果要优化或者有需要的的话,有几个大点需要处理。
|
基本可以用了,开发暂时就先到这里,如果要优化或者有需要的的话,有几个大点需要处理。
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <of_path.h>
|
#include <of_path.h>
|
||||||
#include <of_str.h>
|
#include <of_str.h>
|
||||||
|
#include <of_util.h>
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
constexpr int g_SendPoolNum = 1;
|
constexpr int g_SendPoolNum = 1;
|
||||||
@ -109,6 +110,11 @@ bool CClient::up_task(const std::string& cmd)
|
|||||||
logger_->warn("{} msg empty.", __FUNCTION__);
|
logger_->warn("{} msg empty.", __FUNCTION__);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
msg = CCodec::GBKTou8(msg);
|
||||||
|
#endif
|
||||||
|
|
||||||
std::shared_ptr<CFrameBuffer> buf = std::make_shared<CFrameBuffer>();
|
std::shared_ptr<CFrameBuffer> buf = std::make_shared<CFrameBuffer>();
|
||||||
buf->type_ = TYPE_UP_LIST;
|
buf->type_ = TYPE_UP_LIST;
|
||||||
buf->data_ = new char[msg.size() + 1];
|
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->data_ = new char[file.size() + 1];
|
||||||
buf->len_ = std::snprintf(buf->data_, file.size() + 1, "%s", file.data());
|
buf->len_ = std::snprintf(buf->data_, file.size() + 1, "%s", file.data());
|
||||||
if (!send_frame(buf.get())) {
|
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_id_.clear();
|
||||||
down_->cur_remote_file_.clear();
|
down_->cur_remote_file_.clear();
|
||||||
return false;
|
return false;
|
||||||
@ -214,6 +220,10 @@ void CClient::handle_frame(CFrameBuffer* buf)
|
|||||||
if (real.empty()) {
|
if (real.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
real = CCodec::u8ToGBK(real);
|
||||||
|
#endif
|
||||||
if (real.find("[") == std::string::npos) {
|
if (real.find("[") == std::string::npos) {
|
||||||
logger_->info("FILE ==> {}", real);
|
logger_->info("FILE ==> {}", real);
|
||||||
task_list_[index]->files.push_back(real);
|
task_list_[index]->files.push_back(real);
|
||||||
|
2
ofen
2
ofen
@ -1 +1 @@
|
|||||||
Subproject commit b130012e5b6e9aeeed0ff9084ea524c67c726dd7
|
Subproject commit ab87624a333e385e08abb82ac623bce8da798539
|
@ -1,5 +1,6 @@
|
|||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include <of_str.h>
|
#include <of_str.h>
|
||||||
|
#include <of_util.h>
|
||||||
|
|
||||||
using namespace ofen;
|
using namespace ofen;
|
||||||
|
|
||||||
@ -115,11 +116,17 @@ void CTcpServer::handle_frame()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_UP_LIST: {
|
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<std::mutex> lock(cli_mut_);
|
std::lock_guard<std::mutex> lock(cli_mut_);
|
||||||
if (client_map_.count(buf->fid_)) {
|
if (client_map_.count(buf->fid_)) {
|
||||||
auto& cli = client_map_[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();
|
cli->time_ = OfUtil::now_time();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user