-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## [2.0.7] - 2021-02-02 Integration: Remove com.unity.nuget.newtonsoft-json dependency in favor of the built-in JsonUtility for the VS Test Runner. ## [2.0.6] - 2021-01-20 Project generation: - Improved language version detection. Integration: - Added support for the VS Test Runner. - Added initial support for displaying asset usage. - Fixed remaining issues with special characters in file/path.
- Loading branch information
Unity Technologies
committed
Feb 2, 2021
1 parent
08ab0fb
commit 8cbbe81
Showing
34 changed files
with
999 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
using System; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Threading; | ||
|
||
namespace Microsoft.Unity.VisualStudio.Editor.Messaging | ||
{ | ||
internal class TcpClient | ||
{ | ||
private const int ConnectOrReadTimeoutMilliseconds = 5000; | ||
|
||
private class State | ||
{ | ||
public System.Net.Sockets.TcpClient TcpClient; | ||
public NetworkStream NetworkStream; | ||
public byte[] Buffer; | ||
public Action<byte[]> OnBufferAvailable; | ||
} | ||
|
||
public static void Queue(IPAddress address, int port, int bufferSize, Action<byte[]> onBufferAvailable) | ||
{ | ||
var client = new System.Net.Sockets.TcpClient(); | ||
var state = new State {OnBufferAvailable = onBufferAvailable, TcpClient = client, Buffer = new byte[bufferSize]}; | ||
|
||
try | ||
{ | ||
ThreadPool.QueueUserWorkItem(_ => | ||
{ | ||
var handle = client.BeginConnect(address, port, OnClientConnected, state); | ||
if (!handle.AsyncWaitHandle.WaitOne(ConnectOrReadTimeoutMilliseconds)) | ||
Cleanup(state); | ||
}); | ||
} | ||
catch (Exception) | ||
{ | ||
Cleanup(state); | ||
} | ||
} | ||
|
||
private static void OnClientConnected(IAsyncResult result) | ||
{ | ||
var state = (State)result.AsyncState; | ||
|
||
try | ||
{ | ||
state.TcpClient.EndConnect(result); | ||
state.NetworkStream = state.TcpClient.GetStream(); | ||
var handle = state.NetworkStream.BeginRead(state.Buffer, 0, state.Buffer.Length, OnEndRead, state); | ||
if (!handle.AsyncWaitHandle.WaitOne(ConnectOrReadTimeoutMilliseconds)) | ||
Cleanup(state); | ||
} | ||
catch (Exception) | ||
{ | ||
Cleanup(state); | ||
} | ||
} | ||
|
||
private static void OnEndRead(IAsyncResult result) | ||
{ | ||
var state = (State)result.AsyncState; | ||
|
||
try | ||
{ | ||
var count = state.NetworkStream.EndRead(result); | ||
if (count == state.Buffer.Length) | ||
state.OnBufferAvailable?.Invoke(state.Buffer); | ||
} | ||
catch (Exception) | ||
{ | ||
// Ignore and cleanup | ||
} | ||
finally | ||
{ | ||
Cleanup(state); | ||
} | ||
} | ||
|
||
private static void Cleanup(State state) | ||
{ | ||
state.NetworkStream?.Dispose(); | ||
state.TcpClient?.Close(); | ||
|
||
state.NetworkStream = null; | ||
state.TcpClient = null; | ||
state.Buffer = null; | ||
state.OnBufferAvailable = null; | ||
} | ||
} | ||
} |
Oops, something went wrong.