Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
b8c209b0
Unverified
Commit
b8c209b0
authored
Jun 15, 2018
by
Dominik Charousset
Committed by
GitHub
Jun 15, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #700
Add OpenSSL locking functions
parents
6c4b69e0
8881fae7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
1 deletion
+57
-1
libcaf_openssl/src/manager.cpp
libcaf_openssl/src/manager.cpp
+57
-1
No files found.
libcaf_openssl/src/manager.cpp
View file @
b8c209b0
...
@@ -23,6 +23,9 @@ CAF_PUSH_WARNINGS
...
@@ -23,6 +23,9 @@ CAF_PUSH_WARNINGS
#include <openssl/ssl.h>
#include <openssl/ssl.h>
CAF_POP_WARNINGS
CAF_POP_WARNINGS
#include <vector>
#include <mutex>
#include "caf/expected.hpp"
#include "caf/expected.hpp"
#include "caf/actor_system.hpp"
#include "caf/actor_system.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/scoped_actor.hpp"
...
@@ -35,11 +38,53 @@ CAF_POP_WARNINGS
...
@@ -35,11 +38,53 @@ CAF_POP_WARNINGS
#include "caf/openssl/middleman_actor.hpp"
#include "caf/openssl/middleman_actor.hpp"
struct
CRYPTO_dynlock_value
{
std
::
mutex
mtx
;
};
namespace
caf
{
namespace
caf
{
namespace
openssl
{
namespace
openssl
{
static
int
init_count
=
0
;
static
std
::
mutex
init_mutex
;
static
std
::
vector
<
std
::
mutex
>
mutexes
;
static
void
locking_function
(
int
mode
,
int
n
,
const
char
*
/* file */
,
int
/* line */
)
{
if
(
mode
&
CRYPTO_LOCK
)
mutexes
[
n
].
lock
();
else
mutexes
[
n
].
unlock
();
}
static
CRYPTO_dynlock_value
*
dynlock_create
(
const
char
*
/* file */
,
int
/* line */
)
{
return
new
CRYPTO_dynlock_value
{};
}
static
void
dynlock_lock
(
int
mode
,
CRYPTO_dynlock_value
*
dynlock
,
const
char
*
/* file */
,
int
/* line */
)
{
if
(
mode
&
CRYPTO_LOCK
)
dynlock
->
mtx
.
lock
();
else
dynlock
->
mtx
.
unlock
();
}
static
void
dynlock_destroy
(
CRYPTO_dynlock_value
*
dynlock
,
const
char
*
/* file */
,
int
/* line */
)
{
delete
dynlock
;
}
manager
::~
manager
()
{
manager
::~
manager
()
{
// nop
std
::
lock_guard
<
std
::
mutex
>
lock
{
init_mutex
};
--
init_count
;
if
(
init_count
==
0
)
{
CRYPTO_set_locking_callback
(
nullptr
);
CRYPTO_set_dynlock_create_callback
(
nullptr
);
CRYPTO_set_dynlock_lock_callback
(
nullptr
);
CRYPTO_set_dynlock_destroy_callback
(
nullptr
);
mutexes
=
std
::
vector
<
std
::
mutex
>
(
0
);
}
}
}
void
manager
::
start
()
{
void
manager
::
start
()
{
...
@@ -69,6 +114,17 @@ void manager::init(actor_system_config&) {
...
@@ -69,6 +114,17 @@ void manager::init(actor_system_config&) {
if
(
system
().
config
().
openssl_key
.
size
()
==
0
)
if
(
system
().
config
().
openssl_key
.
size
()
==
0
)
CAF_RAISE_ERROR
(
"No private key configured for SSL endpoint"
);
CAF_RAISE_ERROR
(
"No private key configured for SSL endpoint"
);
}
}
std
::
lock_guard
<
std
::
mutex
>
lock
{
init_mutex
};
++
init_count
;
if
(
init_count
==
1
)
{
mutexes
=
std
::
vector
<
std
::
mutex
>
(
CRYPTO_num_locks
());
CRYPTO_set_locking_callback
(
locking_function
);
CRYPTO_set_dynlock_create_callback
(
dynlock_create
);
CRYPTO_set_dynlock_lock_callback
(
dynlock_lock
);
CRYPTO_set_dynlock_destroy_callback
(
dynlock_destroy
);
// OpenSSL's default thread ID callback should work, so don't set our own.
}
}
}
actor_system
::
module
::
id_t
manager
::
id
()
const
{
actor_system
::
module
::
id_t
manager
::
id
()
const
{
...
...
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