Skip to content

Commit

Permalink
Fixes CBL-326 by adding SocketError.NetworkDown case (#1181)
Browse files Browse the repository at this point in the history
CBL-326 
* Add SocketError.NetworkDown case to resume replication when manually turn off/on the android phone.
* Create new WaitPendingConflictTasks to separate the chain logic in if statement.
  • Loading branch information
Sandychuang8 committed Sep 17, 2019
1 parent e7645e7 commit 4f95465
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/Couchbase.Lite.Shared/API/Sync/Replicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,31 @@ private static TimeSpan RetryDelay(int retryCount)
private static void StatusChangedCallback(C4Replicator* repl, C4ReplicatorStatus status, void* context)
{
var replicator = GCHandle.FromIntPtr((IntPtr)context).Target as Replicator;
if (replicator == null)
return;

replicator.WaitPendingConflictTasks(status);
replicator.DispatchQueue.DispatchSync(() =>
{
replicator.StatusChangedCallback(status);
});
}

private void WaitPendingConflictTasks(C4ReplicatorStatus status)
{
if (status.error.code == 0 && status.error.domain == 0)
return;

bool transient;
if ((replicator != null && replicator.IsPermanentError(status.error, out transient))
&& status.level == C4ReplicatorActivityLevel.Stopped) {
var array = replicator?._conflictTasks?.Keys?.ToArray();
if (!IsPermanentError(status.error, out transient))
return;

if (status.level == C4ReplicatorActivityLevel.Stopped) {
var array = _conflictTasks?.Keys?.ToArray();
if (array != null) {
Task.WaitAll(array);
}
}

replicator?.DispatchQueue.DispatchSync(() =>
{
replicator.StatusChangedCallback(status);
});
}

private void ClearRepl()
Expand Down
5 changes: 5 additions & 0 deletions src/Couchbase.Lite.Shared/Support/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public static unsafe void ConvertNetworkError(Exception e, C4Error* outError)
c4err.domain = C4ErrorDomain.POSIXDomain;
c4err.code = PosixBase.GetCode(nameof(PosixWindows.ECONNREFUSED));
break;
case SocketError.NetworkDown:
message = se.Message;
c4err.domain = C4ErrorDomain.POSIXDomain;
c4err.code = PosixBase.GetCode(nameof(PosixWindows.ENETDOWN));
break;
}

break;
Expand Down

0 comments on commit 4f95465

Please sign in to comment.