11,7 → 11,6 |
// 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 |
158,7 → 157,7 |
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
socket.Bind(new IPEndPoint(IPAddress.Any, listenPort)); |
socket.Listen(100); |
ThreadDebugger.Add(socket.BeginAccept(new AsyncCallback(OnClientConnect), null), "StartListening"); |
socket.BeginAccept(new AsyncCallback(OnClientConnect), null); |
SendLog(null, LogLevel.Important, "Listen on " + socket.LocalEndPoint); |
} |
|
201,7 → 200,7 |
try |
{ |
Socket worker = socket.EndAccept(asyn); |
ThreadDebugger.Add(socket.BeginAccept(new AsyncCallback(OnClientConnect), null), "OnClientConnect"); // wait for next client |
socket.BeginAccept(new AsyncCallback(OnClientConnect), null); // wait for next client |
|
TcpConnection tcp = new TcpConnection(string.Format("{0:0000}", tcpId++)); |
tcp.Close += new TcpEventHandler(TcpConnectionClosed); |
755,7 → 754,6 |
this.localSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1); |
|
localSendThread = new Thread(new ThreadStart(LocalSendProc)); |
ThreadDebugger.Add(localSendThread, "LocalSendProc"); |
localSendThread.Name = "SocketWorker.LocalSendProc"; |
localSendThread.Start(); |
|
777,7 → 775,6 |
tcp.SetRemotePoint((IPEndPoint)remoteSocket.RemoteEndPoint); |
|
remoteSendThread = new Thread(new ThreadStart(RemoteSendProc)); |
ThreadDebugger.Add(remoteSendThread, "RemoteSendProc"); |
remoteSendThread.Name = "SocketWorker.RemoteSendProc"; |
remoteSendThread.Start(); |
|
804,9 → 801,7 |
try |
{ |
localDataBuffer = new byte[BUF_SIZE]; |
ThreadDebugger.Add( |
localSocket.BeginReceive(localDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveLocalMethod, this), |
"ContinueLocalReceive"); |
localSocket.BeginReceive(localDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveLocalMethod, this); |
} |
catch(ObjectDisposedException ex) // the socket is closed |
{ |
825,9 → 820,7 |
try |
{ |
remoteDataBuffer = new byte[BUF_SIZE]; |
ThreadDebugger.Add( |
remoteSocket.BeginReceive(remoteDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveRemoteMethod, this), |
"ContinueRemoteReceive"); |
remoteSocket.BeginReceive(remoteDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveRemoteMethod, this); |
} |
catch(ObjectDisposedException ex) // the socket is closed |
{ |
1439,7 → 1432,6 |
{ |
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(); |
|
1475,7 → 1467,6 |
try |
{ |
responseThread = new Thread(new ThreadStart(MatchResponses)); |
ThreadDebugger.Add(responseThread, "MatchResponses"); |
responseThread.Name = "HttpParser.MatchResponses"; |
responseThread.Start(); |
|
2460,61 → 2451,4 |
} |
} |
|
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; |
} |
} |
} |
} |