[Mono-dev] Socket.BeginReceive never throw Exception

Stefan [At] swieser1983 at gmail.com
Mon Apr 12 04:22:46 EDT 2010

> 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

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.

More information about the Mono-devel-list mailing list