Remove ConfigureAwait until thread safe

This commit is contained in:
Frank A. Krueger 2017-06-15 17:16:52 -07:00
parent e191d66a75
commit 08a815f3ee
1 changed files with 6 additions and 6 deletions

View File

@ -118,7 +118,7 @@ namespace Ooui
Console.ResetColor (); Console.ResetColor ();
while (!token.IsCancellationRequested) { while (!token.IsCancellationRequested) {
var listenerContext = await listener.GetContextAsync ().ConfigureAwait (false); var listenerContext = await listener.GetContextAsync ();
if (listenerContext.Request.IsWebSocketRequest) { if (listenerContext.Request.IsWebSocketRequest) {
ProcessWebSocketRequest (listenerContext, token); ProcessWebSocketRequest (listenerContext, token);
} }
@ -207,7 +207,7 @@ namespace Ooui
WebSocketContext webSocketContext = null; WebSocketContext webSocketContext = null;
WebSocket webSocket = null; WebSocket webSocket = null;
try { try {
webSocketContext = await listenerContext.AcceptWebSocketAsync (subProtocol: "ooui").ConfigureAwait (false); webSocketContext = await listenerContext.AcceptWebSocketAsync (subProtocol: "ooui");
webSocket = webSocketContext.WebSocket; webSocket = webSocketContext.WebSocket;
Console.WriteLine ("WEBSOCKET {0}", listenerContext.Request.Url.LocalPath); Console.WriteLine ("WEBSOCKET {0}", listenerContext.Request.Url.LocalPath);
} }
@ -268,19 +268,19 @@ namespace Ooui
var receiveResult = await webSocket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), token); var receiveResult = await webSocket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), token);
if (receiveResult.MessageType == WebSocketMessageType.Close) { if (receiveResult.MessageType == WebSocketMessageType.Close) {
await webSocket.CloseAsync (WebSocketCloseStatus.NormalClosure, "", token).ConfigureAwait (false); await webSocket.CloseAsync (WebSocketCloseStatus.NormalClosure, "", token);
} }
else if (receiveResult.MessageType == WebSocketMessageType.Binary) { else if (receiveResult.MessageType == WebSocketMessageType.Binary) {
await webSocket.CloseAsync (WebSocketCloseStatus.InvalidMessageType, "Cannot accept binary frame", token).ConfigureAwait (false); await webSocket.CloseAsync (WebSocketCloseStatus.InvalidMessageType, "Cannot accept binary frame", token);
} }
else { else {
var size = receiveResult.Count; var size = receiveResult.Count;
while (!receiveResult.EndOfMessage) { while (!receiveResult.EndOfMessage) {
if (size >= receiveBuffer.Length) { if (size >= receiveBuffer.Length) {
await webSocket.CloseAsync (WebSocketCloseStatus.MessageTooBig, "Message too big", token).ConfigureAwait (false); await webSocket.CloseAsync (WebSocketCloseStatus.MessageTooBig, "Message too big", token);
return; return;
} }
receiveResult = await webSocket.ReceiveAsync (new ArraySegment<byte>(receiveBuffer, size, receiveBuffer.Length - size), token).ConfigureAwait (false); receiveResult = await webSocket.ReceiveAsync (new ArraySegment<byte>(receiveBuffer, size, receiveBuffer.Length - size), token);
size += receiveResult.Count; size += receiveResult.Count;
} }
var receivedString = Encoding.UTF8.GetString (receiveBuffer, 0, size); var receivedString = Encoding.UTF8.GetString (receiveBuffer, 0, size);