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

InvokeAfterReceiveEnd增加try catch

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