[Mono-bugs] [Bug 44282][Cri] New - Socket.Poll always returns false

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Sat, 7 Jun 2003 06:41:07 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by giuseppe.greco@agamura.com.

http://bugzilla.ximian.com/show_bug.cgi?id=44282

--- shadow/44282	Sat Jun  7 06:41:07 2003
+++ shadow/44282.tmp.8615	Sat Jun  7 06:41:07 2003
@@ -0,0 +1,158 @@
+Bug#: 44282
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: Red Hat 9
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Critical
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: giuseppe.greco@agamura.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Socket.Poll always returns false
+
+Socket.Poll() always return false when checking
+for new datagrams.
+
+Here's how to reproduce the problem:
+
+1. Create a multicaster like this: 
+
+   using System;
+   using System.Net;
+   using System.Net.Sockets;
+   using System.Text;
+   using System.Threading;
+
+   class Multicaster
+   {
+     Socket socket;
+     IPEndPoint endPoint =
+       new IPEndPoint(IPAddress.Parse("224.100.0.1"), 9000);
+
+     public static void Main()
+     { 
+       socket = new Socket(
+         AddressFamily.InterNetwork,
+         SocketType.Dgram,
+         ProtocolType.Udp);
+
+       socket.SetSocketOption(
+         SocketOptionLevel.IP,
+         SocketOptionName.MulticastTimeToLive,
+         60);
+
+       socket.SetSocketOption(
+         SocketOptionLevel.IP,
+         SocketOptionName.AddMembership,
+         new MulticastOption(endPoint.Address);
+
+       byte[] data = Encoding.UTF8.GetBytes("Hello World");
+        
+       socket.BeginSendTo(
+         data,
+         0,
+         data.Length,
+         SocketFlags.None,
+         endPoint,
+         new AsyncCallback(AsyncSend),
+         socket);
+       
+       // Just to keep the process alive...
+       // I'm performing an async send
+       while (true) {
+         Thread.Sleep(2000);
+       }
+     }
+
+     private void AsyncSend(IAsyncResult asyncResult)
+     {
+       socket.EndSendTo(asyncResult);
+     }
+                                                                          
+                                  }
+
+2. Compile the code above as an exe (e.g sender.exe).
+
+3. Create a listener like this:
+
+   class Listener
+   {
+     Socket socket;
+     byte[] data = new byte[1024];
+     IPEndPoint endPoint =
+       new IPEndPoint(IPAddress.Parse("224.100.0.1"), 9000);
+
+     public static void Main()
+     {
+        socket = new Socket(
+          AddressFamily.InterNetwork,
+          SocketType.Dgram,
+          ProtocolType.Udp);
+
+        socket.Bind(new IPEndPoint(IPAddress.Any, endPoint.Port));
+
+                                                                          
+                                        socket.SetSocketOption(
+          SocketOptionLevel.IP,
+          SocketOptionName.AddMembership,
+          new MulticastOption(endPoint.Address);
+
+                                                                          
+                                      while (true) {
+        if (socket.Poll(1000000, SelectMode.SelectRead)) {
+          socket.BeginReceiveFrom(
+            data,
+            0,
+            data.Length,
+            SocketFlags.None,
+            ref endPoint,
+            new AsyncCallback(AsyncReceive),
+            socket);
+        }
+      }
+    }
+
+    private void AsyncReceive(IAsyncResult asyncResult)
+    {
+ 
+      EndPoint ep = (EndPoint) endPoint;
+      int recv = socket.EndReceiveFrom(asyncResult, ref endPoint);
+                                                                          
+                                 
+      if (recv > 0) {
+        Console.WriteLine("{0}", Encoding.UTF8.GetString(data, 0, recv));
+      }
+    }
+   }
+ 
+4. Compile the code above as an exe (e.g. receiver.exe)
+
+5. Run mono receiver.exe
+
+6. Run mono sender.exe
+
+
+Actual Results:
+The receiver doesn't display the message sent by
+the sender since Socket.Poll() always returns false.
+
+
+Expected Results:
+The receiver should display the message sent by
+the sender, and Socket.Poll() should return true
+when data arrives.
+
+How often does this happen? 
+Always.
+
+
+Additional Information:
+The example above does function on Windows with
+.NET; Try to run the two applications on the same
+machine.