Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
la-we committed Oct 28, 2024
1 parent e3d47c9 commit 12fa2e6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
using System.Threading.Tasks;
using FirebirdSql.Data.Common;

#if !(NET48 || NETSTANDARD2_0)
using System.Buffers;
#endif

namespace FirebirdSql.Data.Client.Managed.Version10;

internal sealed class GdsBlob : BlobBase
Expand Down Expand Up @@ -134,7 +130,7 @@ public override int GetLength()
_database.Xdr.Write(IscCodes.op_info_blob);
_database.Xdr.Write(_blobHandle);
_database.Xdr.Write(0);
_database.Xdr.WriteBuffer(new byte[]{ IscCodes.isc_info_blob_total_length }, 1);
_database.Xdr.WriteBuffer(new byte[] { IscCodes.isc_info_blob_total_length }, 1);
_database.Xdr.Write(bufferLength);

_database.Xdr.Flush();
Expand Down Expand Up @@ -174,7 +170,7 @@ public override async ValueTask<int> GetLengthAsync(CancellationToken cancellati
await _database.Xdr.WriteAsync(IscCodes.op_info_blob, cancellationToken).ConfigureAwait(false);
await _database.Xdr.WriteAsync(_blobHandle, cancellationToken).ConfigureAwait(false);
await _database.Xdr.WriteAsync(0, cancellationToken).ConfigureAwait(false);
await _database.Xdr.WriteBufferAsync(new byte[]{ IscCodes.isc_info_blob_total_length }, 1, cancellationToken).ConfigureAwait(false);
await _database.Xdr.WriteBufferAsync(new byte[] { IscCodes.isc_info_blob_total_length }, 1, cancellationToken).ConfigureAwait(false);
await _database.Xdr.WriteAsync(bufferLength, cancellationToken).ConfigureAwait(false);

await _database.Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -278,7 +274,7 @@ public override async ValueTask GetSegmentAsync(Stream stream, CancellationToken

if (buffer.Length == 0)
{
// previous segment was last, this has no data
//previous segment was last, this has no data
return;
}

Expand Down Expand Up @@ -328,7 +324,7 @@ public override byte[] GetSegment()

if (buffer.Length == 0)
{
// previous segment was last, this has no data
//previous segment was last, this has no data
return Array.Empty<byte>();
}

Expand Down Expand Up @@ -446,13 +442,13 @@ public override async ValueTask PutSegmentAsync(byte[] buffer, CancellationToken
}
}

public override void Seek(int offset, int fbSeekMode)
public override void Seek(int offset, int seekMode)
{
try
{
_database.Xdr.Write(IscCodes.op_seek_blob);
_database.Xdr.Write(_blobHandle);
_database.Xdr.Write(fbSeekMode);
_database.Xdr.Write(seekMode);
_database.Xdr.Write(offset);
_database.Xdr.Flush();

Expand All @@ -465,13 +461,13 @@ public override void Seek(int offset, int fbSeekMode)
throw IscException.ForIOException(ex);
}
}
public override async ValueTask SeekAsync(int offset, int fbSeekMode, CancellationToken cancellationToken = default)
public override async ValueTask SeekAsync(int offset, int seekMode, CancellationToken cancellationToken = default)
{
try
{
await _database.Xdr.WriteAsync(IscCodes.op_seek_blob, cancellationToken).ConfigureAwait(false);
await _database.Xdr.WriteAsync(_blobHandle, cancellationToken).ConfigureAwait(false);
await _database.Xdr.WriteAsync(fbSeekMode, cancellationToken).ConfigureAwait(false);
await _database.Xdr.WriteAsync(seekMode, cancellationToken).ConfigureAwait(false);
await _database.Xdr.WriteAsync(offset, cancellationToken).ConfigureAwait(false);
await _database.Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

Expand Down
4 changes: 2 additions & 2 deletions src/FirebirdSql.Data.FirebirdClient/Client/Native/FesBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public override int GetLength()
_statusVector,
ref _blobHandle,
1,
new byte[]{IscCodes.isc_info_blob_total_length},
new byte[] { IscCodes.isc_info_blob_total_length },
(short)buffer.Length,
buffer);

Expand All @@ -192,7 +192,7 @@ public override ValueTask<int> GetLengthAsync(CancellationToken cancellationToke
_statusVector,
ref _blobHandle,
1,
new byte[]{IscCodes.isc_info_blob_total_length},
new byte[] { IscCodes.isc_info_blob_total_length },
(short)buffer.Length,
buffer);

Expand Down
12 changes: 3 additions & 9 deletions src/FirebirdSql.Data.FirebirdClient/Common/BlobBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public string ReadString()
var buffer = Read();
return _charset.GetString(buffer, 0, buffer.Length);
}

public async ValueTask<string> ReadStringAsync(CancellationToken cancellationToken = default)
{
var buffer = await ReadAsync(cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -87,7 +86,6 @@ public byte[] Read()
return ms.ToArray();
}
}

public async ValueTask<byte[]> ReadAsync(CancellationToken cancellationToken = default)
{
using (var ms = new MemoryStream())
Expand Down Expand Up @@ -119,7 +117,6 @@ public void Write(string data)
{
Write(_charset.GetBytes(data));
}

public ValueTask WriteAsync(string data, CancellationToken cancellationToken = default)
{
return WriteAsync(_charset.GetBytes(data), cancellationToken);
Expand All @@ -129,7 +126,6 @@ public void Write(byte[] buffer)
{
Write(buffer, 0, buffer.Length);
}

public ValueTask WriteAsync(byte[] buffer, CancellationToken cancellationToken = default)
{
return WriteAsync(buffer, 0, buffer.Length, cancellationToken);
Expand Down Expand Up @@ -172,9 +168,7 @@ public void Write(byte[] buffer, int index, int count)
throw;
}
}

public async ValueTask WriteAsync(byte[] buffer, int index, int count,
CancellationToken cancellationToken = default)
public async ValueTask WriteAsync(byte[] buffer, int index, int count, CancellationToken cancellationToken = default)
{
try
{
Expand Down Expand Up @@ -230,8 +224,8 @@ public async ValueTask WriteAsync(byte[] buffer, int index, int count,
public abstract void PutSegment(byte[] buffer);
public abstract ValueTask PutSegmentAsync(byte[] buffer, CancellationToken cancellationToken = default);

public abstract void Seek(int offset, int fbSeekMode);
public abstract ValueTask SeekAsync(int offset, int fbSeekMode, CancellationToken cancellationToken = default);
public abstract void Seek(int offset, int seekMode);
public abstract ValueTask SeekAsync(int offset, int seekMode, CancellationToken cancellationToken = default);

public abstract void Close();
public abstract ValueTask CloseAsync(CancellationToken cancellationToken = default);
Expand Down
11 changes: 3 additions & 8 deletions src/FirebirdSql.Data.FirebirdClient/Common/BlobStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public override int Read(byte[] buffer, int offset, int count)

return copied;
}

public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -113,15 +112,15 @@ public override long Seek(long offset, SeekOrigin origin)
if (!_blobHandle.IsOpen)
_blobHandle.Open();

var fbSeekMode = origin switch
var seekMode = origin switch
{
SeekOrigin.Begin => IscCodes.isc_blb_seek_from_head,
SeekOrigin.Current => IscCodes.isc_blb_seek_relative,
SeekOrigin.End => IscCodes.isc_blb_seek_from_tail,
_ => throw new ArgumentOutOfRangeException(nameof(origin))
};

_blobHandle.Seek((int)offset, fbSeekMode);
_blobHandle.Seek((int)offset, seekMode);
return _position = _blobHandle.Position;
}

Expand Down Expand Up @@ -158,15 +157,12 @@ public override void Write(byte[] buffer, int offset, int count)
}
catch
{
// Cancel the blob and rethrow the exception
_blobHandle.Cancel();

throw;
}
}

public override async Task WriteAsync(byte[] buffer, int offset, int count,
CancellationToken cancellationToken)
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
try
{
Expand Down Expand Up @@ -194,7 +190,6 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count,
}
catch
{
// Cancel the blob and rethrow the exception
await _blobHandle.CancelAsync(cancellationToken).ConfigureAwait(false);

throw;
Expand Down

0 comments on commit 12fa2e6

Please sign in to comment.