• R/O
  • SSH
  • HTTPS

ewatch: Commit


Commit MetaInfo

Révision92 (tree)
l'heure2018-04-07 17:49:11
Auteurbananajinn

Message de Log

reloadコマンドを受けた時に ObjectDisposedException で強制終了してしまうのを回避

Change Summary

Modification

--- trunk/EWatch/EWatch/Server/TcpServer.cs (revision 91)
+++ trunk/EWatch/EWatch/Server/TcpServer.cs (revision 92)
@@ -95,32 +95,36 @@
9595
9696 void Accept(IAsyncResult ar)
9797 {
98- var tcpClient = tcpListener.EndAcceptTcpClient(ar);
99- Task.Factory.StartNew(
100- () => {
101- try {
102- var clientAddress = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString();
103- log.InfoFormat("Connect from {0}.", clientAddress);
104- tcpClient.NoDelay = true;
105- tcpClient.ReceiveTimeout = 30000;
106- var stream = tcpClient.GetStream();
107- while(tcpClient.Connected){
108- var commandLine = StreamUtil.ReadLine(stream);
109- if(string.IsNullOrEmpty(commandLine)){
110- break;
98+ try {
99+ var tcpClient = tcpListener.EndAcceptTcpClient(ar);
100+ Task.Factory.StartNew(
101+ () => {
102+ try {
103+ var clientAddress = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString();
104+ log.InfoFormat("Connect from {0}.", clientAddress);
105+ tcpClient.NoDelay = true;
106+ tcpClient.ReceiveTimeout = 30000;
107+ var stream = tcpClient.GetStream();
108+ while(tcpClient.Connected){
109+ var commandLine = StreamUtil.ReadLine(stream);
110+ if(string.IsNullOrEmpty(commandLine)){
111+ break;
112+ }
113+ ExecuteCommand(commandLine, stream, clientAddress);
111114 }
112- ExecuteCommand(commandLine, stream, clientAddress);
113115 }
114- }
115- catch(Exception ex){
116- log.Error("error", ex);
117- var data = Encoding.UTF8.GetBytes(string.Concat("[ERROR] ", ex.Message));
118- tcpClient.GetStream().Write(data, 0, data.Length);
119- }
120- finally {
121- tcpClient.Close();
122- }
123- });
116+ catch(Exception ex){
117+ log.Error("error", ex);
118+ var data = Encoding.UTF8.GetBytes(string.Concat("[ERROR] ", ex.Message));
119+ tcpClient.GetStream().Write(data, 0, data.Length);
120+ }
121+ finally {
122+ tcpClient.Close();
123+ }
124+ });
125+ } catch(ObjectDisposedException ex){
126+ log.Debug("Canceled", ex);
127+ }
124128 if(tcpListener.Server.IsBound)
125129 tcpListener.BeginAcceptTcpClient(Accept, tcpListener);
126130 }
Afficher sur ancien navigateur de dépôt.