After playing a while with Mono, I see one strange thing – every call to Send(), EndSend(), SendAsync() etc return not number of bytes sent in this particular operation, but total number of bytes sent during the lifetime of a Socket.
According to various sources (including official Microsoft documentation), the number of bytes sent should reflect only last operation (which seems logical and standard), but in Mono this is different.
I’ve tried Mono 2.8.2, 2.10.5 – this behaviour is still there. Looking into sources (including master on GitHub), I see that this is “behaviour by design”, however, this contradicts to documented behaviour.
So, my question is – is this a bug in Mono, or I misunderstood something? If this is a bug – how could it happen that it lurks there for years, and nobody noticed?
Sorry, but can’t reproduce that with Send or EndSend. Considering test program and Mono’s source code I would say there is no bug in Mono. Details below.
I used this code to test, it is not beautiful, however shows what should be shown:
On my machine output is:
Which is what expected. I was testing using Mono from git commit b21a860 on Ubuntu 10.10. About
send_so_far, you mentioned: please notice, that call toint Send (byte [] buf)callsinternal int Send_nochecks(...)and this in turn callsint Send_internal (socket, buf, offset, size, flags, out nativeError)which is tagged with[MethodImplAttribute (MethodImplOptions.InternalCall)](so implemented directly in runtime) and uses nosend_so_farat all. (As far as I can see,send_so_faris used in AsyncResult, but only in one AsyncResult, therefore it does not have to be zeroed – you can’t call EndSend twice on same AsyncResult.).EDIT:
I have just tested it with async version (i.e. EndSend) and it works properly too. Could you post some piece of problematic code?