Represents an asynchronous TCP Connection that is synchronized for all critical operations. None of its methods are blocking. Therefore most actions are not completed when returning from a method but should be handled using the given events of this class. If this Connection is throttled, its Throttle will take care of the buffer size management. In that state it is illegal to change the buffersize of the throttled buffers (send- and/or receive- buffer respectively) since the throttling depends on a correctly adjusted buffersize.
コード例 #1
0
 public void ApplyTo(IrcClient irc)
 {
     if (irc != null)
     {
         // add handler
         con = irc.Client;
         con.BytesReceived += rcvdHandler;
     }
     else
     {
         // remove handler
         con.BytesReceived -= rcvdHandler;
         con = null;
     }
     this.irc = irc;
 }
コード例 #2
0
 public ConnectionTunnel()
 {
     SetupListener();
     server = new Connection();
 }
コード例 #3
0
 private void ResetSendBuffer(Connection con)
 {
     con.SetSendBufferSize(Connection.DefaultSendBufferSize, true);
 }
コード例 #4
0
        /// <summary>
        /// 
        /// </summary>
        public void HandleBytes(Connection con, ByteBuffer buf)
        {
            var packets = ExtractPackets(buf);
            foreach (var packet in packets)
            {
                var handlers = IrcProtocol.Instance[packet.Key];
                if (handlers == null)
                {
                    //if (IrcProtocol.Instance.DefaultPacketHandler == null) {
                    //    throw new NullReferenceException("DefaultPacketHandler has not been set.");
                    //}
                    IrcProtocol.Instance.DefaultPacketHandler(packet);
                }
                else
                {
                    if (handlers.Count == 1)
                    {
                        handlers[0](packet);
                    }
                    else if (handlers.Count > 1)
                    {
                        var pos = packet.Content.Position;
                        for (var i = 0; i < handlers.Count; i++)
                        {
                            var handler = handlers[i];
                            handler(packet);
                            packet.Content.Position = pos;
                        }
                    }
                }

                if (PacketReceived != null)
                {
                    PacketReceived(packet);
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Removes an existent Connection from this throttle or does nothing if the connection
 /// does not belong to this throttle.
 /// </summary>
 public void Remove(Connection con)
 {
     lock (conLock)
     {
         Remove(cons.IndexOf(con));
     }
 }
コード例 #6
0
 private void ResetReceiveBuffer(Connection con)
 {
     con.SetRcvBufferSize(Connection.DefaultReceiveBufferSize, true);
 }
コード例 #7
0
 /// <summary>
 /// Adds a new connection to this throttle.
 /// </summary>
 public void Add(Connection con)
 {
     lock (conLock)
     {
         con.SetThrottle(this);
         cons.Add(con);
     }
     if (Active)
     {
         if (ThrottlesDownload)
             AdjustReceiveBuffer();
         if (ThrottlesUpload)
             AdjustSendBuffer();
     }
 }
コード例 #8
0
 public void Add(Connection con)
 {
     cons.Add(con);
 }
コード例 #9
0
 public ConnectionWriter(Connection con)
     : this()
 {
     Connection = con;
 }
コード例 #10
0
 private void OnInternalSent(Connection con, int amount, bool hasReamining)
 {
     if (writing && !hasReamining)
         ContinueReadStreamData();
 }
コード例 #11
0
 private void OnInternalDisconnected(Connection con, bool conLost)
 {
     if (writing)
         ResetAfterTransfer();
 }