Skip to content

Commit

Permalink
[dotnet] Send data over cdp consecutively (#12666)
Browse files Browse the repository at this point in the history
Send data over cdp consecutively
  • Loading branch information
nvborisenko committed Sep 1, 2023
1 parent d670a70 commit 174e394
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dotnet/src/webdriver/DevTools/WebSocketConnection.cs
Expand Up @@ -37,6 +37,7 @@ public class WebSocketConnection
private Task dataReceiveTask;
private bool isActive = false;
private ClientWebSocket client = new ClientWebSocket();
private readonly SemaphoreSlim sendMethodSemaphore = new SemaphoreSlim(1, 1);

/// <summary>
/// Initializes a new instance of the <see cref="WebSocketConnection" /> class.
Expand Down Expand Up @@ -159,7 +160,17 @@ public virtual async Task SendData(string data)
{
ArraySegment<byte> messageBuffer = new ArraySegment<byte>(Encoding.UTF8.GetBytes(data));
this.Log($"SEND >>> {data}");
await this.client.SendAsync(messageBuffer, WebSocketMessageType.Text, endOfMessage: true, CancellationToken.None);

await sendMethodSemaphore.WaitAsync().ConfigureAwait(false);

try
{
await this.client.SendAsync(messageBuffer, WebSocketMessageType.Text, endOfMessage: true, CancellationToken.None);
}
finally
{
sendMethodSemaphore.Release();
}
}

/// <summary>
Expand Down

0 comments on commit 174e394

Please sign in to comment.