Пример #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);
                        }
                    }
                }
            }
Пример #2
0
            /*
             * Update the SocketState.TAA and check to see if any Edges need
             * to be closed.
             */
            public override void Start(SocketState ss)
            {
                ss.TAA = TAA;
                ArrayList bad_edges = new ArrayList();

                foreach (Socket s in ss.AllSockets)
                {
                    TcpEdge e = ss.GetEdge(s);
                    if (e != null)
                    {
                        if (TAA.Authorize(e.RemoteTA) == TAAuthorizer.Decision.Deny)
                        {
                            //We can't close now, that would invalidate the AllSockets
                            //iterator
                            bad_edges.Add(e);
                        }
                    }
                }
                foreach (TcpEdge e in bad_edges)
                {
                    EL.RequestClose(e);
                    CloseAction ca = new CloseAction(e, null);
                    ca.Start(ss);
                }
            }
Пример #3
0
            protected void HandleReads(SocketState ss)
            {
                ArrayList readsocks   = ss.ReadSocks;
                Socket    listen_sock = ss.ListenSock;

                for (int i = 0; i < readsocks.Count; i++)
                {
                    Socket s = (Socket)readsocks[i];
                    //See if this is a new socket
                    if (s == listen_sock)
                    {
                        TcpEdge e     = null;
                        Socket  new_s = null;
                        try {
                            new_s = listen_sock.Accept();
                            IPEndPoint rep = (IPEndPoint)new_s.RemoteEndPoint;
                            new_s.LingerState = new LingerOption(true, 0);
                            TransportAddress rta =
                                TransportAddressFactory.CreateInstance(TransportAddress.TAType.Tcp, rep);
                            if (ss.TAA.Authorize(rta) == TAAuthorizer.Decision.Deny)
                            {
                                //No thank you Dr. Evil
                                Console.Error.WriteLine("Denying: {0}", rta);
                                new_s.Close();
                            }
                            else
                            {
                                //This edge looks clean
                                TcpEdgeListener.SetSocketOpts(s);
                                e = new TcpEdge(TEL, true, new_s);
                                ss.AddEdge(e);
                                //Handle closes in the select thread:
                                CloseAction ca = new CloseAction(e, TEL.ActionQueue);
                                e.CloseEvent += ca.CloseHandler;
                                TEL.SendEdgeEvent(e);
                            }
                        }
                        catch (Exception) {
                            //Looks like this Accept has failed.  Do nothing
                            //Console.Error.WriteLine("New incoming edge ({0}) failed: {1}", new_s, sx);
                            //Make sure the edge is closed
                            if (e != null)
                            {
                                TEL.RequestClose(e);
                                //Go ahead and forget about this socket.
                                CloseAction ca = new CloseAction(e, null);
                                ca.Start(ss);
                            }
                            else if (new_s != null)
                            {
                                //This should not be able to throw an exception:
                                new_s.Close();
                            }
                        }
                    }
                    else
                    {
                        ReceiveState rs = ss.GetReceiveState(s);
                        if (rs != null && !rs.Receive())
                        {
                            TEL.RequestClose(rs.Edge);
                            //Go ahead and forget about this socket.
                            CloseAction ca = new CloseAction(rs.Edge, null);
                            ca.Start(ss);
                        }
                    }
                }
            }
Пример #4
0
 protected void HandleReads(SocketState ss) {
   ArrayList readsocks = ss.ReadSocks;
   Socket listen_sock = ss.ListenSock;
   for(int i = 0; i < readsocks.Count; i++) {
     Socket s = (Socket)readsocks[i];
     //See if this is a new socket
     if( s == listen_sock ) {
       TcpEdge e = null;
       Socket new_s = null;
       try {
         new_s = listen_sock.Accept();
         IPEndPoint rep = (IPEndPoint)new_s.RemoteEndPoint;
         new_s.LingerState = new LingerOption (true, 0);
         TransportAddress rta =
                  TransportAddressFactory.CreateInstance(TransportAddress.TAType.Tcp, rep);
         if( ss.TAA.Authorize(rta) == TAAuthorizer.Decision.Deny ) {
           //No thank you Dr. Evil
           Console.Error.WriteLine("Denying: {0}", rta);
           new_s.Close();
         }
         else {
           //This edge looks clean
           TcpEdgeListener.SetSocketOpts(s);
           e = new TcpEdge(TEL, true, new_s);
           ss.AddEdge(e);
           //Handle closes in the select thread:
           CloseAction ca = new CloseAction(e, TEL.ActionQueue);
           e.CloseEvent += ca.CloseHandler;
           TEL.SendEdgeEvent(e);
         }
       }
       catch(Exception) {
         //Looks like this Accept has failed.  Do nothing
         //Console.Error.WriteLine("New incoming edge ({0}) failed: {1}", new_s, sx);
         //Make sure the edge is closed
         if( e != null ) {
           TEL.RequestClose(e);
           //Go ahead and forget about this socket.
           CloseAction ca = new CloseAction(e, null);
           ca.Start(ss);
         }
         else if( new_s != null) {
           //This should not be able to throw an exception:
           new_s.Close();
         }
       }
     }
     else {
       ReceiveState rs = ss.GetReceiveState(s);
       if( rs != null && !rs.Receive() ) {
         TEL.RequestClose(rs.Edge);
         //Go ahead and forget about this socket.
         CloseAction ca = new CloseAction(rs.Edge, null);
         ca.Start(ss);
       }
     }
   }
 }
Пример #5
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);
       }
     }
   }
 }
Пример #6
0
 /*
  * Update the SocketState.TAA and check to see if any Edges need
  * to be closed.
  */
 public override void Start(SocketState ss) {
   ss.TAA = TAA;
   ArrayList bad_edges = new ArrayList();
   foreach(Socket s in ss.AllSockets) {
     TcpEdge e = ss.GetEdge(s);
     if( e != null ) {
       if( TAA.Authorize( e.RemoteTA ) == TAAuthorizer.Decision.Deny ) {
         //We can't close now, that would invalidate the AllSockets
         //iterator
         bad_edges.Add(e);
       }
     }
   }
   foreach(TcpEdge e in bad_edges) {
     EL.RequestClose(e);
     CloseAction ca = new CloseAction(e, null);
     ca.Start(ss);
   }
 }