[Mono-list] Async Sockets with List<ArraySegment<byte>> -- Is It Supposed to Work?

Ken98045 kkoch at centralert.com
Wed May 28 12:39:43 EDT 2008


Are async sockets with List<ArraySegment<byte>> supposed to work?  I am
working with Mono on Windows, AND on the Mac.  I can get BeginReceive to
work using buffers, but not with List<ArraySegment<byte>>.  Basically at
some point before the callback function is called I'm getting an Access
Violation exception in Mono itself.  This is the same for both the PC and
the Mac.

I have written about the simplest possible test code, and haven't had any
luck.  If this had not been implement I would think I'd get a "Not
Implemented" exception when BeginReceive was called.

The same problem occurs with BeginSend.

Here is some simple test code.

  public class Tester
  {
    Socket _listenSocket;
    Socket _outgoingSocket;
    Socket _receiveSocket;
    Socket _connected;
    byte[] buffer = new byte[10000];
    byte[] outBuffer = new byte[10000];
    List<ArraySegment<byte>> _list = new List<ArraySegment<byte>>();

    public Tester()
    {
      IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 44444);
      _listenSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
      _listenSocket.Bind(endpoint);
      _listenSocket.Listen(10);

      _outgoingSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
      _outgoingSocket.Connect("localhost", 44444);
      _connected = _listenSocket.Accept();
      ArraySegment<byte> seg = new ArraySegment<byte>(outBuffer, 0, 10);
      _list.Add(seg);
      _connected.BeginReceive(_list, SocketFlags.None, OnReceiveComplete,
_connected);
      _outgoingSocket.BeginSend(buffer, 0, 0, SocketFlags.None,
OnSendComplete, null);
      SocketError err;
      _outgoingSocket.Send(outBuffer, 0, 10, SocketFlags.None, out err);
      Thread.Sleep(1000);
    }

    public void OnReceiveComplete(IAsyncResult ar)
    {
      // This NEVER gets called.
      Console.WriteLine("OnReceiveComplete");
      int bytesReceived = _connected.EndReceive(ar);
      Console.WriteLine("Bytes received: {0}", bytesReceived);

    }

    public void OnSendComplete(IAsyncResult ar)
    {
      // This does get called.
      Console.WriteLine("OnSendComplete");
      int bytesSent = _outgoingSocket.EndSend(ar);


    }

  }

-- 
View this message in context: http://www.nabble.com/Async-Sockets-with-List%3CArraySegment%3Cbyte%3E%3E----Is-It-Supposed-to-Work--tp17516954p17516954.html
Sent from the Mono - General mailing list archive at Nabble.com.



More information about the Mono-list mailing list