Azure / Azure/DotNetty

Dotnetty's SocketDatagramChannel no have Socket.ReceiveFrom() in DoReadMessages()

Open
#538 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.3k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

dotnetty use for unity 2019.2f in mobile,
udp packet sending is work, but receieving is not work in my case...

and i try see it SocketDatagramChannel.cs ,

and i found SocketDatagramChannel no have Socket.ReceiveFrom() funtions...

maybe right this? please check this code and dotnetty's SocketDatagramChannel.cs

my english not good sorry.

SocketDatagramChannel.cs line 139

https://github.com/Azure/DotNetty/blob/dev/src/DotNetty.Transport/Channels/Sockets/SocketDatagramChannel.cs#L139
----------------------------------------------------------------------------------

protected override int DoReadMessages(List buf)
{
Contract.Requires(buf != null);

SocketChannelAsyncOperation operation = this.ReadOperation;
IByteBuffer data = (IByteBuffer)operation.UserToken;
bool free = true;

try
{
IRecvByteBufAllocatorHandle handle = this.Unsafe.RecvBufAllocHandle;

↓ changed
===============================================================
EndPoint remoteEndPoint = null;

if (this.Socket.Connected)
{
remoteEndPoint = this.Socket.RemoteEndPoint;
}
else
{
remoteEndPoint = operation.RemoteEndPoint;
}

int received = this.Socket.ReceiveFrom(data.Array, data.ArrayOffset + data.WriterIndex, data.WritableBytes, SocketFlags.None, ref remoteEndPoint);
============================================================

//int received = operation.BytesTransferred; <-- source
if (received <= 0)
{
return 0;
}

handle.LastBytesRead = received;
data.SetWriterIndex(data.WriterIndex + received);
EndPoint remoteAddress = operation.RemoteEndPoint;
buf.Add(new DatagramPacket(data, remoteAddress, this.LocalAddress));
free = false;

return 1;
}
finally
{
if (free)
{
data.Release();
}

operation.UserToken = null;
}
}

-------------------------------------------------------------------------------------

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.