Skip to content

Commit

Permalink
LogModel disposability
Browse files Browse the repository at this point in the history
  • Loading branch information
duketwo committed Nov 13, 2016
1 parent c4ee589 commit c687655
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
31 changes: 20 additions & 11 deletions SharpLogLite/Model/LogModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class LogModel : IDisposable
{
private static ManualResetEvent ManualResetEvent = new ManualResetEvent(false);
public ConcurrentDictionary<uint?, FixedSizedQueue<SharpLogMessage>> Queues;
private Socket listener;

public LogModel()
{
Expand All @@ -33,23 +34,31 @@ public void StartListening()
IPEndPoint localEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3273);
Console.WriteLine("Local address and port : {0}", localEP.ToString());

Socket listener = new Socket(localEP.Address.AddressFamily,
this.listener = new Socket(localEP.Address.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);

try
{
listener.Bind(localEP);
listener.Listen(20);
this.listener.Bind(localEP);
this.listener.Listen(20);

while (true)
{
ManualResetEvent.Reset();
Console.WriteLine("Waiting for a connection...");
listener.BeginAccept(
new AsyncCallback(new LogModelHandler(ManualResetEvent, this.Queues).AcceptCallback),
listener);
try
{
ManualResetEvent.Reset();
Console.WriteLine("Waiting for a connection...");
this.listener.BeginAccept(
new AsyncCallback(new LogModelHandler(ManualResetEvent, this.Queues).AcceptCallback),
this.listener);

ManualResetEvent.WaitOne();
ManualResetEvent.WaitOne();
}
catch (Exception e)
{
Console.WriteLine(String.Format("Exception: {0}", e));
break;
}
}
}
catch (Exception e)
Expand All @@ -60,11 +69,11 @@ public void StartListening()
Console.WriteLine("Closing the listener...");
}



public void Dispose()
{

this.listener.Close();
}

}
Expand Down
3 changes: 1 addition & 2 deletions SharpLogLite/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
using System.Threading;

/*
* User: duketwo
* User: duketwo - https://github.com/duketwo/
* Date: 10.11.2016
*
*/

namespace SharpLogLite
Expand Down
5 changes: 5 additions & 0 deletions SharpLogLite/Utility/FixedSizedQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
using System.Collections.Concurrent;
using System.Collections.Specialized;

/*
* User: duketwo - https://github.com/duketwo/
* Date: 10.11.2016
*/

namespace SharpLogLite.Utility
{
/// <summary>
Expand Down

0 comments on commit c687655

Please sign in to comment.