Skip to content
Merged
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
697 changes: 348 additions & 349 deletions QuickFIXn/AbstractInitiator.cs

Large diffs are not rendered by default.

173 changes: 86 additions & 87 deletions QuickFIXn/ClientHandlerThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,117 +3,116 @@
using System;
using QuickFix.Logger;

namespace QuickFix
namespace QuickFix;

/// <summary>
/// Created by a ThreadedSocketReactor to handle a client connection.
/// Each ClientHandlerThread has a SocketReader which reads
/// from the socket.
/// </summary>
internal class ClientHandlerThread : IResponder, IDisposable
{
/// <summary>
/// Created by a ThreadedSocketReactor to handle a client connection.
/// Each ClientHandlerThread has a SocketReader which reads
/// from the socket.
/// </summary>
internal class ClientHandlerThread : IResponder, IDisposable
internal class ExitedEventArgs : EventArgs
{
internal class ExitedEventArgs : EventArgs
{
public ClientHandlerThread ClientHandlerThread { get; private set; }
public ClientHandlerThread ClientHandlerThread { get; private set; }

public ExitedEventArgs(ClientHandlerThread clientHandlerThread)
{
ClientHandlerThread = clientHandlerThread;
}
public ExitedEventArgs(ClientHandlerThread clientHandlerThread)
{
ClientHandlerThread = clientHandlerThread;
}
}

internal delegate void ExitedEventHandler(object sender, ExitedEventArgs e);
internal event ExitedEventHandler? Exited;
internal delegate void ExitedEventHandler(object sender, ExitedEventArgs e);
internal event ExitedEventHandler? Exited;

public long Id { get; private set; }
public long Id { get; private set; }

private Thread? _thread = null;
private volatile bool _isShutdownRequested = false;
private readonly SocketReader _socketReader;
private Thread? _thread = null;
private volatile bool _isShutdownRequested = false;
private readonly SocketReader _socketReader;

internal ClientHandlerThread(
TcpClient tcpClient,
long clientId,
SocketSettings socketSettings,
AcceptorSocketDescriptor? acceptorDescriptor,
IQuickFixLoggerFactory loggerFactory
) {
Id = clientId;
_socketReader = new SocketReader(tcpClient, socketSettings, this, acceptorDescriptor, loggerFactory);
}
internal ClientHandlerThread(
TcpClient tcpClient,
long clientId,
SocketSettings socketSettings,
AcceptorSocketDescriptor? acceptorDescriptor,
IQuickFixLoggerFactory loggerFactory
) {
Id = clientId;
_socketReader = new SocketReader(tcpClient, socketSettings, this, acceptorDescriptor, loggerFactory);
}

public void Start()
{
_thread = new Thread(Run);
_thread.Start();
}
public void Start()
{
_thread = new Thread(Run);
_thread.Start();
}

public void Shutdown(string reason)
{
// TODO - need the reason param?
_isShutdownRequested = true;
}
public void Shutdown(string reason)
{
// TODO - need the reason param?
_isShutdownRequested = true;
}

public void Join()
{
if (_thread is null)
return;
if (_thread.IsAlive)
_thread.Join(5000);
_thread = null;
}
public void Join()
{
if (_thread is null)
return;
if (_thread.IsAlive)
_thread.Join(5000);
_thread = null;
}

private void Run()
private void Run()
{
while (!_isShutdownRequested)
{
while (!_isShutdownRequested)
try
{
try
{
_socketReader.Read();
}
catch (Exception e)
{
Shutdown(e.Message);
}
_socketReader.Read();
}
catch (Exception e)
{
Shutdown(e.Message);
}

OnExited();
}

private void OnExited() {
Exited?.Invoke(this, new ExitedEventArgs(this));
}
OnExited();
}

#region Responder Members
private void OnExited() {
Exited?.Invoke(this, new ExitedEventArgs(this));
}

public bool Send(string data)
{
return _socketReader.Send(data) > 0;
}
#region Responder Members

public void Disconnect()
{
Shutdown("Disconnected");
}
public bool Send(string data)
{
return _socketReader.Send(data) > 0;
}

#endregion
public void Disconnect()
{
Shutdown("Disconnected");
}

~ClientHandlerThread() => Dispose(false);
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion

~ClientHandlerThread() => Dispose(false);
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private bool _disposed = false;
protected virtual void Dispose(bool disposing)
private bool _disposed = false;
protected virtual void Dispose(bool disposing)
{
if (_disposed) return;
if (disposing)
{
if (_disposed) return;
if (disposing)
{
_socketReader.Dispose();
}
_disposed = true;
_socketReader.Dispose();
}
_disposed = true;
}
}
Loading
Loading