Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
dcdb
dcdb
Commits
e2426341
Commit
e2426341
authored
Mar 22, 2019
by
Daniele Tafani
Browse files
Made the PDU plugin thread-safe.
parent
a674f138
Changes
3
Hide whitespace changes
Inline
Side-by-side
dcdbpusher/sensors/pdu/PDUSensorGroup.cpp
View file @
e2426341
...
...
@@ -35,7 +35,7 @@ PDUSensorGroup& PDUSensorGroup::operator=(const PDUSensorGroup& other) {
void
PDUSensorGroup
::
init
(
boost
::
asio
::
io_service
&
io
)
{
SensorGroupTemplate
::
init
(
io
);
if
(
_pdu
)
{
_pdu
->
init
ializeStrand
(
io
);
_pdu
->
init
(
io
);
}
else
{
LOG
(
error
)
<<
"No PDUUnit set for sensorgroup "
<<
_groupName
<<
"! Cannot initialize sensor."
;
}
...
...
@@ -129,6 +129,7 @@ void PDUSensorGroup::read() {
throw
std
::
runtime_error
(
"Value not found!"
);
}
reading
.
value
=
stoll
(
readStr
);
#ifdef DEBUG
LOG
(
debug
)
<<
_groupName
<<
"::"
<<
s
->
getName
()
<<
" raw reading:
\"
"
<<
reading
.
value
<<
"
\"
"
;
#endif
...
...
dcdbpusher/sensors/pdu/PDUUnit.cpp
View file @
e2426341
...
...
@@ -9,39 +9,43 @@
#include
<iostream>
#include
<openssl/ssl.h>
#include
<openssl/err.h>
#include
<openssl/bio.h>
PDUUnit
::
PDUUnit
()
{
_host
=
""
;
_strand
=
nullptr
;
_ctx
=
nullptr
;
}
PDUUnit
::~
PDUUnit
()
{
if
(
_strand
)
{
delete
_strand
;
}
if
(
_ctx
)
{
SSL_CTX_free
(
_ctx
);
}
}
void
PDUUnit
::
init
ializeStrand
(
boost
::
asio
::
io_service
&
io
)
{
void
PDUUnit
::
init
(
boost
::
asio
::
io_service
&
io
)
{
if
(
!
_strand
)
{
_strand
=
new
boost
::
asio
::
io_service
::
strand
(
io
);
}
SSL_library_init
();
SSL_load_error_strings
();
ERR_load_BIO_strings
();
OpenSSL_add_all_algorithms
();
_ctx
=
SSL_CTX_new
(
SSLv23_method
());
}
bool
PDUUnit
::
sendRequest
(
const
std
::
string
&
request
,
std
::
string
&
response
)
{
SSL_library_init
();
SSL_load_error_strings
();
ERR_load_BIO_strings
();
OpenSSL_add_all_algorithms
();
SSL_CTX
*
ctx
;
BIO
*
bio
;
ctx
=
SSL_CTX_new
(
SSLv23_method
());
if
(
!
ctx
)
{
if
(
!
_ctx
)
{
LOG
(
error
)
<<
"OpenSSL: Could not create context: "
<<
ERR_reason_error_string
(
ERR_get_error
());
return
false
;
}
...
...
@@ -54,7 +58,7 @@ bool PDUUnit::sendRequest(const std::string& request, std::string& response) {
}
*/
bio
=
BIO_new_ssl_connect
(
ctx
);
bio
=
BIO_new_ssl_connect
(
_
ctx
);
BIO_set_conn_hostname
(
bio
,
_host
.
c_str
());
...
...
@@ -62,7 +66,6 @@ bool PDUUnit::sendRequest(const std::string& request, std::string& response) {
{
LOG
(
error
)
<<
"OpenSSL: Could not connect: "
<<
ERR_reason_error_string
(
ERR_get_error
());
BIO_free_all
(
bio
);
SSL_CTX_free
(
ctx
);
return
false
;
}
...
...
@@ -78,7 +81,6 @@ bool PDUUnit::sendRequest(const std::string& request, std::string& response) {
if
(
BIO_write
(
bio
,
reqBuf
,
len
)
<=
0
)
{
LOG
(
error
)
<<
"OpenSSL: Could not send request: "
<<
ERR_reason_error_string
(
ERR_get_error
());
BIO_free_all
(
bio
);
SSL_CTX_free
(
ctx
);
return
false
;
}
...
...
@@ -92,12 +94,10 @@ bool PDUUnit::sendRequest(const std::string& request, std::string& response) {
if
(
len
<
0
)
{
std
::
cerr
<<
"OpenSSL: Could not read response: "
<<
ERR_reason_error_string
(
ERR_get_error
())
<<
std
::
endl
;
BIO_free_all
(
bio
);
SSL_CTX_free
(
ctx
);
return
false
;
}
BIO_free_all
(
bio
);
SSL_CTX_free
(
ctx
);
return
true
;
}
...
...
dcdbpusher/sensors/pdu/PDUUnit.h
View file @
e2426341
...
...
@@ -16,7 +16,7 @@
#include
<boost/asio.hpp>
#include
<boost/property_tree/ptree.hpp>
#include
"logging.h"
#include
<openssl/ssl.h>
typedef
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
attributesVector_t
;
typedef
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
,
attributesVector_t
>>
xmlPathVector_t
;
...
...
@@ -36,7 +36,7 @@ public:
_host
=
host
+
":443"
;
}
}
void
init
ializeStrand
(
boost
::
asio
::
io_service
&
io
);
void
init
(
boost
::
asio
::
io_service
&
io
);
const
std
::
string
&
getHost
()
{
return
_host
;
}
boost
::
asio
::
io_service
::
strand
*
getStrand
()
const
{
return
_strand
;
}
...
...
@@ -57,7 +57,7 @@ private:
std
::
string
_host
;
boost
::
asio
::
io_service
::
strand
*
_strand
;
SSL_CTX
*
_ctx
;
LOGGER
lg
;
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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