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

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);
}
......
......@@ -160,25 +160,32 @@ namespace Mozi.HttpEmbedded
Socket client = so.WorkSocket;
if (client.Connected)
{
int iByteRead = client.EndReceive(iar);
if (iByteRead > 0)
try
{
//置空数据缓冲区
so.ResetBuffer(iByteRead);
if (client.Available > 0)
int iByteRead = client.EndReceive(iar);
if (iByteRead > 0)
{
//Thread.Sleep(10);
client.BeginReceive(so.Buffer, 0, so.Buffer.Length, SocketFlags.None, CallbackReceived, so);
//置空数据缓冲区
so.ResetBuffer(iByteRead);
if (client.Available > 0)
{
//Thread.Sleep(10);
client.BeginReceive(so.Buffer, 0, so.Buffer.Length, SocketFlags.None, CallbackReceived, so);
}
else
{
InvokeAfterReceiveEnd(so, client);
}
}
else
{
InvokeAfterReceiveEnd(so, client);
}
}
else
finally
{
InvokeAfterReceiveEnd(so, client);
}
}
else
......@@ -188,19 +195,24 @@ namespace Mozi.HttpEmbedded
}
private void InvokeAfterReceiveEnd(StateObject so, Socket client)
{
RemoveClientSocket(so);
if (AfterReceiveEnd != null)
try
{
AfterReceiveEnd(this,
new DataTransferArgs()
{
Data = so.Data.ToArray(),
IP = so.IP,
Port = so.RemotePort,
Socket = so.WorkSocket,
Client = client,
State = so
});
RemoveClientSocket(so);
if (AfterReceiveEnd != null)
{
AfterReceiveEnd(this,
new DataTransferArgs()
{
Data = so.Data.ToArray(),
IP = so.IP,
Port = so.RemotePort,
Socket = so.WorkSocket,
Client = client,
State = so
});
}
}finally{
}
}
//TODO 此处开启Socket状态监听,对断开的链接进行关闭销毁
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册