Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
8f722848
Commit
8f722848
authored
Apr 28, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ModbusTCPCore: сделал чтение не по одному байту, а сразу "много"
parent
003f7f6a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
21 deletions
+57
-21
ModbusTCPCore.cc
src/Communications/Modbus/ModbusTCPCore.cc
+57
-21
No files found.
src/Communications/Modbus/ModbusTCPCore.cc
View file @
8f722848
...
...
@@ -19,6 +19,8 @@
using
namespace
std
;
using
namespace
ModbusRTU
;
// -------------------------------------------------------------------------
#define USE_BUFFER_FOR_READ 1
// -------------------------------------------------------------------------
size_t
ModbusTCPCore
::
readNextData
(
UTCPStream
*
tcp
,
std
::
queue
<
unsigned
char
>&
qrecv
,
size_t
max
,
timeout_t
t
)
{
...
...
@@ -27,10 +29,35 @@ size_t ModbusTCPCore::readNextData(UTCPStream* tcp,
size_t
i
=
0
;
#ifdef USE_BUFFER_FOR_READ
char
*
buf
=
new
char
[
max
];
if
(
buf
==
0
)
return
0
;
try
{
ssize_t
l
=
tcp
->
readData
(
buf
,
max
,
0
,
t
);
if
(
l
>
0
)
{
for
(
ssize_t
k
=
0
;
k
<
l
;
k
++
)
qrecv
.
push
(
buf
[
k
]);
i
=
l
;
}
}
catch
(
ost
::
SockException
&
e
)
{
}
delete
[]
buf
;
#else
try
{
for
(
;
i
<
max
;
i
++
)
{
// (не оптимально): читаем один символ за раз..
unsigned
char
c
;
ssize_t
l
=
tcp
->
readData
(
&
c
,
sizeof
(
c
),
0
,
t
);
...
...
@@ -43,6 +70,8 @@ size_t ModbusTCPCore::readNextData(UTCPStream* tcp,
catch
(
ost
::
SockException
&
e
)
{
}
#endif
return
i
;
}
...
...
@@ -78,43 +107,50 @@ size_t ModbusTCPCore::getNextData(UTCPStream* tcp,
// -------------------------------------------------------------------------
size_t
ModbusTCPCore
::
readDataFD
(
int
fd
,
std
::
queue
<
unsigned
char
>&
qrecv
,
size_t
max
,
size_t
attempts
)
{
size_t
i
=
0
;
#if 1
#ifdef USE_BUFFER_FOR_READ
char
*
buf
=
new
char
[
max
];
if
(
buf
==
0
)
return
0
;
ssize_t
l
=
0
;
size_t
cnt
=
0
;
for
(
size_t
a
=
0
;
a
<
attempts
;
a
++
)
{
for
(
;
i
<
max
;
i
++
)
l
=
::
read
(
fd
,
buf
,
max
);
if
(
l
>
0
)
{
// читаем один символ за раз..
unsigned
char
c
;
ssize_t
l
=
::
read
(
fd
,
&
c
,
sizeof
(
c
));
for
(
int
k
=
0
;
k
<
l
;
k
++
)
qrecv
.
push
(
buf
[
k
]);
if
(
l
<=
0
)
cnt
+=
l
;
if
(
cnt
>=
max
)
break
;
qrecv
.
push
(
c
);
}
}
delete
[]
buf
;
#else
char
*
buf
=
new
char
[
max
];
ssize_t
l
=
0
;
size_t
i
=
0
;
for
(
size_t
a
=
0
;
a
<
attempts
;
a
++
)
{
l
=
::
read
(
fd
,
buf
,
sizeof
(
buf
));
for
(
;
i
<
max
;
i
++
)
{
// (не оптимально): читаем один символ за раз..
unsigned
char
c
;
ssize_t
l
=
::
read
(
fd
,
&
c
,
sizeof
(
c
));
if
(
l
>
0
)
break
;
}
if
(
l
<=
0
)
break
;
if
(
l
>
0
)
{
for
(
int
i
=
0
;
i
<
l
;
i
++
)
qrecv
.
push
(
buf
[
i
]);
qrecv
.
push
(
c
);
}
}
delete
[]
buf
;
#endif
return
(
qrecv
.
size
()
>=
max
?
max
:
qrecv
.
size
()
);
...
...
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