Beispiel #1
0
            protected void HandleWrites(SocketState ss)
            {
                ArrayList socks = ss.WriteSocks;

                for (int i = 0; i < socks.Count; i++)
                {
                    Socket        s  = (Socket)socks[i];
                    CreationState cs = ss.TakeCreationState(s);
                    if (cs != null)
                    {
                        cs.HandleWritability(s);
                    }
                    else
                    {
                        //Let's try to flush the buffer:
                        try {
                            ss.FlushSocket(s);
                        }
                        catch {
                            /*
                             * We should close this edge
                             */
                            TcpEdge tcpe = ss.GetEdge(s);
                            TEL.RequestClose(tcpe);
                            //Go ahead and forget about this socket.
                            CloseAction ca = new CloseAction(tcpe, null);
                            ca.Start(ss);
                        }
                    }
                }
            }
Beispiel #2
0
            /**
             * Implements the SocketStateAction interface.  This is called to trigger the ECB
             * in the SelectThread so we don't have to worry about multiple threads
             * accessing variables.
             */
            public override void Start(SocketState ss)
            {
                object result = Result.Value;

                if (result != null)
                {
                    TcpEdge new_edge = result as TcpEdge;
                    if (new_edge != null)
                    {
                        //Tell the world about the new Edge:
                        ss.AddEdge(new_edge);
                        ECB(true, new_edge, null);
                    }
                    else
                    {
                        ECB(false, null, (Exception)result);
                    }
                }
                else
                {
                    //Try to make a new start:
                    if (IPAddressQueue.Count <= 0)
                    {
                        ECB(false, null, new EdgeException("No more IP Addresses"));
                    }
                    else
                    {
                        Socket s = null;
                        try {
                            s = new Socket(AddressFamily.InterNetwork,
                                           SocketType.Stream,
                                           ProtocolType.Tcp);
                            s.Blocking = false;
                            ss.AddCreationState(s, this);
                            IPAddress  ipaddr = (IPAddress)IPAddressQueue.Dequeue();
                            IPEndPoint end    = new IPEndPoint(ipaddr, Port);
                            //This is a hack because of a bug in MS.Net and Mono:
                            //https://bugzilla.novell.com/show_bug.cgi?id=349449
                            //http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=332142
                            s.Bind(new IPEndPoint(IPAddress.Any, 0));
                            s.Connect(end);
                        }
                        catch (SocketException sx) {
                            if (sx.SocketErrorCode != SocketError.WouldBlock)
                            {
                                if (s != null)
                                {
                                    ss.TakeCreationState(s);
                                }
                                ECB(false, null, new EdgeException(false, "Could not Connect", sx));
                            }
                            /* else Ignore the non-blocking socket error */
                        }
                    }
                }
            }
Beispiel #3
0
            protected void HandleErrors(SocketState ss)
            {
                ArrayList socks = ss.ErrorSocks;

                for (int i = 0; i < socks.Count; i++)
                {
                    Socket        s  = (Socket)socks[i];
                    CreationState cs = ss.TakeCreationState(s);
                    if (cs != null)
                    {
                        cs.HandleError(s);
                    }
                }
            }
Beispiel #4
0
 protected void HandleWrites(SocketState ss) {
   ArrayList socks = ss.WriteSocks;
   for(int i = 0; i < socks.Count; i++) {
     Socket s = (Socket)socks[i];
     CreationState cs = ss.TakeCreationState( s );
     if( cs != null ) {
       cs.HandleWritability(s);
     }
     else {
       //Let's try to flush the buffer:
       try {
         ss.FlushSocket(s);
       }
       catch {
         /*
          * We should close this edge
          */
         TcpEdge tcpe = ss.GetEdge(s);
         TEL.RequestClose(tcpe);
         //Go ahead and forget about this socket.
         CloseAction ca = new CloseAction(tcpe, null);
         ca.Start(ss);
       }
     }
   }
 }
Beispiel #5
0
 protected void HandleErrors(SocketState ss) {
   ArrayList socks = ss.ErrorSocks;
   for(int i = 0; i < socks.Count; i++) {
     Socket s = (Socket)socks[i];
     CreationState cs = ss.TakeCreationState( s );
     if( cs != null ) {
       cs.HandleError(s);
     }
   }
 }
Beispiel #6
0
 /**
  * Implements the SocketStateAction interface.  This is called to trigger the ECB
  * in the SelectThread so we don't have to worry about multiple threads
  * accessing variables.
  */
 public override void Start(SocketState ss) {
   object result = Result.Value;
   if( result != null ) {
     TcpEdge new_edge = result as TcpEdge;
     if( new_edge != null ) {
       //Tell the world about the new Edge:
       ss.AddEdge(new_edge);
       ECB(true, new_edge, null); 
     }
     else {
       ECB(false, null, (Exception)result); 
     }
   }
   else {
     //Try to make a new start:
     if( IPAddressQueue.Count <= 0 ) {
       ECB(false, null, new EdgeException("No more IP Addresses"));
     }
     else {
       Socket s = null;
       try {
         s = new Socket(AddressFamily.InterNetwork,
                              SocketType.Stream,
                              ProtocolType.Tcp);
         s.Blocking = false;
         ss.AddCreationState(s, this);
         IPAddress ipaddr = (IPAddress)IPAddressQueue.Dequeue();
         IPEndPoint end = new IPEndPoint(ipaddr, Port);
         //This is a hack because of a bug in MS.Net and Mono:
         //https://bugzilla.novell.com/show_bug.cgi?id=349449
         //http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=332142
         s.Bind(new IPEndPoint(IPAddress.Any, 0));
         s.Connect(end);
       }
       catch(SocketException sx) {
         if( sx.SocketErrorCode != SocketError.WouldBlock ) {
           if( s != null ) {
             ss.TakeCreationState(s);
           }
           ECB(false, null, new EdgeException(false, "Could not Connect", sx)); 
         }
         /* else Ignore the non-blocking socket error */
       }
     }
   }
 }