public override async ValueTask AttachAsync(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey, CancellationToken cancellationToken = default) { try { await SendAttachToBufferAsync(dpb, database, cancellationToken).ConfigureAwait(false); await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false); var response = await ReadResponseAsync(cancellationToken).ConfigureAwait(false); if (response is ContAuthResponse) { while (response is ContAuthResponse contAuthResponse) { AuthBlock.Start(contAuthResponse.ServerData, contAuthResponse.AcceptPluginName, contAuthResponse.IsAuthenticated, contAuthResponse.ServerKeys); await AuthBlock.SendContAuthToBufferAsync(Xdr, cancellationToken).ConfigureAwait(false); await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false); response = await AuthBlock.ProcessContAuthResponseAsync(Xdr, cancellationToken).ConfigureAwait(false); response = await ProcessCryptCallbackResponseIfNeededAsync(response, cryptKey, cancellationToken).ConfigureAwait(false); } var genericResponse = (GenericResponse)response; await ProcessAttachResponseAsync(genericResponse, cancellationToken).ConfigureAwait(false); if (genericResponse.Data.Any()) { await AuthBlock.SendWireCryptToBufferAsync(Xdr, cancellationToken).ConfigureAwait(false); await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false); await AuthBlock.ProcessWireCryptResponseAsync(Xdr, _connection, cancellationToken).ConfigureAwait(false); } } else { response = await ProcessCryptCallbackResponseIfNeededAsync(response, cryptKey, cancellationToken).ConfigureAwait(false); await ProcessAttachResponseAsync((GenericResponse)response, cancellationToken).ConfigureAwait(false); AuthBlock.Complete(); } AuthBlock.WireCryptValidate(IscCodes.PROTOCOL_VERSION13); } catch (IscException) { await SafelyDetachAsync(cancellationToken).ConfigureAwait(false); throw; } catch (IOException ex) { await SafelyDetachAsync(cancellationToken).ConfigureAwait(false); throw IscException.ForIOException(ex); } await AfterAttachActionsAsync(cancellationToken).ConfigureAwait(false); }
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); } }
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); } }
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; } }
public virtual async ValueTask ReleaseObjectAsync(int op, int id, CancellationToken cancellationToken = default) { try { await SendReleaseObjectToBufferAsync(op, id, cancellationToken).ConfigureAwait(false); await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false); await ProcessReleaseObjectResponseAsync(await ReadResponseAsync(cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); } catch (IOException ex) { throw IscException.ForIOException(ex); } }
public override async ValueTask CreateDatabaseAsync(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey, CancellationToken cancellationToken = default) { try { await SendCreateToBufferAsync(dpb, database, cancellationToken).ConfigureAwait(false); await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false); await ProcessCreateResponseAsync((GenericResponse)await ReadResponseAsync(cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); } catch (IOException ex) { throw IscException.ForIOException(ex); } }
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); }
public override async ValueTask CancelOperationAsync(int kind, CancellationToken cancellationToken = default) { try { await SendCancelOperationToBufferAsync(kind, cancellationToken).ConfigureAwait(false); await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false); // no response, this is out-of-band } catch (IOException ex) { throw IscException.ForIOException(ex); } }
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); } }
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); } }
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); } }
public override async ValueTask AttachAsync(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey, CancellationToken cancellationToken = default) { try { await SendAttachToBufferAsync(dpb, database, cancellationToken).ConfigureAwait(false); await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false); await ProcessAttachResponseAsync((GenericResponse)await ReadResponseAsync(cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); } catch (IscException) { await SafelyDetachAsync(cancellationToken).ConfigureAwait(false); throw; } catch (IOException ex) { await SafelyDetachAsync(cancellationToken).ConfigureAwait(false); throw IscException.ForIOException(ex); } await AfterAttachActionsAsync(cancellationToken).ConfigureAwait(false); }