Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net6 #712

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Net6 #712

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ obj
*.user
*.userprefs
UpgradeLog*.*

.DS_Store
/websocket-sharp/.vs/websocket-sharp.NET6/FileContentIndex
/.vs

25 changes: 25 additions & 0 deletions websocket-sharp.NET.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "websocket-sharp.NET", "websocket-sharp\websocket-sharp.NET.csproj", "{DAAA6D7A-454B-453C-836E-5AB5892189A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DAAA6D7A-454B-453C-836E-5AB5892189A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAAA6D7A-454B-453C-836E-5AB5892189A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAAA6D7A-454B-453C-836E-5AB5892189A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAAA6D7A-454B-453C-836E-5AB5892189A0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {386D1E9F-5E7F-45C6-8CFD-CE2A50B9EF3A}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion websocket-sharp/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.2.*")]
[assembly: AssemblyVersion("1.0.3.3")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
67 changes: 67 additions & 0 deletions websocket-sharp/Ext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,72 @@ internal static byte[] ReadBytes (
}
}

#if NET
internal static void ReadBytesAsync(this Stream stream, int length, Action<byte[]> completed, Action<Exception> error)
{

byte[] buff = new byte[length];

stream.ReadAsync(buff, 0, length).ContinueWith((x) =>
{
if (x.Exception?.InnerException != null)
{
if (x.Exception.InnerException is ObjectDisposedException || x.Exception.InnerException is NotSupportedException)
{
completed(new byte[0]);
}
else
{
error(x.Exception.InnerException);
}
}
else
{
completed(buff);
}
}, TaskContinuationOptions.NotOnCanceled);

}

internal static void ReadBytesAsync(this Stream stream, long length, int bufferLength, Action<byte[]> completed, Action<Exception> error)
{
DoReadAsync(stream, length, bufferLength, completed, error).ContinueWith(x => System.Diagnostics.Debug.WriteLine(x.Result));
}

private static async Task<long> DoReadAsync(Stream stream, long length, int bufferLength, Action<byte[]> complected, Action<Exception> error)
{
var dest = new MemoryStream();
var buff = new byte[bufferLength];
long nRead = 0;
try
{
while (nRead < length)
{
var actualLength = await stream.ReadAsync(buff, 0, bufferLength);
if (actualLength == 0)
break;
nRead += actualLength;
dest.Write(buff, 0, actualLength);
}
complected(dest.ToArray());
}
catch (Exception ex)
{
if (ex is ObjectDisposedException || ex is NotSupportedException)
{
complected(new byte[0]);
}
else
{
error(ex);
}

}
return nRead;
}

#else

internal static void ReadBytesAsync (
this Stream stream,
int length,
Expand Down Expand Up @@ -872,6 +938,7 @@ Action<Exception> error
error (ex);
}
}
#endif

internal static T[] Reverse<T> (this T[] array)
{
Expand Down
20 changes: 17 additions & 3 deletions websocket-sharp/Net/HttpStreamAsyncResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ internal void Complete ()
_waitHandle.Set ();

if (_callback != null)
_callback.BeginInvoke (this, ar => _callback.EndInvoke (ar), null);
{
#if NET
var workTask = Task.Run(() => _callback.Invoke(this));
#else
_callback.BeginInvoke(this, ar => _callback.EndInvoke(ar), null);
#endif
}

}
}

Expand All @@ -192,10 +199,17 @@ internal void Complete (Exception exception)
_waitHandle.Set ();

if (_callback != null)
_callback.BeginInvoke (this, ar => _callback.EndInvoke (ar), null);
{
#if NET
var workTask = Task.Run(() => _callback.Invoke(this));
#else
_callback.BeginInvoke(this, ar => _callback.EndInvoke(ar), null);
#endif
}

}
}

#endregion
#endregion
}
}
Loading