Skip to content

Commit

Permalink
add disconnect event
Browse files Browse the repository at this point in the history
  • Loading branch information
hiram3512 committed Sep 2, 2018
1 parent a26ba75 commit 591f6db
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/HiSocket/TcpConnection/Socket/TcpSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,14 @@ private void EndSend(IAsyncResult ar)
Array.Copy(SendBuffer.Array, SendBuffer.ReadPosition, sendBytes, 0, sendBytes.Length);
SocketSendEvent(sendBytes);
SendBuffer.MoveReadPosition(length);
Send();
if (length > 0)
{
Send();
}
else
{
DisconnectedEvnet();
}
}

private void Receive()
Expand Down Expand Up @@ -247,7 +254,14 @@ private void EndReceive(IAsyncResult ar)
ReceiveBuffer.MoveWritePosition(length);
var bytes = ReceiveBuffer.ReadAll();
SocketReceiveEvent(bytes);
Receive();
if (length > 0)
{
Receive();
}
else
{
DisconnectedEvnet();
}
}

public void DisConnect()
Expand Down

0 comments on commit 591f6db

Please sign in to comment.