Skip to content

Commit

Permalink
优化登录状态,注销后进入Ready,允许重新登录,修正StarAgent切换服务器时无法自动重新登录的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jan 2, 2025
1 parent 6aadfb5 commit 4abf891
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
18 changes: 7 additions & 11 deletions NewLife.Remoting/Clients/ClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected override void Dispose(Boolean disposing)

StopTimer();

Status = LoginStatus.LoggedOut;
Status = LoginStatus.Ready;

_timerLogin.TryDispose();
_timerLogin = null;
Expand Down Expand Up @@ -435,18 +435,14 @@ private async Task TryConnectServer(Object state)
/// <returns></returns>
public virtual async Task<ILoginResponse?> Login(CancellationToken cancellationToken = default)
{
if (Status >= LoginStatus.LoggedOut) return null;
//if (Status >= LoginStatus.LoggedOut) return null;

// 如果已登录,直接返回。如果正在登录,则稍等一会,避免重复登录。
if (Status == LoginStatus.LoggedIn) return null;
if (Status == LoginStatus.LoggingIn)
if (Status >= LoginStatus.LoggedIn) return null;
for (var i = 0; Status == LoginStatus.LoggingIn && i < 50; i++)
{
for (var i = 0; i < 50; i++)
{
await TaskEx.Delay(100, cancellationToken).ConfigureAwait(false);
if (Status == LoginStatus.LoggedIn) return null;
if (Status != LoginStatus.LoggingIn) break;
}
await TaskEx.Delay(100, cancellationToken).ConfigureAwait(false);
if (Status == LoginStatus.LoggedIn) return null;
}

if (Status != LoginStatus.LoggedIn) Status = LoginStatus.LoggingIn;
Expand Down Expand Up @@ -593,7 +589,7 @@ protected virtual void FillLoginRequest(ILoginRequest request)

StopTimer();

Status = LoginStatus.LoggedOut;
Status = LoginStatus.Ready;

return rs;
}
Expand Down
4 changes: 2 additions & 2 deletions NewLife.Remoting/Clients/LoginStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public enum LoginStatus
/// <summary>已登录</summary>
LoggedIn = 2,

/// <summary>已注销</summary>
LoggedOut = 3,
///// <summary>已注销</summary>
//LoggedOut = 3,
}

0 comments on commit 4abf891

Please sign in to comment.