11,6 → 11,7 |
// FIXME deny write access to all public properties |
// FIXME for text/xml get encoding from body if not specified in header |
// FIXME option to not store parsed data, just raw packets and reparse on demand |
// FIXME implement chunk-encoding |
namespace TCPproxy |
{ |
public enum BinLogTypes |
157,7 → 158,7 |
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
socket.Bind(new IPEndPoint(IPAddress.Any, listenPort)); |
socket.Listen(100); |
socket.BeginAccept(new AsyncCallback(OnClientConnect), null); |
ThreadDebugger.Add(socket.BeginAccept(new AsyncCallback(OnClientConnect), null), "StartListening"); |
SendLog(null, LogLevel.Important, "Listen on " + socket.LocalEndPoint); |
} |
|
200,7 → 201,7 |
try |
{ |
Socket worker = socket.EndAccept(asyn); |
socket.BeginAccept(new AsyncCallback(OnClientConnect), null); // wait for next client |
ThreadDebugger.Add(socket.BeginAccept(new AsyncCallback(OnClientConnect), null), "OnClientConnect"); // wait for next client |
|
TcpConnection tcp = new TcpConnection(string.Format("{0:0000}", tcpId++)); |
tcp.Close += new TcpEventHandler(TcpConnectionClosed); |
754,6 → 755,7 |
this.localSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1); |
|
localSendThread = new Thread(new ThreadStart(LocalSendProc)); |
ThreadDebugger.Add(localSendThread, "LocalSendProc"); |
localSendThread.Name = "SocketWorker.LocalSendProc"; |
localSendThread.Start(); |
|
775,6 → 777,7 |
tcp.SetRemotePoint((IPEndPoint)remoteSocket.RemoteEndPoint); |
|
remoteSendThread = new Thread(new ThreadStart(RemoteSendProc)); |
ThreadDebugger.Add(remoteSendThread, "RemoteSendProc"); |
remoteSendThread.Name = "SocketWorker.RemoteSendProc"; |
remoteSendThread.Start(); |
|
801,7 → 804,9 |
try |
{ |
localDataBuffer = new byte[BUF_SIZE]; |
localSocket.BeginReceive(localDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveLocalMethod, this); |
ThreadDebugger.Add( |
localSocket.BeginReceive(localDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveLocalMethod, this), |
"ContinueLocalReceive"); |
} |
catch(ObjectDisposedException ex) // the socket is closed |
{ |
820,7 → 825,9 |
try |
{ |
remoteDataBuffer = new byte[BUF_SIZE]; |
remoteSocket.BeginReceive(remoteDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveRemoteMethod, this); |
ThreadDebugger.Add( |
remoteSocket.BeginReceive(remoteDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveRemoteMethod, this), |
"ContinueRemoteReceive"); |
} |
catch(ObjectDisposedException ex) // the socket is closed |
{ |
1432,6 → 1439,7 |
{ |
HttpParser parser = new HttpParser(messages); |
parser.runThread = new Thread(new ThreadStart(parser.Run)); |
ThreadDebugger.Add(parser.runThread, "HttpParser.Run"); |
parser.runThread.Name = "HttpParser.Run"; |
parser.runThread.Start(); |
|
1467,6 → 1475,7 |
try |
{ |
responseThread = new Thread(new ThreadStart(MatchResponses)); |
ThreadDebugger.Add(responseThread, "MatchResponses"); |
responseThread.Name = "HttpParser.MatchResponses"; |
responseThread.Start(); |
|
2451,4 → 2460,61 |
} |
} |
|
public class ThreadDebugger |
{ |
private static ArrayList threads = new ArrayList(); |
private static ArrayList asyncs = new ArrayList(); |
|
internal static void Add(Thread thread, string comment) |
{ |
threads.Add(new ThreadItem(thread, comment)); |
Console.WriteLine("ThreadDebugger: thread added {0}", comment); |
} |
|
internal static void Add(IAsyncResult async, string comment) |
{ |
asyncs.Add(new AsyncItem(async, comment)); |
Console.WriteLine("ThreadDebugger: async added ", comment); |
} |
|
public static void PrintStatus() |
{ |
Console.WriteLine("=== ThreadDebugger Status Begin ======"); |
Console.WriteLine("--- Threads --------------------------"); |
foreach(ThreadItem t in threads) |
{ |
Console.WriteLine("{0} ({1}): {2}", t.thread.Name, t.comment, t.thread.IsAlive ? "alive" : "dead"); |
} |
Console.WriteLine("--- Asyncs ---------------------------"); |
foreach(AsyncItem a in asyncs) |
{ |
Console.WriteLine("{0}: {1}", a.comment, a.async.IsCompleted ? "alive" : "dead"); |
} |
Console.WriteLine("=== ThreadDebugger Status End ========"); |
} |
|
private class ThreadItem |
{ |
public Thread thread; |
public string comment; |
|
public ThreadItem(Thread thread, string comment) |
{ |
this.thread = thread; |
this.comment = comment; |
} |
} |
|
private class AsyncItem |
{ |
public IAsyncResult async; |
public string comment; |
|
public AsyncItem(IAsyncResult async, string comment) |
{ |
this.async = async; |
this.comment = comment; |
} |
} |
} |
} |