public Start ( OnNewClient onConnection ) : void | ||
onConnection | OnNewClient | |
return | void |
public void Start(OnNewClient onConnection)
{
InitListenException = null;
InitListenFinished.Reset();
IsListening = false;
IsShuttingDown = false;
OnClientStart = onConnection;
ListeningThread = new Thread(StartThread);
ListeningThread.Name = "ListenTCP";
ListeningThread.IsBackground = true;
ListeningThread.Start();
const int cleanTimeout = 300 * 1000; // in ms
CleanTimer = new Timer(new TimerCallback(CheckSockets), null,
cleanTimeout, cleanTimeout);
}
/// <summary> /// 指定ポートで Listening を開始する。 /// Shutdown() を呼び出さずに2回目の Startup() を呼び出した場合、InvalidOperationException が発生する。 /// </summary> /// <param name="listeningPort">Listeningするポート。</param> /// <param name="useIpV6">falseの場合、127.0.0.1で待ち受ける。trueの場合、::1で待ち受ける。既定false。</param> /// <param name="isSetProxyInProcess">trueの場合、プロセス内IEプロキシの設定を実施し、HTTP通信をNekoxyに向ける。既定true。</param> public static void Startup(int listeningPort, bool useIpV6 = false, bool isSetProxyInProcess = true) { if (server != null) throw new InvalidOperationException("Calling Startup() twice without calling Shutdown() is not permitted."); TransparentProxyLogic.AfterSessionComplete += InvokeAfterSessionComplete; TransparentProxyLogic.AfterReadRequestHeaders += InvokeAfterReadRequestHeaders; TransparentProxyLogic.AfterReadResponseHeaders += InvokeAfterReadResponseHeaders; ListeningPort = listeningPort; try { if (isSetProxyInProcess) WinInetUtil.SetProxyInProcessForNekoxy(listeningPort); server = new TcpServer(listeningPort, useIpV6); server.Start(TransparentProxyLogic.CreateProxy); server.InitListenFinished.WaitOne(); if (server.InitListenException != null) throw server.InitListenException; } catch (Exception) { Shutdown(); throw; } }