Skip to content

Commit 92787d1

Browse files
committed
Remove workaround local methods.
C# 13 now allows lock and ref struct within the body of async methods. https://devblogs.microsoft.com/dotnet/csharp-13-explore-preview-features/#ref-and-unsafe-in-async-methods-and-iterators
1 parent 4329de3 commit 92787d1

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,15 +1646,12 @@ private async Task GetRealServerDetailsAsync(IOBehavior ioBehavior, Cancellation
16461646

16471647
// first (and only) row
16481648
payload = await ReceiveReplyAsync(ioBehavior, CancellationToken.None).ConfigureAwait(false);
1649-
static void ReadRow(ReadOnlySpan<byte> span, out int? connectionId, out ServerVersion? serverVersion)
1650-
{
1651-
var reader = new ByteArrayReader(span);
1652-
var length = reader.ReadLengthEncodedIntegerOrNull();
1653-
connectionId = (length != -1 && Utf8Parser.TryParse(reader.ReadByteString(length), out int id, out _)) ? id : default(int?);
1654-
length = reader.ReadLengthEncodedIntegerOrNull();
1655-
serverVersion = length != -1 ? new ServerVersion(reader.ReadByteString(length)) : default;
1656-
}
1657-
ReadRow(payload.Span, out var connectionId, out var serverVersion);
1649+
1650+
var reader = new ByteArrayReader(payload.Span);
1651+
var length = reader.ReadLengthEncodedIntegerOrNull();
1652+
var connectionId = (length != -1 && Utf8Parser.TryParse(reader.ReadByteString(length), out int id, out _)) ? id : default(int?);
1653+
length = reader.ReadLengthEncodedIntegerOrNull();
1654+
var serverVersion = length != -1 ? new ServerVersion(reader.ReadByteString(length)) : default;
16581655

16591656
// OK/EOF payload
16601657
payload = await ReceiveReplyAsync(ioBehavior, CancellationToken.None).ConfigureAwait(false);

src/MySqlConnector/MySqlConnection.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,20 +1189,16 @@ private async Task DoCloseAsync(bool changeState, IOBehavior ioBehavior)
11891189
};
11901190
connection.TakeSessionFrom(this);
11911191

1192-
ReplaceConnection(this, connection);
1193-
static void ReplaceConnection(MySqlConnection thisConnection, MySqlConnection connection)
1192+
// put the new, idle, connection into the list of sessions for this transaction (replacing this MySqlConnection)
1193+
lock (s_lock)
11941194
{
1195-
// put the new, idle, connection into the list of sessions for this transaction (replacing this MySqlConnection)
1196-
lock (s_lock)
1195+
foreach (var enlistedTransaction in s_transactionConnections[connection.m_enlistedTransaction!.Transaction])
11971196
{
1198-
foreach (var enlistedTransaction in s_transactionConnections[connection.m_enlistedTransaction!.Transaction])
1197+
if (enlistedTransaction.Connection == this)
11991198
{
1200-
if (enlistedTransaction.Connection == thisConnection)
1201-
{
1202-
enlistedTransaction.Connection = connection;
1203-
enlistedTransaction.IsIdle = true;
1204-
break;
1205-
}
1199+
enlistedTransaction.Connection = connection;
1200+
enlistedTransaction.IsIdle = true;
1201+
break;
12061202
}
12071203
}
12081204
}

0 commit comments

Comments
 (0)