Close() public method

public Close ( ) : bool
return bool
コード例 #1
0
ファイル: WrapperEdge.cs プロジェクト: ikaragkiozoglou/brunet
 public override bool Close()
 {
     if (!base.Close())
     {
         return(false);
     }
     _edge.Close();
     return(true);
 }
コード例 #2
0
        protected void RequestClose(Edge e)
        {
            EventHandler eh = EdgeCloseRequestEvent;

            if (eh == null)
            {
                //We have to close the edge:
                e.Close();
            }
            else
            {
                try {
                    eh(this, new EdgeCloseRequestArgs(e));
                }
                catch (Exception x) {
                    Console.Error.WriteLine("ERROR: closing: {0} -- {1}", e, x);
                    e.Close();
                }
            }
        }
コード例 #3
0
        public void CreationCallback(bool success, Edge e, Exception x)
        {
            if (!success && _edge != null)
            {
                _edge.Close();
            }
            if (System.Threading.Interlocked.Exchange(ref _called, 1) == 1)
            {
                return;
            }

            ExternalECB(success, e, x);
        }
コード例 #4
0
            public void HandleEC(bool succ, Edge e, Exception x)
            {
                if (!succ)
                {
                    ECB(false, null, x);
                    return;
                }
                else if (_root)
                {
                    Interlocked.Increment(ref _pel._count);
                    e.CloseEvent += _pel.CloseHandler;
                    ECB(succ, e, x);
                    return;
                }

                /*
                 * Got the underlying Edge, now do the path protocol
                 */
                Channel results = new Channel(1);

                results.CloseEvent += delegate(object q, EventArgs args) {
                    try {
                        RpcResult res = (RpcResult)results.Dequeue();
                        object    o   = res.Result;
                        if (o is Exception)
                        {
                            throw (o as Exception);
                        }
                    } catch (Exception cx) {
                        e.Close();
                        ECB(false, null, cx);
                        return;
                    }

                    //If we get here, everything looks good:
                    PathEdge pe = new PathEdge(_pel._pem, e, LocalPath, RemotePath);
                    //Start sending e's packets into pe
                    pe.Subscribe();
                    pe.CloseEvent += _pel.CloseHandler;
                    Interlocked.Increment(ref _pel._count);
                    ECB(true, pe, null);
                };

                //Make sure we hear the packets on this edge:
                e.Subscribe(_pel._pem, null);
                //Now make the rpc call:
                _pel._pem.Rpc.Invoke(e, results, "sys:pathing.create", LocalPath, RemotePath);
            }
コード例 #5
0
        /** Watch this incoming Edge
         */
        protected void HandleEdge(object newedge, System.EventArgs args)
        {
            Edge e = (Edge)newedge;

            try {
                e.CloseEvent += this.HandleEdgeClose;
                e.Subscribe(this, null);
                lock ( _sync ) {
                    _edges.Add(e);
                }
            }
            catch (Exception x) {
                //Didn't work out, make sure the edges is closed
                ProtocolLog.WriteIf(ProtocolLog.Pathing,
                                    String.Format("Closing ({0}) due to: {1}", e, x));
                e.Close();
            }
        }
コード例 #6
0
ファイル: PathEdgeListener.cs プロジェクト: hseom/brunet
      public void HandleEC(bool succ, Edge e, Exception x) {
        if(!succ) {
          ECB(false, null, x);
          return;
        } else if(_root) {
          Interlocked.Increment(ref _pel._count);
          e.CloseEvent += _pel.CloseHandler;
          ECB(succ, e, x);
          return;
        }

        /*
         * Got the underlying Edge, now do the path protocol
         */ 
        Channel results = new Channel(1);
        results.CloseEvent += delegate(object q, EventArgs args) {
          try {
            RpcResult res = (RpcResult)results.Dequeue();
            object o = res.Result;
            if(o is Exception) {
              throw (o as Exception);
            }
          } catch(Exception cx) {
            e.Close();
            ECB(false, null, cx);
            return;
          }

          //If we get here, everything looks good:
          PathEdge pe = new PathEdge(_pel._pem, e, LocalPath, RemotePath);
          //Start sending e's packets into pe
          pe.Subscribe();
          pe.CloseEvent += _pel.CloseHandler;
          Interlocked.Increment(ref _pel._count);
          ECB(true, pe, null);
        };

        //Make sure we hear the packets on this edge:
        e.Subscribe(_pel._pem, null);
        //Now make the rpc call:
        _pel._pem.Rpc.Invoke(e, results, "sys:pathing.create", LocalPath, RemotePath ); 
      }
コード例 #7
0
 public void Start()
 {
     ToClose.Close();
 }
コード例 #8
0
 public override bool Close()
 {
     _e.Close();
     return(base.Close());
 }
コード例 #9
0
        /** Handle incoming data on an Edge
         */
        public void HandleData(MemBlock data, ISender retpath, object state)
        {
            MemBlock rest_of_data;
            PType    p;

            if (state == null)
            {
                try {
                    p = PType.Parse(data, out rest_of_data);
                } catch (ParseException) {
                    ProtocolLog.WriteIf(ProtocolLog.Pathing, "Invalid PType from: " + data);
                    return;
                }
                p = PType.Parse(data, out rest_of_data);
            }
            else
            {
                //a demux has already happened:
                p            = (PType)state;
                rest_of_data = data;
            }

            if (PType.Protocol.Pathing.Equals(p))
            {
                /*
                 * We use a special PType to denote this transaction so
                 * we don't confuse it with other RepRep communication
                 */
                _rrm.HandleData(rest_of_data, retpath, null);
            }
            else if (PType.Protocol.Rpc.Equals(p))
            {
                /*
                 * Send this to the RpcHandler
                 */
                Rpc.HandleData(rest_of_data, retpath, null);
            }
            else
            {
                /*
                 * This is some other data
                 * It is either:
                 * 1) Time to announce an already created edge.
                 * 2) Assume this is a "default path" edge creation, to be backwards
                 * compatible
                 */
                Edge     e  = null;
                PathEdge pe = null;
                try {
                    e = (Edge)retpath;
                    PathEdgeListener pel = null;
                    lock ( _sync ) {
                        if (_unannounced.TryGetValue(e, out pe))
                        {
                            //
                            _unannounced.Remove(e);
                            pel = _pel_map[pe.LocalPath];
                        }
                    }
                    if (pe == null)
                    {
                        if (!_pel_map.ContainsKey(Root))
                        {
                            ProtocolLog.WriteIf(ProtocolLog.Pathing, "No root, can't create edge");
                            if (e != null)
                            {
                                e.Close();
                            }
                            return;
                        }

                        /*
                         * This must be a "default path" incoming connection
                         */
                        pel = _pel_map[Root];
                        pe  = new PathEdge(this, e, Root, Root);
                    }
                    pel.SendPathEdgeEvent(pe);
                    pe.Subscribe();
                    pe.ReceivedPacketEvent(data);
                }
                catch (Exception x) {
                    if (pe != null)
                    {
                        //This closes both edges:
                        pe.Close();
                    }
                    else if (e != null)
                    {
                        ProtocolLog.WriteIf(ProtocolLog.Pathing,
                                            String.Format("Closing ({0}) due to: {1}", e, x));
                        e.Close();
                    }
                }
            }
        }