Commit 62ab5cfd by guanghui.cui

修复内存分配不足问题

parent 04ef5760
......@@ -2,7 +2,7 @@
port=24446
[ODS]
ip=127.0.0.1
ip=172.16.13.71
pushPort=30001
recvPort=30002
socketTimeout=60
......
#include "SocketModule.h"
#include <stdio.h>
#include "../3rdParty/easylogging/easylogging++.h"
TCPSocket::TCPSocket(): m_sockfd(-1){}
TCPSocket::~TCPSocket()
......@@ -19,6 +20,30 @@ bool TCPSocket::create()
close();
if ((m_sockfd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1)
return false;
//查看默认 发送/接收 缓存区大小
// int rcvbuf_len;
//#ifdef WIN32
// int len;
//#else
// socklen_t len;
//#endif // WIN32
//
// len = sizeof(rcvbuf_len);
// if (getsockopt(m_sockfd, SOL_SOCKET, SO_RCVBUF, (char *)&rcvbuf_len, &len) < 0) {
// perror("getsockopt: ");
// return -1;
// }
// LOG(INFO) << "the recevice buf len:" << rcvbuf_len;
//
// int sendbuf_len;
// len = sizeof(sendbuf_len);
// if (getsockopt(m_sockfd, SOL_SOCKET, SO_SNDBUF, (char *)&sendbuf_len, &len) < 0) {
// perror("getsockopt: ");
// return -1;
// }
// LOG(INFO) << "the send buf len:" << sendbuf_len;
return true;
}
......@@ -192,7 +217,6 @@ bool TCPClient::receive(std::string &message)
m_bValid = false;
return false;
}
//然后读取数据部分
unsigned int lenHost = ntohl(buf.msgLen);
readBytes = readn(m_sockfd, buf.text, lenHost);
......
......@@ -19,7 +19,7 @@
#include <fcntl.h>
#endif
#define BUF_SIZE 1024*6
#define FM_BUF_SIZE 1024*15
class TCPSocket
{
......@@ -49,7 +49,7 @@ private:
struct Packet
{
unsigned int msgLen; //数据部分的长度(网络字节序)
char text[BUF_SIZE]; //报文的数据部分
char text[FM_BUF_SIZE]; //报文的数据部分
};
public:
TCPClient():m_bValid(false){}
......
......@@ -18,7 +18,7 @@
INITIALIZE_EASYLOGGINGPP
#define VERSION "1.0.3 Beta 4" //版本号
#define VERSION "1.0.5" //版本号
std::string g_init_data;
std::string g_init_data_ods_back;
......@@ -80,7 +80,7 @@ void* listen_pos_func(void* arg)
if( server.accept(pos) )
{
char tmpBuf[BUF_SIZE] = {0};
char tmpBuf[FM_BUF_SIZE] = {0};
if( pos.read(tmpBuf, sizeof(tmpBuf)) )
{
posRequestData = tmpBuf;
......@@ -339,7 +339,7 @@ int main(int argc,char *argv[])
while(true)
{
//g_init_data = "{\"fm_cmd\": 1000,\"storeId\": \"208888\",\"pos_id\": \"0001\",\"operator_id\": \"00001\",\"business_date\": \"20171225\",\"is_master\": true,\"listen_port\": 3289,\"ver\":1}";
//g_init_data = "{\"fm_cmd\":1000,\"listen_port\":24445,\"storeId\":\"202557\",\"pos_id\":\"1\",\"operator_id\":\"17076352\",\"is_master\":true,\"ver\":1}";
if(!g_init_data.empty())
{
if( ods.send(g_init_data) )
......@@ -470,7 +470,7 @@ bool order_send_to_pos(IN std::string &order_json,IN std::string &ods_json,OUT s
{
if( pos.write(order_json.c_str()) )
{
char tmpBuf[BUF_SIZE] = {0};
char tmpBuf[FM_BUF_SIZE] = {0};
if( pos.read(tmpBuf,sizeof(tmpBuf)) )
{
LOG(INFO) << "POS ===>> PLUGIN:"<<tmpBuf;
......@@ -535,7 +535,7 @@ void kill_origin_process()
std::string tmp = "{\"fm_cmd\": -1}";
if (pos.doConnect(client_listen_port, pos_ip.c_str())){
if (pos.write(tmp.c_str())){
char tmpBuf[BUF_SIZE] = { 0 };
char tmpBuf[FM_BUF_SIZE] = { 0 };
if (pos.read(tmpBuf, sizeof(tmpBuf))){
LOG(INFO) << "kill back:" << tmpBuf;
if (strcmp(tmpBuf, "100") == 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment