modify codes.

This commit is contained in:
pandx 2025-01-22 19:06:01 +08:00
parent 493da71a81
commit 83a892465c
6 changed files with 24 additions and 13 deletions

View File

@ -1,3 +1,6 @@
#include <fstream>
#include "zlog.h"
#include "communication_cmd.hpp" #include "communication_cmd.hpp"
#include "localserver/local_server.hpp" #include "localserver/local_server.hpp"
#include "common/common_func.hpp" #include "common/common_func.hpp"
@ -5,8 +8,6 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "dbaccess/sql_db.hpp" #include "dbaccess/sql_db.hpp"
#include "scheduler/schedule.hpp" #include "scheduler/schedule.hpp"
#include "zlog.h"
#include <fstream>
extern zlog_category_t *zct; extern zlog_category_t *zct;
@ -514,4 +515,4 @@ std::string get_file_md5(const std::string& file_path) {
result.erase(result.find_last_not_of("\n") + 1); result.erase(result.find_last_not_of("\n") + 1);
return result; return result;
} }

View File

@ -1,8 +1,9 @@
#include <string.h>
#include "zlog.h"
#include "local_server.hpp" #include "local_server.hpp"
#include "jsonparse/communication_cmd.hpp" #include "jsonparse/communication_cmd.hpp"
#include "common/global.hpp" #include "common/global.hpp"
#include <string.h>
#include "zlog.h"
extern zlog_category_t *zct; extern zlog_category_t *zct;
@ -107,4 +108,4 @@ void LocalServer::HandleTcp_cmd(const char* recv_data,char* send_data,uint8_t& r
break; break;
} }
} }

View File

@ -11,6 +11,7 @@
extern zlog_category_t *zct; extern zlog_category_t *zct;
void CMTSession::start() { void CMTSession::start() {
data_ = (char*)malloc(CMT_TCP_LEN);
memset(data_, 0, CMT_TCP_LEN); memset(data_, 0, CMT_TCP_LEN);
sessionSet_.insert(shared_from_this()); // 将会话添加到会话集合中 sessionSet_.insert(shared_from_this()); // 将会话添加到会话集合中
do_read(); do_read();

View File

@ -188,6 +188,11 @@ public:
version_ = 1; version_ = 1;
head_len_ = sizeof(PackageHead); head_len_ = sizeof(PackageHead);
} }
~CMTSession() {
if (data_ != nullptr) {
free(data_);
}
}
void start(); void start();
void set_data(char *data, int len); void set_data(char *data, int len);
@ -198,7 +203,7 @@ private:
tcp::socket socket_; tcp::socket socket_;
std::unordered_set<std::shared_ptr<CMTSession>>& sessionSet_; std::unordered_set<std::shared_ptr<CMTSession>>& sessionSet_;
char data_[CMT_TCP_LEN]; char *data_;
std::string web_version_; std::string web_version_;
int version_; int version_;
int head_len_; int head_len_;

View File

@ -116,9 +116,6 @@ int main(int argc, char *argv[]) {
boost::thread startTcpCgi(attrs, StartCgiServer); boost::thread startTcpCgi(attrs, StartCgiServer);
startTcpCgi.detach(); startTcpCgi.detach();
// //启动CMT server
// boost::thread startTcpCmt(attrs, StartCMTServer);
// startTcpCmt.detach();
sleep(5); sleep(5);
uart_inst::instance().ZigbeeParameterConfig(); uart_inst::instance().ZigbeeParameterConfig();
@ -141,6 +138,10 @@ int main(int argc, char *argv[]) {
zlog_error(zbt, "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)"); zlog_error(zbt, "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)");
} }
//启动CMT server
boost::thread startTcpCmt(attrs, StartCMTServer);
startTcpCmt.detach();
int fd = OpenWatchDog(); int fd = OpenWatchDog();
int count = 0; int count = 0;
while (GlobalConfig::QuitFlag_G) { while (GlobalConfig::QuitFlag_G) {

View File

@ -1,5 +1,6 @@
#include "thread_func.hpp" #include "thread_func.hpp"
#include <map> #include <map>
#include <memory>
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
@ -21,7 +22,6 @@
#include "utility/search_dev.hpp" #include "utility/search_dev.hpp"
#include "localserver/local_server.hpp" #include "localserver/local_server.hpp"
#include "localserver/cmt_server.hpp" #include "localserver/cmt_server.hpp"
#include <memory>
extern zlog_category_t *zct; extern zlog_category_t *zct;
@ -31,6 +31,8 @@ static std::string serverPort;
Dial dial; Dial dial;
static int clean_memory = 0; static int clean_memory = 0;
std::unique_ptr<CMTServer> g_mgr_server;
void StartCgiServer() { void StartCgiServer() {
zlog_info(zbt, "start deal cgi"); zlog_info(zbt, "start deal cgi");
@ -40,8 +42,8 @@ void StartCgiServer() {
} }
} }
std::unique_ptr<CMTServer> g_mgr_server;
void StartCMTServer() { void StartCMTServer() {
sleep(2);
boost::asio::io_service io_service; boost::asio::io_service io_service;
g_mgr_server = std::make_unique<CMTServer>(io_service, 10000); io_service.run(); g_mgr_server = std::make_unique<CMTServer>(io_service, 10000); io_service.run();
} }
@ -418,4 +420,4 @@ void DiskSpaceCheck() {
} }
sleep(30); sleep(30);
} }
} }