Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
J
jami-daemon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
130
Issues
130
List
Boards
Labels
Service Desk
Milestones
Iterations
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
savoirfairelinux
jami-daemon
Commits
bf1dfb91
Commit
bf1dfb91
authored
Aug 11, 2019
by
Adrien Béraud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pupnp: wait on condition
Change-Id: I053ca22980267a8e2fd04e73e9a0c1e4a1064248
parent
eb7bde60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
35 deletions
+44
-35
src/upnp/protocol/pupnp/pupnp.cpp
src/upnp/protocol/pupnp/pupnp.cpp
+44
-35
No files found.
src/upnp/protocol/pupnp/pupnp.cpp
View file @
bf1dfb91
...
...
@@ -86,54 +86,63 @@ PUPnP::PUPnP()
pupnpThread_
=
std
::
thread
([
this
]
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
ctrlptMutex_
);
while
(
pupnpRun_
)
{
pupnpCv_
.
wait
(
lk
);
pupnpCv_
.
wait
(
lk
,
[
this
]{
return
not
clientRegistered_
or
not
pupnpRun_
or
searchForIgd_
or
not
dwnldlXmlList_
.
empty
();
});
if
(
not
clientRegistered_
)
{
// Register Upnp control point.
int
upnp_err
=
UpnpRegisterClient
(
ctrlPtCallback
,
this
,
&
ctrlptHandle_
);
if
(
upnp_err
!=
UPNP_E_SUCCESS
)
if
(
upnp_err
!=
UPNP_E_SUCCESS
)
{
JAMI_ERR
(
"PUPnP: Can't register client: %s"
,
UpnpGetErrorMessage
(
upnp_err
));
else
pupnpRun_
=
false
;
break
;
}
else
clientRegistered_
=
true
;
}
if
(
not
pupnpRun_
)
break
;
if
(
clientRegistered_
and
searchForIgd_
)
{
// Send out search for multiple types of devices, as some routers may possibly only reply to one.
UpnpSearchAsync
(
ctrlptHandle_
,
SEARCH_TIMEOUT
,
UPNP_ROOT_DEVICE
,
this
);
UpnpSearchAsync
(
ctrlptHandle_
,
SEARCH_TIMEOUT
,
UPNP_IGD_DEVICE
,
this
);
UpnpSearchAsync
(
ctrlptHandle_
,
SEARCH_TIMEOUT
,
UPNP_WANIP_SERVICE
,
this
);
UpnpSearchAsync
(
ctrlptHandle_
,
SEARCH_TIMEOUT
,
UPNP_WANPPP_SERVICE
,
this
);
// Reset variable.
searchForIgd_
=
false
;
}
if
(
clientRegistered_
)
{
auto
xmlList
=
std
::
move
(
dwnldlXmlList_
);
decltype
(
xmlList
)
finished
{};
// Wait on futures asynchronously
lk
.
unlock
();
for
(
auto
it
=
xmlList
.
begin
();
it
!=
xmlList
.
end
();)
{
if
(
it
->
wait_for
(
std
::
chrono
::
seconds
(
1
))
==
std
::
future_status
::
ready
)
{
finished
.
splice
(
finished
.
end
(),
xmlList
,
it
++
);
}
else
{
JAMI_WARN
(
"PUPnP: XML download timed out"
);
++
it
;
}
if
(
searchForIgd_
)
{
// Send out search for multiple types of devices, as some routers may possibly only reply to one.
UpnpSearchAsync
(
ctrlptHandle_
,
SEARCH_TIMEOUT
,
UPNP_ROOT_DEVICE
,
this
);
UpnpSearchAsync
(
ctrlptHandle_
,
SEARCH_TIMEOUT
,
UPNP_IGD_DEVICE
,
this
);
UpnpSearchAsync
(
ctrlptHandle_
,
SEARCH_TIMEOUT
,
UPNP_WANIP_SERVICE
,
this
);
UpnpSearchAsync
(
ctrlptHandle_
,
SEARCH_TIMEOUT
,
UPNP_WANPPP_SERVICE
,
this
);
// Reset variable.
searchForIgd_
=
false
;
}
lk
.
lock
();
// Move back failed items to end of list
dwnldlXmlList_
.
splice
(
dwnldlXmlList_
.
end
(),
xmlList
);
// Handle successful downloads
for
(
auto
&
item
:
finished
)
{
auto
result
=
item
.
get
();
if
(
not
result
.
document
or
not
validateIgd
(
result
))
{
cpDeviceList_
.
erase
(
result
.
location
);
if
(
not
dwnldlXmlList_
.
empty
())
{
auto
xmlList
=
std
::
move
(
dwnldlXmlList_
);
decltype
(
xmlList
)
finished
{};
// Wait on futures asynchronously
lk
.
unlock
();
for
(
auto
it
=
xmlList
.
begin
();
it
!=
xmlList
.
end
();)
{
if
(
it
->
wait_for
(
std
::
chrono
::
seconds
(
1
))
==
std
::
future_status
::
ready
)
{
finished
.
splice
(
finished
.
end
(),
xmlList
,
it
++
);
}
else
{
JAMI_WARN
(
"PUPnP: XML download timed out"
);
++
it
;
}
}
lk
.
lock
();
// Move back failed items to end of list
dwnldlXmlList_
.
splice
(
dwnldlXmlList_
.
end
(),
xmlList
);
// Handle successful downloads
for
(
auto
&
item
:
finished
)
{
auto
result
=
item
.
get
();
if
(
not
result
.
document
or
not
validateIgd
(
result
))
{
cpDeviceList_
.
erase
(
result
.
location
);
}
}
}
}
...
...
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