From 0e32d241f9ddd7e202879230585cb939dd3877b2 Mon Sep 17 00:00:00 2001 From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674> Date: 星期二, 25 四月 2017 13:00:34 +0800 Subject: [PATCH] bug fix --- FaceServer/make.sh | 2 FaceServer/main_face_daemon.cpp | 20 ++++-- FaceServer/ev_server.cpp | 6 + FaceServer/face_daemon_proto.h | 10 ++- FaceServer/ev_proto.h | 9 +++ FaceServer/ev_server.h | 2 FaceServer/proto_hton_ntoh.cpp | 73 ++++++++++++++++++++++++ 7 files changed, 109 insertions(+), 13 deletions(-) diff --git a/FaceServer/ev_proto.h b/FaceServer/ev_proto.h index 2f1bed4..469ca52 100644 --- a/FaceServer/ev_proto.h +++ b/FaceServer/ev_proto.h @@ -56,6 +56,9 @@ int16_t cmd; // EVPCommand::EVPC uint32_t size; // sizeof(EVPHeader)+sizeof(subcmd) + void hton(); + void ntoh(); + EVPHeader() : _padding1(0), proto(EVPProto::EVPP__FIRST), cmd(EVPCommand::EVPC__FIRST), size(8) {} }; @@ -63,12 +66,18 @@ struct EVP_Status { int16_t status; + + void hton(); + void ntoh(); }; struct EVP_VariableBuffer { int16_t type; uint8_t buff[0]; + + void hton(); + void ntoh(); }; //#todo diff --git a/FaceServer/ev_server.cpp b/FaceServer/ev_server.cpp index ce9ebb1..2fc41e4 100644 --- a/FaceServer/ev_server.cpp +++ b/FaceServer/ev_server.cpp @@ -132,6 +132,7 @@ } evpHeader = (EVPHeader*)headerBuff; + evpHeader->ntoh(); // check header if (evpHeader->proto <= EVPProto::EVPP__FIRST || evpHeader->proto >= EVPProto::EVPP__LAST || @@ -166,9 +167,10 @@ do { readSize = bufferevent_read(bufev, client->recvbuff + client->recvbuff_end, client->recvbuff_max - client->recvbuff_end); - client->read_times++; if (readSize == 0) break; + else + client->read_times++; client->recvbuff_end += readSize; } while (readSize > 0); @@ -352,7 +354,9 @@ EVPHeader* evpHeader = new (client.sendBuff) EVPHeader; evpHeader->cmd = EVPCommand::EVPC_STATUS; evpHeader->size = client.sendBuffSize; + evpHeader->hton(); EVP_Status* evpStatus = new (client.sendBuff + sizeof(EVPHeader)) EVP_Status; evpStatus->status = status; + evpHeader->hton(); } diff --git a/FaceServer/ev_server.h b/FaceServer/ev_server.h index bb720b7..39639fe 100644 --- a/FaceServer/ev_server.h +++ b/FaceServer/ev_server.h @@ -9,7 +9,7 @@ #define SERVER_PORT 5432 #endif #define REUSEADDR_ON 1 -#define CLIENT_BUFFER_MAX 100*1024 // 100KB +#define CLIENT_BUFFER_MAX 1*1024*1024 // 1MB #define CLIENT_READ_TIMES_MAX 100 #define CLIENT_MAX 100 // max count of clients connected //#todo not support diff --git a/FaceServer/face_daemon_proto.h b/FaceServer/face_daemon_proto.h index eb475b6..4bc6e34 100644 --- a/FaceServer/face_daemon_proto.h +++ b/FaceServer/face_daemon_proto.h @@ -31,8 +31,10 @@ int16_t height; uint8_t buff[0]; - void hton();//#todo + void hton(); + void ntoh(); }; +//sizeof(FDP_Image)=10 struct FDP_FaceDetectPB { @@ -41,7 +43,8 @@ FDP_FaceDetectPB(int32_t _db_id) : db_id(_db_id) {} - void hton();//#todo + void hton(); + void ntoh(); }; struct FDP_FaceDetectResult @@ -52,7 +55,8 @@ FDP_FaceDetectResult(int32_t _db_id, int32_t _st_id) : db_id(_db_id), st_id(_st_id) {} - void hton();//#todo + void hton(); + void ntoh(); }; #pragma pack() diff --git a/FaceServer/main_face_daemon.cpp b/FaceServer/main_face_daemon.cpp index 4ddf3e7..6cfc437 100644 --- a/FaceServer/main_face_daemon.cpp +++ b/FaceServer/main_face_daemon.cpp @@ -107,6 +107,7 @@ { EVPHeader* evpHeader = (EVPHeader*)client.recvBuff; FDP_Image* fdpImage = (FDP_Image*)(client.recvBuff + sizeof(EVPHeader)); + fdpImage->ntoh(); STFaceImage stfaceImg; stfaceImg.db_id = fdpImage->db_id; @@ -116,13 +117,16 @@ stfaceImg.size = evpHeader->size - sizeof(EVPHeader) - sizeof(FDP_Image); stfaceImg.buff = fdpImage->buff; - //char imgfn[100 * 1024]; - //static int i = 0; - //sprintf(imgfn, "IMG_%d_%d_w%d_h%d.rgb565", stfaceImg.db_id, ++i, stfaceImg.width, stfaceImg.height); - //FILE * pFile = fopen(imgfn, "wb"); - //fwrite(stfaceImg.buff, sizeof(char), stfaceImg.size, pFile); - //fclose(pFile); - //pFile = nullptr; + LOGP(DEBUG, "stfaceImg db_id=%d, mb_type=%d, width=%d, height=%d, size=%d", + (int)stfaceImg.db_id, (int)stfaceImg.mb_type, (int)stfaceImg.width, (int)stfaceImg.height, (int)stfaceImg.size); + + char imgfn[100 * 1024]; + static int i = 0; + sprintf(imgfn, "IMG_%d_%d_w%d_h%d.rgb565", stfaceImg.db_id, ++i, stfaceImg.width, stfaceImg.height); + FILE * pFile = fopen(imgfn, "wb"); + fwrite(stfaceImg.buff, sizeof(char), stfaceImg.size, pFile); + fclose(pFile); + pFile = nullptr; fdr_vec_t result; FDP_FaceDetectResult fdrResult = g_STFaceCache.add(stfaceImg); @@ -162,7 +166,7 @@ bool ev_dispatcher_proto_rawbin(EVClientStub& client) { - LOG_DEBUG << "ev_dispatcher_proto_pb" << LOG_ENDL; + LOG_DEBUG << "ev_dispatcher_proto_rawbin" << LOG_ENDL; EVPHeader* evpHeader = (EVPHeader*)client.recvBuff; if (evpHeader->size != client.recvBuffSize) diff --git a/FaceServer/make.sh b/FaceServer/make.sh index af7de03..b0d607e 100644 --- a/FaceServer/make.sh +++ b/FaceServer/make.sh @@ -26,6 +26,7 @@ g++ $PIPELINE_BASE/Logger/src/logger.cc $CFLAGS $CPPFLAGS g++ ev_server.cpp -DUSER_DEFINE_EVCLIENT_PROC $CFLAGS $CPPFLAGS +g++ proto_hton_ntoh.cpp $CFLAGS $CPPFLAGS g++ $VISITFACE_BASE/PbFaceList.pb.cc $CFLAGS $CPPFLAGS g++ main_face_daemon.cpp $CFLAGS $CPPFLAGS g++ sample_face_search.cpp $CFLAGS $CPPFLAGS @@ -38,6 +39,7 @@ g++ -g -std=c++11 \ logger.o \ ev_server.o \ + proto_hton_ntoh.o \ PbFaceList.pb.o \ main_face_daemon.o \ sample_face_search.o \ diff --git a/FaceServer/proto_hton_ntoh.cpp b/FaceServer/proto_hton_ntoh.cpp new file mode 100644 index 0000000..02ce433 --- /dev/null +++ b/FaceServer/proto_hton_ntoh.cpp @@ -0,0 +1,73 @@ +#include "ev_proto.h" +#include "face_daemon_proto.h" +#include <netinet/in.h> + +void EVPHeader::hton() +{ + cmd = htons(cmd); + size = htonl(size); +} + +void EVPHeader::ntoh() +{ + cmd = ntohs(cmd); + size = ntohl(size); +} + +void EVP_Status::hton() +{ + status = htons(status); +} + +void EVP_Status::ntoh() +{ + status = ntohs(status); +} + +void EVP_VariableBuffer::hton() +{ + type = htons(type); +} + +void EVP_VariableBuffer::ntoh() +{ + type = ntohs(type); +} + +void FDP_Image::hton() +{ + db_id = htonl(db_id); + mb_type = htons(mb_type); + width = htons(width); + height = htons(height); +} + +void FDP_Image::ntoh() +{ + db_id = ntohl(db_id); + mb_type = ntohs(mb_type); + width = ntohs(width); + height = ntohs(height); +} + +void FDP_FaceDetectPB::hton() +{ + db_id = htonl(db_id); +} + +void FDP_FaceDetectPB::ntoh() +{ + db_id = ntohl(db_id); +} + +void FDP_FaceDetectResult::hton() +{ + db_id = htonl(db_id); + st_id = htonl(st_id); +} + +void FDP_FaceDetectResult::ntoh() +{ + db_id = ntohl(db_id); + st_id = ntohl(st_id); +} -- Gitblit v1.8.0