- Separate handling of close and ping/pong messages into their own functions. This helps to keep the main receive function a bit more streamlined, and helping with the more common case we care to optimize for, sending and receiving.
- Remove two locals from the receive async function; this shrinks the size of that async state machine when yielding by a few bytes.
Commit migrated from https://github.com/dotnet/corefx/commit/ef8fd9e532190dff3d6c343e40b8b0fba5684217
- When we fail to connect due to a abort/cancellation, ensure the inner exception of the WebSocketException is an OperationCanceledException rather than an ObjectDisposedException.
- When sending a keep-alive ping, if the send lock is already held, that means we're actively sending something, so there's no value in also sending a keep-alive; we can simply make it a nop.
- Only create the keep-alive timer if asked for.
- Make a field readonly.
- Ensure that we propagate exceptions as inner exceptions whenever possible
Commit migrated from https://github.com/dotnet/corefx/commit/9257f10f0cb457ad161144ddc757cda2450b627f
CoreFX tests will now compile against netstandard1.3 as references and will now deploy for the platforms listed in their respective supports clause, provided the appropriate TestTFM is passed in. The supports are fully listed inside runtime.json in the new TestSuite metapackage in buildtools. The tests will default to netcoreapp1.0 as their TestTFM.
CoreFx test projects now utilise a test csproj to pkgproj reference which determine the appropriate compile time and runtime assets needed.
Dependent on https://github.com/dotnet/buildtools/pull/770
Commit migrated from https://github.com/dotnet/corefx/commit/b4841454de7ddcd75e92e2bb24ebb238a82df43f
- Our closing the socket may trigger our own pending receive to return successfully with 0 bytes read, as if the other end had closed the connection. We need to treat this as an ObjectDisposedException to match the Windows behavior.
- If the Socket ends with an operation canceled code, we should throw an OperationCanceledException to match the Windows behavior.
- When using wss (https), we use an SslStream, and if the underlying stream is disposed of, SslStream may throw an InvalidOperationException due to the connection no longer being authenticated. That needs to be translated into the appropriate exception type to match Windows behavior.
Commit migrated from https://github.com/dotnet/corefx/commit/2e59fabb707f8f3437d69bfdf683d1ae1b38fcd5
Two issues, one preexisting this change and one introduced by it.
- Preexisting: TcpClient on Unix simulates socket.Connect(string host, int port) by creating a new Socket for each possible address we're attempting to connect to. As a result, if the TcpClient is Dispose'd before the connection is successful, we won't yet have stored the actual Socket into the TcpClient and we won't end up Dispose'ing the Socket. Then subsequent attempts to send/receive on that socket will continue, as they will be operating on a valid Socket.
- New: Previously the Socket would end up being Dispose'd of when we Dispose'd of the TcpClient we were holding on to. now that Dispose happens via the NetworkStream. But we weren't passing ownsSocket: true to the NetworkStream, so when it was Dispose'd, it wasn't Dispose'ing of the Socket, resulting in similar hangs when trying to send/receive in abort scenarios.
Commit migrated from https://github.com/dotnet/corefx/commit/270a831355b9a58913652320f8f6e0a610275d8f
It's an internal type, so there's no need for the base class or the virtual methods. Also, since WebSocket is public, we want to avoid folks being able to cast Task.AsyncState to WebSocket and call methods on this internal object directly, just as a precaution against strange misuse.
Commit migrated from https://github.com/dotnet/corefx/commit/0f21c072c80c3eee7ac199fd01b763a670a225e7
The previous commit was beneficial in avoiding one large set of overhead, but it also has a flaw that, due to a current behavior in Sockets, sending to a socket inevitably completes asynchronously, which means SendFrameAsync almost always hits an await that yields. Since this is a very important code path, until the Socket issue can be addressed, we can optimize the common case to minimize the costs involved.
Commit migrated from https://github.com/dotnet/corefx/commit/3e795b025f10cd7c3382b06cbabba82d2094d2f5
We only need to support a single read and a single write at a time, which means we can create two SocketAsyncEventArgs instances and repeatedly reuse them for all read and write operations on the stream. This avoids a significant amount of the overhead involved in reading/writing with the network.
Commit migrated from https://github.com/dotnet/corefx/commit/7a2acc72a6b4ede8a7fa82e83b2a58e00e7e2b82
They currently take around ~40s on my laptop. We can easily reduce this significantly by splitting the single test class into multiple test classes, allowing the default xunit parallelism to run them with more concurrency. On my quad-core, such that xunit by default allows four tests to run concurrently, the tests now take ~10s. This commit moves some of the shared logic into a base class, and then essentially replaces the regions with classes. No test logic was changed at all.
Commit migrated from https://github.com/dotnet/corefx/commit/2a0819b66da873ee41c1ba30d93c3332bd39271b