Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
familyMart_takeaway
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guanghui.cui
familyMart_takeaway
Commits
62ab5cfd
Commit
62ab5cfd
authored
May 21, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复内存分配不足问题
parent
04ef5760
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
9 deletions
+33
-9
bin/config.ini
+1
-1
src/SocketModule.cpp
+25
-1
src/SocketModule.h
+2
-2
src/main.cpp
+5
-5
No files found.
bin/config.ini
View file @
62ab5cfd
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
port
=
24446
port
=
24446
[ODS]
[ODS]
ip
=
1
27.0.0.
1
ip
=
1
72.16.13.7
1
pushPort
=
30001
pushPort
=
30001
recvPort
=
30002
recvPort
=
30002
socketTimeout
=
60
socketTimeout
=
60
...
...
src/SocketModule.cpp
View file @
62ab5cfd
#include "SocketModule.h"
#include "SocketModule.h"
#include <stdio.h>
#include <stdio.h>
#include "../3rdParty/easylogging/easylogging++.h"
TCPSocket
::
TCPSocket
()
:
m_sockfd
(
-
1
){}
TCPSocket
::
TCPSocket
()
:
m_sockfd
(
-
1
){}
TCPSocket
::~
TCPSocket
()
TCPSocket
::~
TCPSocket
()
...
@@ -19,6 +20,30 @@ bool TCPSocket::create()
...
@@ -19,6 +20,30 @@ bool TCPSocket::create()
close
();
close
();
if
((
m_sockfd
=
::
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
==
-
1
)
if
((
m_sockfd
=
::
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
==
-
1
)
return
false
;
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
;
return
true
;
}
}
...
@@ -192,7 +217,6 @@ bool TCPClient::receive(std::string &message)
...
@@ -192,7 +217,6 @@ bool TCPClient::receive(std::string &message)
m_bValid
=
false
;
m_bValid
=
false
;
return
false
;
return
false
;
}
}
//然后读取数据部分
//然后读取数据部分
unsigned
int
lenHost
=
ntohl
(
buf
.
msgLen
);
unsigned
int
lenHost
=
ntohl
(
buf
.
msgLen
);
readBytes
=
readn
(
m_sockfd
,
buf
.
text
,
lenHost
);
readBytes
=
readn
(
m_sockfd
,
buf
.
text
,
lenHost
);
...
...
src/SocketModule.h
View file @
62ab5cfd
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
#include <fcntl.h>
#include <fcntl.h>
#endif
#endif
#define
BUF_SIZE 1024*6
#define
FM_BUF_SIZE 1024*15
class
TCPSocket
class
TCPSocket
{
{
...
@@ -49,7 +49,7 @@ private:
...
@@ -49,7 +49,7 @@ private:
struct
Packet
struct
Packet
{
{
unsigned
int
msgLen
;
//数据部分的长度(网络字节序)
unsigned
int
msgLen
;
//数据部分的长度(网络字节序)
char
text
[
BUF_SIZE
];
//报文的数据部分
char
text
[
FM_
BUF_SIZE
];
//报文的数据部分
};
};
public
:
public
:
TCPClient
()
:
m_bValid
(
false
){}
TCPClient
()
:
m_bValid
(
false
){}
...
...
src/main.cpp
View file @
62ab5cfd
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
INITIALIZE_EASYLOGGINGPP
INITIALIZE_EASYLOGGINGPP
#define VERSION "1.0.
3 Beta 4
" //版本号
#define VERSION "1.0.
5
" //版本号
std
::
string
g_init_data
;
std
::
string
g_init_data
;
std
::
string
g_init_data_ods_back
;
std
::
string
g_init_data_ods_back
;
...
@@ -80,7 +80,7 @@ void* listen_pos_func(void* arg)
...
@@ -80,7 +80,7 @@ void* listen_pos_func(void* arg)
if
(
server
.
accept
(
pos
)
)
if
(
server
.
accept
(
pos
)
)
{
{
char
tmpBuf
[
BUF_SIZE
]
=
{
0
};
char
tmpBuf
[
FM_
BUF_SIZE
]
=
{
0
};
if
(
pos
.
read
(
tmpBuf
,
sizeof
(
tmpBuf
))
)
if
(
pos
.
read
(
tmpBuf
,
sizeof
(
tmpBuf
))
)
{
{
posRequestData
=
tmpBuf
;
posRequestData
=
tmpBuf
;
...
@@ -339,7 +339,7 @@ int main(int argc,char *argv[])
...
@@ -339,7 +339,7 @@ int main(int argc,char *argv[])
while
(
true
)
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,\"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
(
!
g_init_data
.
empty
())
{
{
if
(
ods
.
send
(
g_init_data
)
)
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
...
@@ -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
())
)
if
(
pos
.
write
(
order_json
.
c_str
())
)
{
{
char
tmpBuf
[
BUF_SIZE
]
=
{
0
};
char
tmpBuf
[
FM_
BUF_SIZE
]
=
{
0
};
if
(
pos
.
read
(
tmpBuf
,
sizeof
(
tmpBuf
))
)
if
(
pos
.
read
(
tmpBuf
,
sizeof
(
tmpBuf
))
)
{
{
LOG
(
INFO
)
<<
"POS ===>> PLUGIN:"
<<
tmpBuf
;
LOG
(
INFO
)
<<
"POS ===>> PLUGIN:"
<<
tmpBuf
;
...
@@ -535,7 +535,7 @@ void kill_origin_process()
...
@@ -535,7 +535,7 @@ void kill_origin_process()
std
::
string
tmp
=
"{
\"
fm_cmd
\"
: -1}"
;
std
::
string
tmp
=
"{
\"
fm_cmd
\"
: -1}"
;
if
(
pos
.
doConnect
(
client_listen_port
,
pos_ip
.
c_str
())){
if
(
pos
.
doConnect
(
client_listen_port
,
pos_ip
.
c_str
())){
if
(
pos
.
write
(
tmp
.
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
))){
if
(
pos
.
read
(
tmpBuf
,
sizeof
(
tmpBuf
))){
LOG
(
INFO
)
<<
"kill back:"
<<
tmpBuf
;
LOG
(
INFO
)
<<
"kill back:"
<<
tmpBuf
;
if
(
strcmp
(
tmpBuf
,
"100"
)
==
0
)
{
if
(
strcmp
(
tmpBuf
,
"100"
)
==
0
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment