Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
f3b758c9
Commit
f3b758c9
authored
4 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
data transfer: use timer instead of thread
Change-Id: Ib9139ab9a826cc134cde5fb47e742a45914343de
parent
891f29c3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/data_transfer.cpp
+12
-20
12 additions, 20 deletions
src/data_transfer.cpp
with
12 additions
and
20 deletions
src/data_transfer.cpp
+
12
−
20
View file @
f3b758c9
...
...
@@ -355,8 +355,7 @@ private:
mutable
bool
headerSent_
{
false
};
bool
peerReady_
{
false
};
const
std
::
string
peerUri_
;
mutable
std
::
unique_ptr
<
std
::
thread
>
timeoutThread_
;
mutable
std
::
atomic_bool
stopTimeout_
{
false
};
mutable
std
::
shared_ptr
<
Task
>
timeoutTask_
;
std
::
mutex
onRecvCbMtx_
;
std
::
function
<
void
(
std
::
string_view
)
>
onRecvCb_
{};
};
...
...
@@ -378,10 +377,8 @@ SubOutgoingFileTransfer::SubOutgoingFileTransfer(DRing::DataTransferId tid,
SubOutgoingFileTransfer
::~
SubOutgoingFileTransfer
()
{
if
(
timeoutThread_
&&
timeoutThread_
->
joinable
())
{
stopTimeout_
=
true
;
timeoutThread_
->
join
();
}
if
(
timeoutTask_
)
timeoutTask_
->
cancel
();
}
void
...
...
@@ -468,20 +465,15 @@ SubOutgoingFileTransfer::emit(DRing::DataTransferEventCode code) const
stateChangedCb_
(
id
,
code
);
metaInfo_
->
updateInfo
(
info_
);
if
(
code
==
DRing
::
DataTransferEventCode
::
wait_peer_acceptance
)
{
timeoutThread_
=
std
::
unique_ptr
<
std
::
thread
>
(
new
std
::
thread
([
this
]()
{
const
auto
TEN_MIN
=
1000
*
60
*
10
;
const
auto
SLEEP_DURATION
=
100
;
for
(
auto
i
=
0
;
i
<
TEN_MIN
/
SLEEP_DURATION
;
++
i
)
{
// 10 min before timeout
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
SLEEP_DURATION
));
if
(
stopTimeout_
.
load
())
return
;
// not waiting anymore
}
JAMI_WARN
()
<<
"FTP#"
<<
this
->
getId
()
<<
": timeout. Cancel"
;
this
->
closeAndEmit
(
DRing
::
DataTransferEventCode
::
timeout_expired
);
}));
}
else
if
(
timeoutThread_
)
{
stopTimeout_
=
true
;
if
(
timeoutTask_
)
timeoutTask_
->
cancel
();
timeoutTask_
=
Manager
::
instance
().
scheduleTask
([
this
]()
{
JAMI_WARN
()
<<
"FTP#"
<<
getId
()
<<
": timeout. Cancel"
;
closeAndEmit
(
DRing
::
DataTransferEventCode
::
timeout_expired
);
},
std
::
chrono
::
steady_clock
::
now
()
+
std
::
chrono
::
minutes
(
10
));
}
else
if
(
timeoutTask_
)
{
timeoutTask_
->
cancel
();
timeoutTask_
.
reset
();
}
}
...
...
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