Socket.SendAsync does not send an order to Mono / Linux

There is a single-threaded server using the .NET Socket with TCP and Socket.Pool(), Socket.Select(), Socket.Receive().

To send, I used:

public void SendPacket(int clientid, byte[] packet)
{
    clients[clientid].socket.Send(packet);
}

But it was very slow when sending a large amount of data to one client (stopping the entire main thread), so I replaced it with this:

public void SendPacket(int clientid, byte[] packet)
{
    using (SocketAsyncEventArgs e = new SocketAsyncEventArgs())
    {
        e.SetBuffer(packet, 0, packet.Length);
        clients[clientid].socket.SendAsync(e);
    }
}

It works fine on Windows with .NET (I don’t know if this is great), but on Linux with Mono, packages are either discarded or reordered (I don’t know). Reverting to the slow version using Socket.Send () works on Linux. Source for the entire server .

How to write a non-blocking SendPacket () function that works on Linux?

+3
source share
3 answers

, using SendAsync. , e , SendAsync . . . using , .

+1

, . , , . iem , , , oder , .

:

  • .
  • dasta , , (ThreadPool) .

, , . /.

0

; Linux SendAsync. linux , . , . , SendAsync, . e.Offset + e.BytesTransferred < e.Buffer.Length, e.SetBuffer(e.Offset + e.BytesTransferred, e.Buffer.Length - e.BytesTransferred - e.Offset); SendAsync.

, mono-linux , , , , .

0

Source: https://habr.com/ru/post/1788914/


All Articles