提交 a220f6aa 编写于 作者: JasonWcx's avatar JasonWcx

InvokeAfterReceiveEnd增加try catch

上级 94f8da09
...@@ -27,7 +27,7 @@ namespace Mozi.HttpEmbedded.Test ...@@ -27,7 +27,7 @@ namespace Mozi.HttpEmbedded.Test
//启用HTTPS //启用HTTPS
//hs.UseHttps().LoadCert(AppDomain.CurrentDomain.BaseDirectory + @"Cert\ServerCert.pfx", "12345678"); //hs.UseHttps().LoadCert(AppDomain.CurrentDomain.BaseDirectory + @"Cert\ServerCert.pfx", "12345678");
//配置端口并启动服务器 //配置端口并启动服务器
hs.SetPort(9000).Start(); hs.SetPort(8080).Start();
//开启认证 //开启认证
//hs.UseAuth(AuthorizationType.Basic).SetUser("admin", "admin"); //hs.UseAuth(AuthorizationType.Basic).SetUser("admin", "admin");
......
...@@ -151,7 +151,7 @@ namespace Mozi.HttpEmbedded ...@@ -151,7 +151,7 @@ namespace Mozi.HttpEmbedded
int posCaret = 0; int posCaret = 0;
int count = 0; int count = 0;
int index = 0; int indLine = 0;
int dataLength = data.Length; int dataLength = data.Length;
while ((posCR < dataLength) && Array.IndexOf(data, ASCIICode.CR, posCR + 1) > 0) while ((posCR < dataLength) && Array.IndexOf(data, ASCIICode.CR, posCR + 1) > 0)
{ {
...@@ -160,7 +160,7 @@ namespace Mozi.HttpEmbedded ...@@ -160,7 +160,7 @@ namespace Mozi.HttpEmbedded
//连续两个CR //连续两个CR
byte[] fragement = new byte[posCR - posCaret]; byte[] fragement = new byte[posCR - posCaret];
Array.Copy(data, posCaret, fragement, 0, posCR - posCaret); Array.Copy(data, posCaret, fragement, 0, posCR - posCaret);
if (index == 0) if (indLine == 0)
{ {
ParseRequestLine(ref req, fragement); ParseRequestLine(ref req, fragement);
} }
...@@ -175,7 +175,7 @@ namespace Mozi.HttpEmbedded ...@@ -175,7 +175,7 @@ namespace Mozi.HttpEmbedded
} }
//跳过分割字节段 //跳过分割字节段
posCaret = posCR + 2; posCaret = posCR + 2;
index++; indLine++;
//TODO 置空对象 //TODO 置空对象
} }
...@@ -594,7 +594,7 @@ namespace Mozi.HttpEmbedded ...@@ -594,7 +594,7 @@ namespace Mozi.HttpEmbedded
req.Method = rm; req.Method = rm;
//判断方法是否是已知方法 //判断方法是否是已知方法
if (object.Equals(req.Method,null)) if (Equals(req.Method,null))
{ {
req.Method = new RequestMethod(sMethod); req.Method = new RequestMethod(sMethod);
} }
......
...@@ -159,6 +159,8 @@ namespace Mozi.HttpEmbedded ...@@ -159,6 +159,8 @@ namespace Mozi.HttpEmbedded
StateObject so = (StateObject)iar.AsyncState; StateObject so = (StateObject)iar.AsyncState;
Socket client = so.WorkSocket; Socket client = so.WorkSocket;
if (client.Connected) if (client.Connected)
{
try
{ {
int iByteRead = client.EndReceive(iar); int iByteRead = client.EndReceive(iar);
...@@ -181,12 +183,19 @@ namespace Mozi.HttpEmbedded ...@@ -181,12 +183,19 @@ namespace Mozi.HttpEmbedded
InvokeAfterReceiveEnd(so, client); InvokeAfterReceiveEnd(so, client);
} }
} }
finally
{
}
}
else else
{ {
InvokeAfterReceiveEnd(so, client); InvokeAfterReceiveEnd(so, client);
} }
} }
private void InvokeAfterReceiveEnd(StateObject so, Socket client) private void InvokeAfterReceiveEnd(StateObject so, Socket client)
{
try
{ {
RemoveClientSocket(so); RemoveClientSocket(so);
if (AfterReceiveEnd != null) if (AfterReceiveEnd != null)
...@@ -202,6 +211,9 @@ namespace Mozi.HttpEmbedded ...@@ -202,6 +211,9 @@ namespace Mozi.HttpEmbedded
State = so State = so
}); });
} }
}finally{
}
} }
//TODO 此处开启Socket状态监听,对断开的链接进行关闭销毁 //TODO 此处开启Socket状态监听,对断开的链接进行关闭销毁
private void RemoveClientSocket(StateObject so) private void RemoveClientSocket(StateObject so)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册