Kleine AIS Korrekturen

This commit is contained in:
Daniel Schick 2018-06-23 10:51:52 +00:00
parent e54b6661cc
commit 4a2feba85a
3 changed files with 18 additions and 11 deletions

View File

@ -40,6 +40,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>

View File

@ -50,7 +50,7 @@ namespace LS100PortProxy
}
private class ConnectionInfo
{
{
public Socket Socket;
public Thread Thread;
public Queue<Chunk> chunks = new Queue<Chunk>();
@ -112,16 +112,16 @@ namespace LS100PortProxy
{ // Accept a connection
try
{
Socket socket = _serverSocket.Accept();
_log.InfoFormat("new connection from {0}", socket.RemoteEndPoint.ToString());
Socket socket = _serverSocket.Accept();
ConnectionInfo connection = new ConnectionInfo();
connection.Socket = socket; // Create the thread for the receives.
connection.Thread = new Thread(ProcessConnection);
connection.Thread.IsBackground = true;
connection.Thread.Start(connection);
connection.Thread.Start(connection);
// Store the socket
lock (_connections)
_connections.Add(connection);
_log.InfoFormat("new connection from {0}, total connections: {1}", socket.RemoteEndPoint.ToString(), _connections.Count);
}
catch (SocketException) { /* tu was */ }
Thread.Sleep(250);
@ -138,7 +138,7 @@ namespace LS100PortProxy
{
// write all chunks in incoming chunk queue to this socket
if (connection.Socket.Poll(1000, SelectMode.SelectWrite))
if (connection.Socket.Poll(500, SelectMode.SelectWrite))
{
while (connection.chunks.Count > 0)
{
@ -146,6 +146,7 @@ namespace LS100PortProxy
lock (_connections)
{
aChunk = connection.chunks.Dequeue();
//Trace.WriteLine(string.Format("{0} : {1}", connection.Socket.RemoteEndPoint, connection.chunks.Count));
}
int bytesToSend = aChunk.length;
byte[] buffer = aChunk.data;
@ -155,12 +156,13 @@ namespace LS100PortProxy
//string[] lines = testOutput.Split('\r');
//foreach(string line in lines)
// _log.Debug(line);
int actuallySentBytes = connection.Socket.Send(aChunk.data, aChunk.length, SocketFlags.None);
int actuallySentBytes = connection.Socket.Send(buffer, bytesToSend, SocketFlags.None);
//Trace.WriteLine(string.Format("{0}/{1}", actuallySentBytes, bytesToSend));
bytesToSend -= actuallySentBytes;
if (bytesToSend > 0)
{
byte[] newBuffer = new byte[bytesToSend];
Array.Copy(buffer, aChunk.length - bytesToSend, newBuffer, 0, bytesToSend);
Array.Copy(buffer, actuallySentBytes, newBuffer, 0, bytesToSend);
buffer = newBuffer;
}
}
@ -188,15 +190,14 @@ namespace LS100PortProxy
{ Console.WriteLine("Exception: " + exc); }
finally
{
_log.InfoFormat("removing connection to {0}", connection.Socket.RemoteEndPoint);
connection.Socket.Close();
lock (_connections)
_connections.Remove(connection);
_log.InfoFormat("connection closed, total connections: {0}", _connections.Count);
GC.Collect();
}
}
internal void StartClient()
{
this._clientThread = new Thread(new ThreadStart(this.ClientConnection));
@ -253,9 +254,10 @@ namespace LS100PortProxy
if(j > chunk.length) // es wurden CR eingefügt
{
chunk.data = null;
chunk.data = target;
chunk.length = j;
_log.DebugFormat("Chunk replaced, new length {0}", j);
_log.DebugFormat("Chunk data replaced, new length {0}", j);
}
if (chunk.length > 0 && (this._connections.Count > 0))
@ -267,10 +269,14 @@ namespace LS100PortProxy
{
foreach (ConnectionInfo connectionInfo in _connections)
{
connectionInfo.chunks.Enqueue(chunk.DeepClone());
connectionInfo.chunks.Enqueue(chunk.DeepClone());
}
}
chunk.data = null;
}
chunk = null;
}
}
else

Binary file not shown.