Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dhtnet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
dhtnet
Commits
b04fbd7e
Commit
b04fbd7e
authored
1 year ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
upnp: use dedicated io_context if none provided
Change-Id: I8482f636007e3625576f5fc9f6f95c3d5be6d2bb
parent
c161aaa5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/upnp/upnp_context.h
+5
-0
5 additions, 0 deletions
include/upnp/upnp_context.h
src/upnp/upnp_context.cpp
+27
-1
27 additions, 1 deletion
src/upnp/upnp_context.cpp
with
32 additions
and
1 deletion
include/upnp/upnp_context.h
+
5
−
0
View file @
b04fbd7e
...
...
@@ -107,6 +107,8 @@ public:
UPnPContext
(
const
std
::
shared_ptr
<
asio
::
io_context
>&
ctx
,
const
std
::
shared_ptr
<
dht
::
log
::
Logger
>&
logger
);
~
UPnPContext
();
std
::
shared_ptr
<
asio
::
io_context
>
createIoContext
(
const
std
::
shared_ptr
<
asio
::
io_context
>&
ctx
,
const
std
::
shared_ptr
<
dht
::
log
::
Logger
>&
logger
);
// Terminate the instance.
void
shutdown
();
...
...
@@ -311,6 +313,9 @@ private:
// Shutdown synchronization
bool
shutdownComplete_
{
false
};
// Thread
std
::
unique_ptr
<
std
::
thread
>
ioContextRunner_
;
};
}
// namespace upnp
...
...
This diff is collapsed.
Click to expand it.
src/upnp/upnp_context.cpp
+
27
−
1
View file @
b04fbd7e
...
...
@@ -44,7 +44,7 @@ constexpr static uint16_t UPNP_UDP_PORT_MIN {20000};
constexpr
static
uint16_t
UPNP_UDP_PORT_MAX
{
UPNP_UDP_PORT_MIN
+
5000
};
UPnPContext
::
UPnPContext
(
const
std
::
shared_ptr
<
asio
::
io_context
>&
ioContext
,
const
std
::
shared_ptr
<
dht
::
log
::
Logger
>&
logger
)
:
mappingListUpdateTimer_
(
*
ioContext
),
ctx
(
ioContext
),
logger_
(
logger
)
:
ctx
(
createIoContext
(
ioContext
,
logger
)),
mappingListUpdateTimer_
(
*
ioContext
),
logger_
(
logger
)
{
if
(
logger_
)
logger_
->
debug
(
"Creating UPnPContext instance [{}]"
,
fmt
::
ptr
(
this
));
...
...
@@ -55,6 +55,25 @@ UPnPContext::UPnPContext(const std::shared_ptr<asio::io_context>& ioContext, con
ctx
->
post
([
this
]
{
init
();
});
}
std
::
shared_ptr
<
asio
::
io_context
>
UPnPContext
::
createIoContext
(
const
std
::
shared_ptr
<
asio
::
io_context
>&
ctx
,
const
std
::
shared_ptr
<
dht
::
log
::
Logger
>&
logger
)
{
if
(
ctx
)
{
return
ctx
;
}
else
{
if
(
logger
)
logger
->
debug
(
"UPnPContext: starting dedicated io_context thread"
);
auto
ioCtx
=
std
::
make_shared
<
asio
::
io_context
>
();
ioContextRunner_
=
std
::
make_unique
<
std
::
thread
>
([
ioCtx
,
l
=
logger
]()
{
try
{
auto
work
=
asio
::
make_work_guard
(
*
ioCtx
);
ioCtx
->
run
();
}
catch
(
const
std
::
exception
&
ex
)
{
if
(
l
)
l
->
error
(
"Unexpected io_context thread exception: {}"
,
ex
.
what
());
}
});
return
ioCtx
;
}
}
void
UPnPContext
::
shutdown
(
std
::
condition_variable
&
cv
)
{
...
...
@@ -75,6 +94,13 @@ UPnPContext::shutdown(std::condition_variable& cv)
shutdownComplete_
=
true
;
cv
.
notify_one
();
}
if
(
ioContextRunner_
)
{
if
(
logger_
)
logger_
->
debug
(
"UPnPContext: stopping io_context thread"
);
ctx
->
stop
();
ioContextRunner_
->
join
();
ioContextRunner_
.
reset
();
}
}
void
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment