[Mono-dev] Socket.BeginReceive never throw Exception

Alan McGovern alan.mcgovern at gmail.com
Mon Apr 12 05:20:25 EDT 2010


Hey,

It really does look like a valid issue but as it stands there's no
testcase to reproduce the issue. I do this *all* the time in the
testcases for MonoTorrent and my callbacks are always invoked. I
explicitly test for this in some of my testcases. There are times when
EndReceive is not supposed to throw an exception even though the
socket is not connected. Maybe you're hitting this case. It's just
impossible for me to see this bug happening so it's impossible for us
to fix it.

I'm not asking you to defend your bug report, i'm just asking you to
make it easy for us to fix it. You have a testcase which can reproduce
the bug 100% of the time. If that testcase could be supplied as part
of the bug report, it would be so much easier to resolve the issue.
All you need to do is put the testcase in a console app so that we can
just compile and run it to see the issue.

Thanks,
Alan.

On Mon, Apr 12, 2010 at 9:22 AM, Stefan [At] <swieser1983 at gmail.com> wrote:
>
>> Is there a testcase for this? This works fine for me, I'm inclined to
>> believe there's a bug in the testcase.
>
> My code relying on the callback on disconnect works fine with Microsoft's
> .NET and it doesn't work with Mono because the callback never occurs. Thus,
> the behaviour from both frameworks deviate. I think my original message
> never posted to the mailing list, so essentially, this is the code I'm
> using:
>
> Socket socket = server.AcceptSocket();
> socket.NoDelay = true;
> socket.Blocking = false;
>
> [...]
>
> socket.BeginReceive(receive_buffer, 0, buffer_size, 0, new
> AsyncCallback(ReceiveDone), socket);
>
> [...]
>
> public void ReceiveDone(IAsyncResult result) {
>    Socket socket = (Socket)result.AsyncState;
>    int bytes_read = socket.EndReceive(result);
>
> [...]
>
> }
>
> The workaround to run through all Sockets and check for the Connected
> property being set to false works with Mono and isn't needed for Microsoft's
> .NET (as the event properly fires). Sockets are set into NoDelay,
> NonBlocking mode and then use asynchronous calls with BeginReceive and
> EndReceive. Maybe it is that particular constellation, or maybe the g++
> compiler, or maybe the host system.
>
> bash-3.2# mono --version
> Mono JIT compiler version 2.6.1 (tarball Thu Apr  8 13:02:55 UTC 2010)
> Copyright (C) 2002-2008 Novell, Inc and Contributors. www.mono-project.com
>        TLS:           __thread
>        GC:            Included Boehm (with typed GC and Parallel Mark)
>        SIGSEGV:       altstack
>        Notifications: epoll
>
> I know, this is not the most recent version ATM, but the OP replied that
> this behaviour occurs with 2.6.3 as well and I do trust their judgement.
>
> I've never gotten into the notion on having to defend my bug reports. I do
> my own test cases and testing, but you are welcome to put it down as a bug
> in my code. As I only need Mono for a quick internal use case in two weeks'
> time, I'll get away using a workaround. Good luck getting this fixed (should
> you decide to treat it as a valid issue), and take care ;)
> --
> View this message in context: http://n4.nabble.com/Socket-BeginReceive-never-throw-Exception-tp1679973p1836801.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>


More information about the Mono-devel-list mailing list