dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System/Net Dns.cs,1.2,1.3


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System/Net Dns.cs,1.2,1.3
Date: Sun, 11 May 2003 15:11:29 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System/Net
In directory subversions:/tmp/cvs-serv8737/System/Net

Modified Files:
        Dns.cs 
Log Message:
Fake Async DNS Operations


Index: Dns.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/Dns.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Dns.cs      14 Sep 2002 08:19:45 -0000      1.2
--- Dns.cs      11 May 2003 19:11:27 -0000      1.3
***************
*** 26,32 ****
--- 26,152 ----
  using System.Net;
  using System.Net.Sockets;
+ using System.Threading;
  
  public sealed class Dns
  {
+       // Asynchronous operation types.
+       private enum DnsOperation
+       {
+               Resolve ,
+               GetHostByName
+ 
+       }; // enum DnsOperation
+ 
+       private sealed class DnsAsyncResult : IAsyncResult
+       {
+               // Internal state.
+               private WaitHandle waitHandle;
+               private bool completedSynchronously;
+               private bool completed;
+               private DnsOperation operation;
+               private AsyncCallback callback;
+               private Object state;
+               private IPHostEntry acceptResult;
+               private Exception exception;
+ 
+               // Constructor.
+               public DnsAsyncResult(AsyncCallback callback, Object state,
+                                                               DnsOperation 
operation)
+                               {
+                               #if ECMA_COMPAT
+                                       this.waitHandle = 
SocketMethods.CreateManualResetEvent();
+                               #else
+                                       this.waitHandle = new 
ManualResetEvent(false);
+                               #endif
+                                       this.completedSynchronously = false;
+                                       this.completed = false;
+                                       this.operation = operation;
+                                       this.callback = callback;
+                                       this.state = state;
+                                       this.acceptResult = null;
+                                       this.exception = null;
+                               }
+ 
+               // Run the operation thread.
+               public void BeginInvoke(String hostName)
+                               {
+                                       try
+                                       {
+                                               switch(operation)
+                                               {
+                                                       case 
DnsOperation.GetHostByName:
+                                                       {
+                                                               acceptResult = 
Dns.GetHostByName(hostName);
+                                                       }
+                                                       break;
+ 
+                                                       case 
DnsOperation.Resolve:
+                                                       {
+                                                               acceptResult = 
Dns.Resolve(hostName);
+                                                       }
+                                                       break;
+                                               }
+                                       }
+                                       catch(Exception e)
+                                       {
+                                               // Save the exception to be 
thrown in EndXXX.
+                                               exception = e;
+                                       }
+                                       completed = true;
+                                       if(callback != null)
+                                       {
+                                               callback(this);
+                                       }
+                               #if ECMA_COMPAT
+                                       SocketMethods.WaitHandleSet(waitHandle);
+                               #else
+                                       ((ManualResetEvent)waitHandle).Set();
+                               #endif
+                               }
+ 
+               public IPHostEntry EndInvoke()
+                               {
+                                       if(exception != null)
+                                       {
+                                               throw exception;
+                                       }
+                                       if(completed)
+                                       {
+                                               return acceptResult;
+                                       }
+                                       throw new NotImplementedException(
+                                                               "TODO: Threaded 
Asynchronous Operations");
+                               }
+ 
+               // Implement the IAsyncResult interface.
+               public Object AsyncState
+                               {
+                                       get
+                                       {
+                                               return state;
+                                       }
+                               }
+               public WaitHandle AsyncWaitHandle
+                               {
+                                       get
+                                       {
+                                               return waitHandle;
+                                       }
+                               }
+               public bool CompletedSynchronously
+                               {
+                                       get
+                                       {
+                                               return completedSynchronously;
+                                       }
+                               }
+               public bool IsCompleted
+                               {
+                                       get
+                                       {
+                                               return completed;
+                                       }
+                               }
+       }; // class DnsAsyncResult
  
        // Begin an asynchronous "get host by name" operation.
***************
*** 37,41 ****
                        {
                                // TODO
!                               return null;
                        }
  
--- 157,164 ----
                        {
                                // TODO
!                               DnsAsyncResult result=new 
DnsAsyncResult(requestedCallback,
!                                                                       
stateObject,DnsOperation.GetHostByName);
!                               result.BeginInvoke(hostName);
!                               return (IAsyncResult) (result);                 
        
                        }
  
***************
*** 47,51 ****
                        {
                                // TODO
!                               return null;
                        }
  
--- 170,177 ----
                        {
                                // TODO
!                               DnsAsyncResult result=new 
DnsAsyncResult(requestedCallback,
!                                                                       
stateObject,DnsOperation.Resolve);
!                               result.BeginInvoke(hostName);
!                               return (IAsyncResult) (result);                 
        
                        }
  
***************
*** 55,59 ****
                        {
                                // TODO
!                               return null;
                        }
  
--- 181,185 ----
                        {
                                // TODO
!                               return 
((DnsAsyncResult)(asyncResult)).EndInvoke();
                        }
  
***************
*** 63,67 ****
                        {
                                // TODO
!                               return null;
                        }
  
--- 189,193 ----
                        {
                                // TODO
!                               return 
((DnsAsyncResult)(asyncResult)).EndInvoke();
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]