Esempio n. 1
0
 /// <summary>
 /// Class managing the reception of an in-band bytestream.
 /// </summary>
 /// <param name="DataCallback">Method called when binary data has been received.</param>
 /// <param name="CloseCallback">Method called when stream has been closed.</param>
 /// <param name="State">State object</param>
 /// <param name="BlockSize">Block size.</param>
 public IncomingStream(DataReceivedEventHandler DataCallback, StreamClosedEventHandler CloseCallback, object State, int BlockSize)
 {
     this.dataCallback  = DataCallback;
     this.closeCallback = CloseCallback;
     this.state         = State;
     this.blockSize     = BlockSize;
 }
        /// <summary>
        /// Call this method to accept the incoming stream.
        /// </summary>
        /// <param name="DataCallback">Method called when data has been received.</param>
        /// <param name="CloseCallback">Method called when stream has been closed.</param>
        /// <param name="State">State object to pass on to the callback method.</param>
        /// <returns>If the stream acceptance was completed (true), or if somebody else accepted the stream beforehand (false).</returns>
        public bool AcceptStream(DataReceivedEventHandler DataCallback, StreamClosedEventHandler CloseCallback, object State)
        {
            if (this.dataCallback is null)
            {
                this.dataCallback  = DataCallback;
                this.closeCallback = CloseCallback;
                this.state         = State;

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
 internal void Closed(CloseReason Reason)
 {
     if (this.closeCallback != null)
     {
         try
         {
             this.closeCallback(this, new StreamClosedEventArgs(Reason, this.state));
         }
         catch (Exception ex)
         {
             Log.Critical(ex);
         }
         finally
         {
             this.closeCallback = null;
             this.dataCallback  = null;
         }
     }
 }