Exemple #1
0
        private async ValueTask DatabaseInfoAsync(byte[] items, byte[] buffer, int bufferLength, CancellationToken cancellationToken = default)
        {
            try
            {
                await Xdr.WriteAsync(IscCodes.op_info_database, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(_handle, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(Incarnation, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteBufferAsync(items, items.Length, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(bufferLength, cancellationToken).ConfigureAwait(false);

                await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                var response = (GenericResponse) await ReadResponseAsync(cancellationToken).ConfigureAwait(false);

                var responseLength = bufferLength;

                if (response.Data.Length < bufferLength)
                {
                    responseLength = response.Data.Length;
                }

                Buffer.BlockCopy(response.Data, 0, buffer, 0, responseLength);
            }
            catch (IOException ex)
            {
                throw IscException.ForIOException(ex);
            }
        }
Exemple #2
0
        public virtual async ValueTask <(int auxHandle, string ipAddress, int portNumber, int timeout)> ConnectionRequestAsync(CancellationToken cancellationToken = default)
        {
            try
            {
                await Xdr.WriteAsync(IscCodes.op_connect_request, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(IscCodes.P_REQ_async, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(_handle, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(PartnerIdentification, cancellationToken).ConfigureAwait(false);

                await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                await ReadOperationAsync(cancellationToken).ConfigureAwait(false);

                var auxHandle = await Xdr.ReadInt32Async(cancellationToken).ConfigureAwait(false);

                var garbage1 = new byte[8];
                await Xdr.ReadBytesAsync(garbage1, 8, cancellationToken).ConfigureAwait(false);

                var respLen = await Xdr.ReadInt32Async(cancellationToken).ConfigureAwait(false);

                respLen += respLen % 4;

                var sin_family = new byte[2];
                await Xdr.ReadBytesAsync(sin_family, 2, cancellationToken).ConfigureAwait(false);

                respLen -= 2;

                var sin_port = new byte[2];
                await Xdr.ReadBytesAsync(sin_port, 2, cancellationToken).ConfigureAwait(false);

                var portNumber = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(sin_port, 0));
                respLen -= 2;

                // * The address returned by the server may be incorrect if it is behind a NAT box
                // * so we must use the address that was used to connect the main socket, not the
                // * address reported by the server.
                var sin_addr = new byte[4];
                await Xdr.ReadBytesAsync(sin_addr, 4, cancellationToken).ConfigureAwait(false);

                var ipAddress = _connection.IPAddress.ToString();
                respLen -= 4;

                var garbage2 = new byte[respLen];
                await Xdr.ReadBytesAsync(garbage2, respLen, cancellationToken).ConfigureAwait(false);

                await Xdr.ReadStatusVectorAsync(cancellationToken).ConfigureAwait(false);

                return(auxHandle, ipAddress, portNumber, _connection.Timeout);
            }
            catch (IOException ex)
            {
                throw IscException.ForIOException(ex);
            }
        }
Exemple #3
0
        public override async ValueTask DetachAsync(CancellationToken cancellationToken = default)
        {
            if (TransactionCount > 0)
            {
                throw IscException.ForErrorCodeIntParam(IscCodes.isc_open_trans, TransactionCount);
            }

            try
            {
                await CloseEventManagerAsync(cancellationToken).ConfigureAwait(false);

                var detach = _handle != -1;
                if (detach)
                {
                    await Xdr.WriteAsync(IscCodes.op_detach, cancellationToken).ConfigureAwait(false);

                    await Xdr.WriteAsync(_handle, cancellationToken).ConfigureAwait(false);
                }
                await Xdr.WriteAsync(IscCodes.op_disconnect, cancellationToken).ConfigureAwait(false);

                await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                if (detach)
                {
                    await ReadResponseAsync(cancellationToken).ConfigureAwait(false);
                }

                await CloseConnectionAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (IOException ex)
            {
                try
                {
                    await CloseConnectionAsync(cancellationToken).ConfigureAwait(false);
                }
                catch (IOException)
                { }
                throw IscException.ForIOException(ex);
            }
            finally
            {
                _connection      = null;
                Charset          = null;
                _eventManager    = null;
                ServerVersion    = null;
                Dialect          = 0;
                _handle          = -1;
                PacketSize       = 0;
                WarningMessage   = null;
                TransactionCount = 0;
            }
        }
Exemple #4
0
        protected virtual async ValueTask SendCreateToBufferAsync(DatabaseParameterBufferBase dpb, string database, CancellationToken cancellationToken = default)
        {
            await Xdr.WriteAsync(IscCodes.op_create, cancellationToken).ConfigureAwait(false);

            await Xdr.WriteAsync(DatabaseObjectId, cancellationToken).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(AuthBlock.Password))
            {
                dpb.Append(IscCodes.isc_dpb_password, AuthBlock.Password);
            }
            await Xdr.WriteBufferAsync(Encoding2.Default.GetBytes(database), cancellationToken).ConfigureAwait(false);

            await Xdr.WriteBufferAsync(dpb.ToArray(), cancellationToken).ConfigureAwait(false);
        }
Exemple #5
0
        protected internal async ValueTask <IResponse> ProcessCryptCallbackResponseIfNeededAsync(IResponse response, byte[] cryptKey, CancellationToken cancellationToken = default)
        {
            while (response is CryptKeyCallbackResponse)
            {
                await Xdr.WriteAsync(IscCodes.op_crypt_key_callback, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteBufferAsync(cryptKey, cancellationToken).ConfigureAwait(false);

                await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                response = await ReadResponseAsync(cancellationToken).ConfigureAwait(false);
            }
            return(response);
        }
Exemple #6
0
        protected override async ValueTask SendAttachToBufferAsync(DatabaseParameterBufferBase dpb, string database, CancellationToken cancellationToken = default)
        {
            await Xdr.WriteAsync(IscCodes.op_attach, cancellationToken).ConfigureAwait(false);

            await Xdr.WriteAsync(0, cancellationToken).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(AuthBlock.Password))
            {
                dpb.Append(IscCodes.isc_dpb_password, AuthBlock.Password);
            }
            dpb.Append(IscCodes.isc_dpb_utf8_filename, 0);
            await Xdr.WriteBufferAsync(Encoding.UTF8.GetBytes(database), cancellationToken).ConfigureAwait(false);

            await Xdr.WriteBufferAsync(dpb.ToArray(), cancellationToken).ConfigureAwait(false);
        }
Exemple #7
0
        public override async ValueTask CancelEventsAsync(RemoteEvent events, CancellationToken cancellationToken = default)
        {
            try
            {
                await Xdr.WriteAsync(IscCodes.op_cancel_events, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(_handle, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(events.LocalId, cancellationToken).ConfigureAwait(false);

                await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                await ReadResponseAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (IOException ex)
            {
                throw IscException.ForIOException(ex);
            }
        }
Exemple #8
0
        public override async ValueTask DropDatabaseAsync(CancellationToken cancellationToken = default)
        {
            try
            {
                await Xdr.WriteAsync(IscCodes.op_drop_database, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(_handle, cancellationToken).ConfigureAwait(false);

                await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                await ReadResponseAsync(cancellationToken).ConfigureAwait(false);

                _handle = -1;
            }
            catch (IOException ex)
            {
                throw IscException.ForIOException(ex);
            }
        }
Exemple #9
0
        public override async ValueTask QueueEventsAsync(RemoteEvent remoteEvent, CancellationToken cancellationToken = default)
        {
            try
            {
                if (_eventManager == null)
                {
                    var(auxHandle, ipAddress, portNumber, timeout) = await ConnectionRequestAsync(cancellationToken).ConfigureAwait(false);

                    _eventManager = new GdsEventManager(auxHandle, ipAddress, portNumber, timeout);
                    await _eventManager.OpenAsync(cancellationToken).ConfigureAwait(false);

                    var dummy = _eventManager.StartWaitingForEvents(remoteEvent);
                }

                remoteEvent.LocalId++;

                var epb     = remoteEvent.BuildEpb();
                var epbData = epb.ToArray();

                await Xdr.WriteAsync(IscCodes.op_que_events, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(_handle, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteBufferAsync(epbData, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(AddressOfAstRoutine, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(ArgumentToAstRoutine, cancellationToken).ConfigureAwait(false);

                await Xdr.WriteAsync(remoteEvent.LocalId, cancellationToken).ConfigureAwait(false);

                await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                var response = (GenericResponse) await ReadResponseAsync(cancellationToken).ConfigureAwait(false);

                remoteEvent.RemoteId = response.ObjectHandle;
            }
            catch (IOException ex)
            {
                throw IscException.ForIOException(ex);
            }
        }
Exemple #10
0
        protected override async ValueTask SendCreateToBufferAsync(DatabaseParameterBufferBase dpb, string database, CancellationToken cancellationToken = default)
        {
            await Xdr.WriteAsync(IscCodes.op_create, cancellationToken).ConfigureAwait(false);

            await Xdr.WriteAsync(0, cancellationToken).ConfigureAwait(false);

            if (!AuthBlock.HasClientData)
            {
                dpb.Append(IscCodes.isc_dpb_auth_plugin_name, AuthBlock.AcceptPluginName);
                dpb.Append(IscCodes.isc_dpb_specific_auth_data, AuthBlock.PublicClientData);
            }
            else
            {
                dpb.Append(IscCodes.isc_dpb_specific_auth_data, AuthBlock.ClientData);
            }
            dpb.Append(IscCodes.isc_dpb_utf8_filename, 0);
            await Xdr.WriteBufferAsync(Encoding.UTF8.GetBytes(database), cancellationToken).ConfigureAwait(false);

            await Xdr.WriteBufferAsync(dpb.ToArray(), cancellationToken).ConfigureAwait(false);
        }
Exemple #11
0
        protected async ValueTask SendCancelOperationToBufferAsync(int kind, CancellationToken cancellationToken = default)
        {
            await Xdr.WriteAsync(IscCodes.op_cancel, cancellationToken).ConfigureAwait(false);

            await Xdr.WriteAsync(kind, cancellationToken).ConfigureAwait(false);
        }
Exemple #12
0
        protected virtual async ValueTask SendReleaseObjectToBufferAsync(int op, int id, CancellationToken cancellationToken = default)
        {
            await Xdr.WriteAsync(op, cancellationToken).ConfigureAwait(false);

            await Xdr.WriteAsync(id, cancellationToken).ConfigureAwait(false);
        }