示例#1
0
        private void SocketRead(int length, ref byte[] buffer)
        {
            var state = new SocketReadState(_socket, length, ref buffer);

            _socket.BeginReceive(buffer, 0, length, SocketFlags.None, SocketReceiveCallback, state);

            var readResult = state.Wait();

            switch (readResult)
            {
            case SocketReadResult.Complete:
                break;

            case SocketReadResult.ConnectionLost:
                if (_isDisconnecting)
                {
                    throw new SshConnectionException(
                              "An established connection was aborted by the software in your host machine.",
                              DisconnectReason.ConnectionLost);
                }
                throw new SshConnectionException("An established connection was aborted by the server.",
                                                 DisconnectReason.ConnectionLost);

            case SocketReadResult.Failed:
                var socketException = state.Exception as SocketException;
                if (socketException != null)
                {
                    if (socketException.SocketErrorCode == SocketError.ConnectionAborted)
                    {
                        buffer = new byte[length];
                        Disconnect();
                        return;
                    }
                }
                throw state.Exception;
            }
        }
示例#2
0
        private void SocketRead(int length, ref byte[] buffer)
        {
            var state = new SocketReadState(_socket, length, ref buffer);

            _socket.BeginReceive(buffer, 0, length, SocketFlags.None, SocketReceiveCallback, state);

            var readResult = state.Wait();
            switch (readResult)
            {
                case SocketReadResult.Complete:
                    break;
                case SocketReadResult.ConnectionLost:
                    if (_isDisconnecting)
                        throw new SshConnectionException(
                            "An established connection was aborted by the software in your host machine.",
                            DisconnectReason.ConnectionLost);
                    throw new SshConnectionException("An established connection was aborted by the server.",
                        DisconnectReason.ConnectionLost);
                case SocketReadResult.Failed:
                    var socketException = state.Exception as SocketException;
                    if (socketException != null)
                    {
                        if (socketException.SocketErrorCode == SocketError.ConnectionAborted)
                        {
                            buffer = new byte[length];
                            Disconnect();
                            return;
                        }
                    }
                    throw state.Exception;
            }
        }