Hi,
I was trying to use the System.Net.Socket.SendPacketsAsync method to send files but I get an error on files larger than 2GB. Then I tried to specify a file offset but only get 2 extra GB, for now being able to send 4GB files.
The reason is the Offset field in the System.Net.Socket.SendPacketsElement class is an Int32. However for representing a file offset it is often necesary an Int64 field. I checked out the internal structures that pass this value to native methods and in correspondency with accepted values from the Windows socket API, specifically the TransmitFile function, they are long fields.
Because of this, apparently the only restriction is in the interface provided by the System.Net.Socket.SendPacketsElement class.
This class tries to support both, buffers and files. Considering this, maybe the field size was restricted because byte arrays on a 32bit environment are limited to an Int32 max size but not a reason to kill functionality. Adding a new constructor overload and making the internal offset field a long value should be enough.
Is this restriction on purpose and why, or just a .NET issue?
[Edited]
My question is not looking for alternatives to sending files. Let me try again.
The .NET Socket.SendPacketsAsync is something like the equivalent to the Windows API functions TransmitFile or TransmitPackets, it uses it behind the escenes to transmit files. However while the TransmitFile/TransmitPackets functions allows to specify file offsets using a variable of type long (64bits) the .NET equivalent is restricted to variables of type int (32bits). This restriction limits the maximum file size to be transmitted in .NET to the number of bytes that can be represented with an Int32 (4GB). So my question is:
Why the .NET Framework uses an Int32 field to match an API function that requires an Int64 field, they have a good reason or it was by mistake?
Notes:
- If you are not familiar with the TransmitFile function, TransmitPackets function, Socket.SendPacketAsync function, SendPacketsElement class and so on, please don't asnwer the question.
- TransmitFile function
- TransmitPackets function
- Socket.SendPacketsAsync method
- Sendpacketselement class