[Mono-bugs] [Bug 502866] New: UDPClient.Recieve does not honor Socket.ReceiveTimeout

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon May 11 16:34:39 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=502866


           Summary: UDPClient.Recieve does not honor Socket.ReceiveTimeout
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 1.9
          Platform: i386
        OS/Version: RHEL 5
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: kingsley at hostby.net
         QAContact: mono-bugs at lists.ximian.com
          Found By: Community User


Description of Problem:

A UDPClient object is created to communicate with a remove UDP service.  It
uses blocking calls to Send and Receive.  

Steps to reproduce the problem:
1. A UDP server that receives UDP packets and drops them.
This can be create simply using netcat
nc -lu 4567
2:

Compiled On MS .net 2.0

using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            UdpClient c = new UdpClient();
            c.Connect("localhost", 4567);
            c.Client.ReceiveTimeout = 4000; //4 seconds
            c.Send(new byte[] { 0x77 }, 1);
            IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 0);
            byte[] result = c.Receive(ref endpoint);
            Console.WriteLine("end");

        }
    }
}


Actual Results:

Receive call continues to block the thread and never times out, despite not
receiving a response.

Expected Results:

Receive call times out and raises a "timeout exception" (this is what happens
on MS .net

How often does this happen? 

Everytime.

Additional Information:

A workaround is to use the raw socket:  

UdpClient c = new UdpClient();
c.Connect("localhost", 4567);
c.Client.ReceiveTimeout = 4000; //4 seconds
c.Send(new byte[] { 0x77 }, 1);
IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 0);
byte[] buffer = new byte[51000]; //max udp packet size on linux (your operating
system may vary)
int len = c.Client.Receive(buffer, buffer.Length, SocketFlags.None);
byte[] result = new byte[len];
Array.ConstrainedCopy(buffer,0,result,0,len);
Console.WriteLine("end");

On MS.net this runs fine, it only affects mono, whether mono or ms.net has the
correct behaviour i'm not sure, its pretty ambiguous from the documentation.

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list