Example #1
0
        /// <summary>
        /// Производит предварительное подключение к серверу. Может использоваться для повторного переподключения.
        /// </summary>
        /// <remarks>Потокобезопасно.</remarks>
        /// <exception cref="VRpcConnectException"/>
        /// <exception cref="VRpcShutdownException"/>
        /// <exception cref="ObjectDisposedException"/>
        public async Task ConnectAsync()
        {
            ConnectResult connectResult = await ConnectExAsync().ConfigureAwait(false);

            switch (connectResult.State)
            {
            case ConnectionState.Connected:
                return;

            case ConnectionState.SocketError:
            {
                Debug.Assert(connectResult.SocketError != null);

                ThrowConnectException($"Unable to connect to the remote server. Error: {(int)connectResult.SocketError}",
                                      innerException: connectResult.SocketError.Value.ToException());

                break;
            }

            case ConnectionState.ShutdownRequest:
            {
                Debug.Assert(connectResult.ShutdownRequest != null);
                ThrowHelper.ThrowException(connectResult.ShutdownRequest.ToException());
                break;
            }
            }
        }
Example #2
0
 /// <summary>
 /// Не бросает исключения.
 /// </summary>
 internal static ConnectResult ToPublicConnectResult(this in InnerConnectionResult conRes)
 {
     if (conRes.Connection != null)
     {
         return(ConnectResult.FromConnectionSuccess());
     }
     else if (conRes.SocketError != null)
     {
         return(ConnectResult.FromError(conRes.SocketError.Value));
     }
     else
     {
         Debug.Assert(conRes.ShutdownRequest != null);
         return(ConnectResult.FromShutdownRequest(conRes.ShutdownRequest));
     }
 }