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
059690d8
Commit
059690d8
authored
Jul 13, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
socket发送动态分配内存修改实现方式,不使用结构体
parent
296c12ce
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
21 deletions
+39
-21
bin/config.ini
+2
-2
bin/log.conf
+2
-3
src/SocketModule.cpp
+28
-10
src/SocketModule.h
+5
-5
src/main.cpp
+2
-1
No files found.
bin/config.ini
View file @
059690d8
...
...
@@ -2,10 +2,10 @@
port
=
24446
[ODS]
ip
=
1
72.16.13.71
ip
=
1
03.13.247.72
pushPort
=
30001
recvPort
=
30002
socketTimeout
=
6
0
socketTimeout
=
12
0
[POS]
ip
=
127.0.0.1
...
...
bin/log.conf
View file @
059690d8
...
...
@@ -6,7 +6,7 @@
FILENAME
=
"./logs/log.log"
MILLISECONDS_WIDTH
=
3
PERFORMANCE_TRACKING
=
false
MAX_LOG_FILE_SIZE
=
1
0485760
MAX_LOG_FILE_SIZE
=
2
0485760
LOG_FLUSH_THRESHOLD
=
10
*
TRACE
:
...
...
@@ -28,4 +28,4 @@
FILENAME
=
"./logs/info_log.log"
*
VERBOSE
:
ENABLED
=
false
\ No newline at end of file
ENABLED
=
false
src/SocketModule.cpp
View file @
059690d8
...
...
@@ -203,23 +203,41 @@ void TCPClient::setSocketTimeout(int timeout)
//send
bool
TCPClient
::
send
(
const
std
::
string
&
message
)
{
bool
rlt
=
true
;
Packet
*
buf
=
nullptr
;
bool
rlt
=
true
;
int
msgLength
=
message
.
length
();
unsigned
int
msgNetLen
=
htonl
(
msgLength
);
char
*
tmpSend
=
new
char
[
msgLength
+
sizeof
(
msgNetLen
)];
memset
(
tmpSend
,
0
,
msgLength
+
sizeof
(
msgNetLen
));
memcpy
(
tmpSend
,
&
msgNetLen
,
sizeof
(
msgNetLen
));
memcpy
(
tmpSend
+
sizeof
(
msgNetLen
),
message
.
data
(),
msgLength
);
//LOG(INFO) << "message length:" << message.length();
int
msgLength
=
message
.
length
();
buf
=
(
Packet
*
)
malloc
(
msgLength
+
sizeof
(
Packet
));
memset
(
buf
,
0
,
msgLength
+
sizeof
(
Packet
));
buf
->
msgLen
=
htonl
(
message
.
length
());
strcpy
(
buf
->
text
,
message
.
c_str
());
if
(
writen
(
m_sockfd
,
buf
,
msgLength
+
sizeof
(
Packet
))
==
-
1
)
if
(
writen
(
m_sockfd
,
tmpSend
,
msgLength
+
sizeof
(
msgNetLen
))
==
-
1
)
{
m_bValid
=
false
;
rlt
=
false
;
}
free
(
buf
)
;
delete
[]
tmpSend
;
return
rlt
;
//----------------用结构体写法--------------
//bool rlt = true;
//Packet *buf = nullptr;
//
////LOG(INFO) << "message length:" << message.length();
//int msgLength = message.length();
//buf = (Packet *)malloc(msgLength + sizeof(Packet));
//memset(buf, 0, msgLength + sizeof(Packet));
//buf->msgLen = htonl(message.length());
//strcpy(buf->text, message.c_str());
//if (writen(m_sockfd, buf, msgLength + sizeof(Packet)) == -1)
//{
// m_bValid = false;
// rlt = false;
//}
//free(buf);
//return rlt;
}
bool
TCPClient
::
receive
(
std
::
string
&
message
)
{
...
...
src/SocketModule.h
View file @
059690d8
...
...
@@ -46,11 +46,11 @@ protected:
class
TCPClient
:
public
TCPSocket
{
private
:
struct
Packet
{
unsigned
int
msgLen
;
//数据部分的长度(网络字节序)
char
text
[
1
];
//报文的数据部分
};
//
struct Packet
//
{
//
unsigned int msgLen; //数据部分的长度(网络字节序)
//
char text[1]; //报文的数据部分
//
};
public:
TCPClient
()
:
m_bValid
(
false
){}
~
TCPClient
(){}
...
...
src/main.cpp
View file @
059690d8
...
...
@@ -11,6 +11,7 @@
//#pragma comment(lib,"../bin/sqlite3.lib")
#else
#include <pthread.h>
#include <unistd.h>
#endif
#define ELPP_NO_DEFAULT_LOG_FILE
...
...
@@ -254,7 +255,7 @@ int main(int argc,char *argv[])
el
::
Helpers
::
installPreRollOutCallback
(
logRolloutHandler
);
LOG
(
INFO
)
<<
"---------software start---------"
;
LOG
(
INFO
)
<<
"
---------"
<<
"version"
<<
VERSION
<<
"---------"
;
LOG
(
INFO
)
<<
"
version:"
<<
VERSION
;
// 读取配置文件信息
std
::
string
strIniPath
(
strBinPath
.
data
());
strIniPath
.
append
(
"config.ini"
);
...
...
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