mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-18 11:48:33 -04:00
Fix not handling partial sends, which would very rarely occur and then cause the game to disconnect with invalid packet
This commit is contained in:
parent
0f590755e8
commit
93c2c9a30a
@ -219,11 +219,20 @@ namespace MCGalaxy.Network {
|
|||||||
static void SendCallback(object sender, SocketAsyncEventArgs e) {
|
static void SendCallback(object sender, SocketAsyncEventArgs e) {
|
||||||
TcpSocket s = (TcpSocket)e.UserToken;
|
TcpSocket s = (TcpSocket)e.UserToken;
|
||||||
try {
|
try {
|
||||||
// TODO: Need to check if all data was sent or not?
|
lock (s.sendLock) {
|
||||||
int sent = e.BytesTransferred;
|
// check if last packet was only partially sent? try to resend it
|
||||||
lock (s.sendLock) {
|
for (;;) {
|
||||||
|
int sent = e.BytesTransferred;
|
||||||
|
int count = e.Count;
|
||||||
|
if (sent >= count || sent < 0) break;
|
||||||
|
|
||||||
|
// last packet was only partially sent - resend rest of packet
|
||||||
|
s.sendArgs.SetBuffer(e.Offset + sent, e.Count - sent);
|
||||||
|
s.sendInProgress = s.socket.SendAsync(s.sendArgs);
|
||||||
|
if (s.sendInProgress) return;
|
||||||
|
}
|
||||||
|
|
||||||
s.sendInProgress = false;
|
s.sendInProgress = false;
|
||||||
|
|
||||||
while (s.sendQueue.Count > 0) {
|
while (s.sendQueue.Count > 0) {
|
||||||
// DoSendAsync returns false if SendAsync completed sync
|
// DoSendAsync returns false if SendAsync completed sync
|
||||||
// If that happens, SendCallback isn't called so we need to send data here instead
|
// If that happens, SendCallback isn't called so we need to send data here instead
|
||||||
|
Loading…
x
Reference in New Issue
Block a user