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
589f752d
Commit
589f752d
authored
Aug 24, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Переход на libPoco]: рефакторинг: чистка от лишних функций
parent
2d036c4c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
13 additions
and
75 deletions
+13
-75
UTCPSocket.h
include/UTCPSocket.h
+1
-9
UTCPStream.h
include/UTCPStream.h
+0
-16
ModbusTCPCore.h
include/modbus/ModbusTCPCore.h
+3
-3
ModbusTCPCore.cc
src/Communications/Modbus/ModbusTCPCore.cc
+6
-6
ModbusTCPMaster.cc
src/Communications/Modbus/ModbusTCPMaster.cc
+1
-1
ModbusTCPServer.cc
src/Communications/Modbus/ModbusTCPServer.cc
+1
-1
UTCPSocket.cc
src/Communications/TCP/UTCPSocket.cc
+1
-23
UTCPStream.cc
src/Communications/TCP/UTCPStream.cc
+0
-16
No files found.
include/UTCPSocket.h
View file @
589f752d
...
...
@@ -24,18 +24,10 @@ class UTCPSocket:
// return true if OK
bool
setKeepAliveParams
(
timeout_t
timeout_sec
=
5
,
int
conn_keepcnt
=
1
,
int
keepintvl
=
2
);
/*!
* Enable/disable delaying packets (Nagle algorithm)
*
* @return true on success.
* @param enable disable Nagle algorithm when set to true.
*/
bool
setNoDelay
(
bool
enable
);
int
getSocket
();
protected
:
void
init
(
bool
throwflag
=
false
);
void
init
();
private
:
...
...
include/UTCPStream.h
View file @
589f752d
...
...
@@ -45,23 +45,7 @@ class UTCPStream:
bool
isSetLinger
()
const
;
void
forceDisconnect
();
// disconnect() без ожидания (с отключением SO_LINGER)
/*!
* Enable/disable delaying packets (Nagle algorithm)
*
* @return true on success.
* @param enable disable Nagle algorithm when set to true.
*/
bool
setNoDelay
(
bool
enable
);
// --------------------------------------------------------------------
// Пришлось вынести эти функции read/write[Data] в public
// т.к. они сразу "посылают" данные в канал, в отличие от operator<<
// который у TCPStream (или std::iostream?) буферизует их и из-за этого
// не позволяет работать с отправкой коротких сообщений
// --------------------------------------------------------------------
ssize_t
writeData
(
const
void
*
buf
,
size_t
len
,
timeout_t
t
=
0
);
ssize_t
readData
(
void
*
buf
,
size_t
len
,
char
separator
=
0
,
timeout_t
t
=
0
);
int
getSocket
()
const
;
timeout_t
getTimeout
()
const
;
...
...
include/modbus/ModbusTCPCore.h
View file @
589f752d
...
...
@@ -12,9 +12,9 @@ namespace ModbusTCPCore
// Если соединение закрыто (другой стороной), функции выкидывают исключение UniSetTypes::CommFailed
// t - msec (сколько ждать)
size_t
readNextData
(
UTCPStream
*
tcp
,
std
::
queue
<
unsigned
char
>&
qrecv
,
size_t
max
=
100
,
timeout_t
t
=
50
);
size_t
getNextData
(
UTCPStream
*
tcp
,
std
::
queue
<
unsigned
char
>&
qrecv
,
unsigned
char
*
buf
,
size_t
len
,
timeout_t
t
=
50
);
ModbusRTU
::
mbErrCode
sendData
(
UTCPStream
*
tcp
,
unsigned
char
*
buf
,
size_t
len
,
timeout_t
t
=
50
);
size_t
readNextData
(
UTCPStream
*
tcp
,
std
::
queue
<
unsigned
char
>&
qrecv
,
size_t
max
=
100
);
size_t
getNextData
(
UTCPStream
*
tcp
,
std
::
queue
<
unsigned
char
>&
qrecv
,
unsigned
char
*
buf
,
size_t
len
);
ModbusRTU
::
mbErrCode
sendData
(
UTCPStream
*
tcp
,
unsigned
char
*
buf
,
size_t
len
);
// работа напрямую с сокетом
size_t
readDataFD
(
int
fd
,
std
::
queue
<
unsigned
char
>&
qrecv
,
size_t
max
=
100
,
size_t
attempts
=
1
);
...
...
src/Communications/Modbus/ModbusTCPCore.cc
View file @
589f752d
...
...
@@ -25,7 +25,7 @@ using namespace ModbusRTU;
#define DEFAULT_BUFFER_SIZE_FOR_READ 255
// -------------------------------------------------------------------------
size_t
ModbusTCPCore
::
readNextData
(
UTCPStream
*
tcp
,
std
::
queue
<
unsigned
char
>&
qrecv
,
size_t
max
,
timeout_t
t
)
std
::
queue
<
unsigned
char
>&
qrecv
,
size_t
max
)
{
if
(
!
tcp
)
// || !tcp->available() )
return
0
;
...
...
@@ -44,7 +44,7 @@ size_t ModbusTCPCore::readNextData(UTCPStream* tcp,
try
{
ssize_t
l
=
tcp
->
re
adData
(
buf
,
max
,
0
,
t
);
ssize_t
l
=
tcp
->
re
ceiveBytes
(
buf
,
max
);
if
(
l
>
0
)
{
...
...
@@ -101,7 +101,7 @@ size_t ModbusTCPCore::readNextData(UTCPStream* tcp,
// ------------------------------------------------------------------------
size_t
ModbusTCPCore
::
getNextData
(
UTCPStream
*
tcp
,
std
::
queue
<
unsigned
char
>&
qrecv
,
unsigned
char
*
buf
,
size_t
len
,
timeout_t
t
)
unsigned
char
*
buf
,
size_t
len
)
{
if
(
qrecv
.
empty
()
||
qrecv
.
size
()
<
len
)
{
...
...
@@ -111,7 +111,7 @@ size_t ModbusTCPCore::getNextData(UTCPStream* tcp,
if
(
len
<=
0
)
len
=
7
;
size_t
ret
=
ModbusTCPCore
::
readNextData
(
tcp
,
qrecv
,
len
,
t
);
size_t
ret
=
ModbusTCPCore
::
readNextData
(
tcp
,
qrecv
,
len
);
if
(
ret
==
0
)
return
0
;
...
...
@@ -223,14 +223,14 @@ size_t ModbusTCPCore::getDataFD( int fd, std::queue<unsigned char>& qrecv,
return
i
;
}
// -------------------------------------------------------------------------
mbErrCode
ModbusTCPCore
::
sendData
(
UTCPStream
*
tcp
,
unsigned
char
*
buf
,
size_t
len
,
timeout_t
t
)
mbErrCode
ModbusTCPCore
::
sendData
(
UTCPStream
*
tcp
,
unsigned
char
*
buf
,
size_t
len
)
{
if
(
!
tcp
)
// || !tcp->available() )
return
erTimeOut
;
try
{
ssize_t
l
=
tcp
->
writeData
(
buf
,
len
,
t
);
ssize_t
l
=
tcp
->
sendBytes
(
buf
,
len
);
if
(
l
==
len
)
return
erNoError
;
...
...
src/Communications/Modbus/ModbusTCPMaster.cc
View file @
589f752d
...
...
@@ -50,7 +50,7 @@ ModbusTCPMaster::~ModbusTCPMaster()
// -------------------------------------------------------------------------
size_t
ModbusTCPMaster
::
getNextData
(
unsigned
char
*
buf
,
size_t
len
)
{
return
ModbusTCPCore
::
getNextData
(
tcp
.
get
(),
qrecv
,
buf
,
len
,
readTimeout
);
return
ModbusTCPCore
::
getNextData
(
tcp
.
get
(),
qrecv
,
buf
,
len
);
}
// -------------------------------------------------------------------------
void
ModbusTCPMaster
::
setChannelTimeout
(
timeout_t
msec
)
...
...
src/Communications/Modbus/ModbusTCPServer.cc
View file @
589f752d
...
...
@@ -49,7 +49,7 @@ ModbusTCPServer::ModbusTCPServer( const std::string& ia, int _port ):
ModbusTCPServer
::~
ModbusTCPServer
()
{
}
// --------------------
w
-----------------------------------------------------
// -------------------------------------------------------------------------
void
ModbusTCPServer
::
setMaxSessions
(
size_t
num
)
{
if
(
num
<
sessCount
)
...
...
src/Communications/TCP/UTCPSocket.cc
View file @
589f752d
...
...
@@ -23,21 +23,6 @@ UTCPSocket::UTCPSocket()
UTCPSocket
::
UTCPSocket
(
int
sock
)
:
Poco
::
Net
::
ServerSocket
(
sock
)
{
/*
struct sockaddr_in client_addr;
socklen_t client_len = sizeof(client_addr);
so = accept(sock, (struct sockaddr*)&client_addr, &client_len);
if( so < 0 )
{
endServerServerSocket();
error(errConnectRejected);
return;
}
ServerServerSocket::state = CONNECTED;
*/
init
();
}
// -------------------------------------------------------------------------
...
...
@@ -52,20 +37,13 @@ bool UTCPSocket::setKeepAliveParams(timeout_t timeout_sec, int keepcnt, int keep
return
UTCPCore
::
setKeepAliveParams
(
Poco
::
Net
::
ServerSocket
::
sockfd
()
,
timeout_sec
,
keepcnt
,
keepintvl
);
}
// -------------------------------------------------------------------------
bool
UTCPSocket
::
setNoDelay
(
bool
enable
)
{
Poco
::
Net
::
ServerSocket
::
setNoDelay
(
enable
);
return
(
Poco
::
Net
::
ServerSocket
::
getNoDelay
()
==
enable
);
}
// -------------------------------------------------------------------------
int
UTCPSocket
::
getSocket
()
{
return
Poco
::
Net
::
ServerSocket
::
sockfd
();
}
// -------------------------------------------------------------------------
void
UTCPSocket
::
init
(
bool
throwflag
)
void
UTCPSocket
::
init
()
{
// setError(throwflag);
Poco
::
Net
::
ServerSocket
::
setKeepAlive
(
true
);
Poco
::
Net
::
ServerSocket
::
setLinger
(
true
,
1
);
setKeepAliveParams
();
...
...
src/Communications/TCP/UTCPStream.cc
View file @
589f752d
...
...
@@ -73,22 +73,6 @@ void UTCPStream::forceDisconnect()
}
}
// -------------------------------------------------------------------------
bool
UTCPStream
::
setNoDelay
(
bool
enable
)
{
Poco
::
Net
::
StreamSocket
::
setNoDelay
(
enable
);
return
(
Poco
::
Net
::
StreamSocket
::
getNoDelay
()
==
enable
);
}
// -------------------------------------------------------------------------
ssize_t
UTCPStream
::
writeData
(
const
void
*
buf
,
size_t
len
,
timeout_t
t
)
{
return
Poco
::
Net
::
StreamSocket
::
sendBytes
(
buf
,
len
);
}
// -------------------------------------------------------------------------
ssize_t
UTCPStream
::
readData
(
void
*
buf
,
size_t
len
,
char
separator
,
timeout_t
t
)
{
return
Poco
::
Net
::
StreamSocket
::
receiveBytes
(
buf
,
len
);
}
// -------------------------------------------------------------------------
int
UTCPStream
::
getSocket
()
const
{
return
Poco
::
Net
::
StreamSocket
::
sockfd
();
...
...
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