Handle() публичный Метод

This is called to pass data to the subscribed handler.
public Handle ( MemBlock b, ISender retpath ) : void
b Brunet.Util.MemBlock The data being passed.
retpath ISender A sender which can send data back to the source of B.
Результат void
Пример #1
0
        public virtual void Handle(MemBlock b, ISender retpath)
        {
            Subscriber sub = _sub;

            if (sub != null)
            {
                sub.Handle(b, retpath);
            }
        }
Пример #2
0
    /**
    <summary>The _listen_threads method, reads from sockets and let's the node
    handle the incoming data.</summary>
    */
    protected void Listen() {
      if (Thread.CurrentThread.Name == null) {
        Thread.CurrentThread.Name = "iphandler_thread";
      }
      ArrayList sockets = new ArrayList();
      sockets.Add(_uc);
      if(_mc != null) {
        sockets.Add(_mc);
      }

      byte[] buffer =  new byte[Int16.MaxValue];
      DateTime last_debug = DateTime.UtcNow;
      TimeSpan debug_period = TimeSpan.FromSeconds(5);
      while(1 == _running) {
        if (ProtocolLog.Monitor.Enabled) {
          DateTime now = DateTime.UtcNow;
          if (now - last_debug > debug_period) {
            last_debug = now;
            ProtocolLog.Write(ProtocolLog.Monitor, String.Format("I am alive: {0}", now));
          }
        }
        try {
          ArrayList readers = (ArrayList) sockets.Clone();
          Socket.Select(readers, null, null, 10000000); //10 seconds
          foreach(Socket socket in readers) {
            EndPoint ep = new IPEndPoint(IPAddress.Any, 0);
            int rec_bytes = socket.ReceiveFrom(buffer, ref ep);
            Subscriber s = _sub;
            //s can't change once we've read it.
            if( s != null && rec_bytes > 0) {
              MemBlock packet = MemBlock.Copy(buffer, 0, rec_bytes);
              MemBlock cookie = packet.Slice(0, 4);
              if(cookie.Equals(MagicCookie)) {
                packet = packet.Slice(4);
                ISender sender = CreateUnicastSender(ep);
                s.Handle(packet, sender);
              }
            }
          }
        }
        catch(ObjectDisposedException odx) {
          //If we are no longer running, this is to be expected.
          if(1 == _running) {
          //If we are running print it out
            ProtocolLog.WriteIf(ProtocolLog.Exceptions, odx.ToString());
          }
          break;
        }
        catch(Exception x) {
          if(0 == _running) {
            ProtocolLog.WriteIf(ProtocolLog.Exceptions, x.ToString());
          }
        }
      }
    }
Пример #3
0
        /**
         * <summary>Calls Handle on all IDataHandlers subscribed.</summary>
         * <param name="b">The data being passed.</param>
         * <param name="retpath">A sender which can send data back to the source of B.
         * <returns> the number of Handlers that saw this data.</returns>
         */
        public int Announce(MemBlock b, ISender return_path)
        {
            ArrayList subs     = _subs;
            int       handlers = subs.Count;

            for (int i = 0; i < handlers; i++)
            {
                Subscriber s = (Subscriber)subs[i];
                //No need to lock since subs can never change
                s.Handle(b, return_path);
            }
            return(handlers);
        }