Skip to content

Commit 591f6db

Browse files
author
Hiram
committed
add disconnect event
1 parent a26ba75 commit 591f6db

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/HiSocket/TcpConnection/Socket/TcpSocket.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,14 @@ private void EndSend(IAsyncResult ar)
211211
Array.Copy(SendBuffer.Array, SendBuffer.ReadPosition, sendBytes, 0, sendBytes.Length);
212212
SocketSendEvent(sendBytes);
213213
SendBuffer.MoveReadPosition(length);
214-
Send();
214+
if (length > 0)
215+
{
216+
Send();
217+
}
218+
else
219+
{
220+
DisconnectedEvnet();
221+
}
215222
}
216223

217224
private void Receive()
@@ -247,7 +254,14 @@ private void EndReceive(IAsyncResult ar)
247254
ReceiveBuffer.MoveWritePosition(length);
248255
var bytes = ReceiveBuffer.ReadAll();
249256
SocketReceiveEvent(bytes);
250-
Receive();
257+
if (length > 0)
258+
{
259+
Receive();
260+
}
261+
else
262+
{
263+
DisconnectedEvnet();
264+
}
251265
}
252266

253267
public void DisConnect()

0 commit comments

Comments
 (0)