mgravell / Pipelines.Sockets.Unofficial

.NET managed sockets wrapper using the new "Pipelines" API
Other
400 stars 51 forks source link

netstandard2.1 DoReceive fails on Zero Length Reads on Mono #70

Open HelloKitty opened 1 year ago

HelloKitty commented 1 year ago

Seems that netstandard2.1 fails to read zero length reads without exception from a combination of the SOCKET_STREAM_BUFFERS path combined with the fact that Mono checks the buffer and bufferlist is non-empty or non-null here: https://github.com/mono/mono/blame/main/mcs/class/System/System.Net.Sockets/Socket.cs#L1508

I don't know why suddenly this issue, after like a year of use, has come up but I guess it can only be because I've updated Unity3D and started targeting netstandard2.1.

I don't have a great solution other than just removing the SOCKET_STREAM_BUFFERS path in SocketConnection.DoRecieve and also setting the null buffer to an empty array with size 1. This solution is probably not ideal so hopefully you'll know what's best to change.

mgravell commented 1 year ago

Do you have a scenario in mind where this manifests? This is usually controlled via the SocketConnectionOptions.ZeroLengthReads flag, in which case: don't specify that?