Skip to content

Commit f6a317f

Browse files
committed
Refactoring.
1 parent c0c5037 commit f6a317f

File tree

4 files changed

+12
-29
lines changed

4 files changed

+12
-29
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/GdsConnection.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void Connect()
132132

133133
public void Identify(string database)
134134
{
135-
using (var xdrStream = CreateXdrStream(false))
135+
using (var xdrStream = CreateXdrStreamImpl(false))
136136
{
137137
try
138138
{
@@ -235,7 +235,7 @@ public void Identify(string database)
235235

236236
public XdrStream CreateXdrStream()
237237
{
238-
return CreateXdrStream(_compression);
238+
return CreateXdrStreamImpl(_compression);
239239
}
240240

241241
public void Disconnect()
@@ -252,9 +252,7 @@ public void Disconnect()
252252

253253
private IPAddress GetIPAddress(string dataSource, AddressFamily addressFamily)
254254
{
255-
IPAddress ipaddress = null;
256-
257-
if (IPAddress.TryParse(dataSource, out ipaddress))
255+
if (IPAddress.TryParse(dataSource, out var ipaddress))
258256
{
259257
return ipaddress;
260258
}
@@ -339,7 +337,7 @@ private byte[] UserIdentificationData()
339337
}
340338
}
341339

342-
private XdrStream CreateXdrStream(bool compression)
340+
private XdrStream CreateXdrStreamImpl(bool compression)
343341
{
344342
return new XdrStream(_networkStream, _characterSet, compression, false);
345343
}

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version10/GdsStatement.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ protected override void Free(int option)
477477
return;
478478

479479
DoFreePacket(option);
480-
_database.XdrStream.Flush();
481480
ProcessFreeResponse(_database.ReadResponse());
482481
}
483482

@@ -499,7 +498,10 @@ protected void DoFreePacket(int option)
499498
{
500499
try
501500
{
502-
SendFreeToBuffer(option);
501+
_database.XdrStream.Write(IscCodes.op_free_statement);
502+
_database.XdrStream.Write(_handle);
503+
_database.XdrStream.Write(option);
504+
_database.XdrStream.Flush();
503505

504506
if (option == IscCodes.DSQL_drop)
505507
{
@@ -516,13 +518,6 @@ protected void DoFreePacket(int option)
516518
}
517519
}
518520

519-
protected void SendFreeToBuffer(int option)
520-
{
521-
_database.XdrStream.Write(IscCodes.op_free_statement);
522-
_database.XdrStream.Write(_handle);
523-
_database.XdrStream.Write(option);
524-
}
525-
526521
protected void ProcessFreeResponse(IResponse response)
527522
{
528523

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version11/GdsStatement.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ protected override void Free(int option)
193193
return;
194194

195195
DoFreePacket(option);
196-
_database.XdrStream.Flush();
197196
(Database as GdsDatabase).DeferredPackets.Enqueue(ProcessFreeResponse);
198197
}
199198
#endregion

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/XdrStream.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ internal class XdrStream : Stream
3434
#region Constants
3535

3636
private const int PreferredBufferSize = 32 * 1024;
37+
private const int InvalidOperation = -1;
3738

3839
#endregion
3940

@@ -308,8 +309,7 @@ public byte[] ToArray()
308309
{
309310
CheckDisposed();
310311

311-
var memoryStream = _innerStream as MemoryStream;
312-
if (memoryStream == null)
312+
if(!(_innerStream is MemoryStream memoryStream))
313313
throw new InvalidOperationException();
314314
Flush();
315315
return memoryStream.ToArray();
@@ -321,7 +321,7 @@ public byte[] ToArray()
321321

322322
public int ReadOperation()
323323
{
324-
var op = ValidOperationAvailable ? _operation : ReadNextOperation();
324+
var op = _operation != InvalidOperation ? _operation : ReadNextOperation();
325325
ResetOperation();
326326
return op;
327327
}
@@ -358,7 +358,7 @@ public void SetOperation(int operation)
358358

359359
private void ResetOperation()
360360
{
361-
_operation = -1;
361+
_operation = InvalidOperation;
362362
}
363363

364364
#endregion
@@ -741,14 +741,5 @@ private void EnsureReadable()
741741
}
742742

743743
#endregion
744-
745-
#region Private Properties
746-
747-
private bool ValidOperationAvailable
748-
{
749-
get { return _operation >= 0; }
750-
}
751-
752-
#endregion
753744
}
754745
}

0 commit comments

Comments
 (0)