Skip to content

Commit

Permalink
#83: partially port JabberNet to .NET Standard
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Mar 16, 2017
1 parent 91217d9 commit 1ceb4f9
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 1,350 deletions.
4 changes: 2 additions & 2 deletions JabberNet.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.26228.9
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{BFD2D70D-3C18-4BFD-B70E-38ED872B8F67}"
ProjectSection(SolutionItems) = preProject
Expand Down
9 changes: 0 additions & 9 deletions src/JabberNet/AssemblyInfo.cs

This file was deleted.

460 changes: 89 additions & 371 deletions src/JabberNet/JabberNet.csproj

Large diffs are not rendered by default.

145 changes: 0 additions & 145 deletions src/JabberNet/bedrock/collections/IndexedTrie.cs

This file was deleted.

14 changes: 7 additions & 7 deletions src/JabberNet/bedrock/collections/StringSet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* --------------------------------------------------------------------------
/* --------------------------------------------------------------------------
* Copyrights
*
* Portions created by or assigned to Cursive Systems, Inc. are
Expand All @@ -22,12 +22,11 @@ namespace JabberNet.bedrock.collections
/// A set of strings, backed into a BitArray. Any given string that is inserted
/// into any instance of a StringSet increases the size of all StringSets over time.
/// </summary>
public class StringSet : IEnumerable, IEnumerable<string>, ICloneable
public class StringSet : IEnumerable, IEnumerable<string>
{
private BitArray m_bits = null;

// List<T>.Add doesn't return an int.
private static ArrayList s_strings = new ArrayList();
private static List<string> s_strings = new List<string>();
private static Dictionary<string, int> s_bits = new Dictionary<string,int>();

/// <summary>
Expand All @@ -45,7 +44,7 @@ public StringSet()
public StringSet(StringSet other)
{
if (other != null)
m_bits = (BitArray)other.m_bits.Clone();
m_bits = new BitArray(other.m_bits);
}

/// <summary>
Expand Down Expand Up @@ -76,7 +75,8 @@ private static int GetStringValue(string s)
{
if (!s_bits.TryGetValue(s, out val))
{
s_bits[s] = val = s_strings.Add(s);
s_strings.Add(s);
s_bits[s] = val = s_strings.Count - 1;
}
}
return val;
Expand Down Expand Up @@ -135,7 +135,7 @@ public void Remove(StringSet set)
{
m_bits.Length = set.m_bits.Length = Math.Max(m_bits.Length, set.m_bits.Length);
// Not is destructive. Stupid.
BitArray os = (BitArray)set.m_bits.Clone();
BitArray os = new BitArray(set.m_bits);
os.Not();
m_bits.And(os);
}
Expand Down
64 changes: 13 additions & 51 deletions src/JabberNet/bedrock/io/ReadEventStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* --------------------------------------------------------------------------
/* --------------------------------------------------------------------------
* Copyrights
*
* Portions created by or assigned to Cursive Systems, Inc. are
Expand All @@ -12,8 +12,9 @@
* See licenses/Jabber-Net_LGPLv3.txt for details.
* --------------------------------------------------------------------------*/

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace JabberNet.bedrock.io
{
Expand Down Expand Up @@ -79,62 +80,23 @@ public override long Position
set { m_stream.Position = value; }
}

/// <summary>
/// Begins an asynchronous read operation.
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="count"></param>
/// <param name="callback"></param>
/// <param name="state"></param>
/// <returns></returns>
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return m_stream.BeginRead (buffer, offset, count, callback, state);
return m_stream.ReadAsync(buffer, offset, count, cancellationToken);
}

/// <summary>
/// Begins an asynchronous write operation.
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="count"></param>
/// <param name="callback"></param>
/// <param name="state"></param>
/// <returns></returns>
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return m_stream.BeginWrite (buffer, offset, count, callback, state);
return m_stream.WriteAsync(buffer, offset, count, cancellationToken);
}

/// <summary>
/// Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.
/// </summary>
public override void Close()
protected override void Dispose(bool disposing)
{
m_stream.Close ();
}

/// <summary>
/// Waits for the pending asynchronous read to complete.
/// </summary>
/// <param name="asyncResult"></param>
/// <returns></returns>
public override int EndRead(IAsyncResult asyncResult)
{
int count = m_stream.EndRead(asyncResult);
byte[] buf = System.Text.Encoding.UTF8.GetBytes("Read " + count + " bytes from async stream");
FireOnRead(buf, 0, buf.Length);
return count;
}

/// <summary>
/// Ends an asynchronous write operation.
/// </summary>
/// <param name="asyncResult"></param>
public override void EndWrite(IAsyncResult asyncResult)
{
m_stream.EndWrite (asyncResult);
base.Dispose(disposing);
if (disposing)
{
m_stream.Dispose();
}
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/JabberNet/bedrock/net/AsyncSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using zlib;

namespace JabberNet.bedrock.net
{
Expand Down
21 changes: 2 additions & 19 deletions src/JabberNet/bedrock/net/Exceptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* --------------------------------------------------------------------------
/* --------------------------------------------------------------------------
* Copyrights
*
* Portions created by or assigned to Cursive Systems, Inc. are
Expand All @@ -19,8 +19,7 @@ namespace JabberNet.bedrock.net
/// <summary>
/// Lame exception, since I couldn't find one I liked.
/// </summary>
[Serializable]
public class AsyncSocketConnectionException : System.SystemException
public class AsyncSocketConnectionException : Exception
{
/// <summary>
/// Create a new exception instance.
Expand Down Expand Up @@ -48,21 +47,5 @@ public AsyncSocketConnectionException(string description, Exception e)
: base(description, e)
{
}

/// <summary>
/// Initializes a new instance of the
/// AsyncSocketConnectionException class with serialized
/// data.
/// </summary>
/// <param name="info">The object that holds the serialized
/// object data.</param>
/// <param name="ctx">The contextual information about the
/// source or destination.</param>
protected AsyncSocketConnectionException(System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext ctx)
:
base(info, ctx)
{
}
}
}
Loading

0 comments on commit 1ceb4f9

Please sign in to comment.