/// <summary>
        /// Initializes a new instance of the <see cref="BaseSocketConnection"/> class.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="creator">The creator.</param>
        /// <param name="socket">The socket.</param>
        protected BaseSocketConnection(BaseSocketConnectionHost host, BaseSocketConnectionCreator creator, System.Net.Sockets.Socket socket)
        {
            //----- Connection Id!
            FId = host.GetConnectionId();

            FSyncData   = new object();
            FReadBytes  = 0;
            FWriteBytes = 0;

            FHost    = host;
            FCreator = creator;
            FSocket  = socket;

            FSyncActive = new Object();
            FActive     = false;

            FWriteOV = new SocketAsyncEventArgs();
            FReadOV  = new SocketAsyncEventArgs();

            FWriteQueue         = new Queue <MessageBuffer>();
            FWriteQueueHasItems = false;

            FSyncReadPending = new object();
            FReadPending     = false;

            FSyncEventProcessing = new object();
            FEventProcessing     = EventProcessing.epNone;

            FLastAction = new DateTimeOffset(DateTime.Now);

            FUserData  = null;
            FEncryptor = null;
            FDecryptor = null;
        }
 protected void AddCreator(BaseSocketConnectionCreator creator)
 {
     if (!Disposed)
     {
         lock (FSocketCreators)
         {
             FSocketCreators.Add(creator);
         }
     }
 }
        protected BaseSocketConnectionCreator[] GetSocketCreators()
        {
            BaseSocketConnectionCreator[] items = null;

            if (!Disposed)
            {
                lock (FSocketCreators)
                {
                    items = new BaseSocketConnectionCreator[FSocketCreators.Count];
                    FSocketCreators.CopyTo(items, 0);
                }
            }

            return(items);
        }
        protected void RemoveCreator(BaseSocketConnectionCreator creator)
        {
            if (!Disposed)
            {
                lock (FSocketCreators)
                {
                    FSocketCreators.Remove(creator);

                    if (FSocketCreators.Count <= 0)
                    {
                        FWaitCreatorsDisposing.Set();
                    }
                }
            }
        }
Пример #5
0
        protected override void Free(bool canAccessFinalizable)
        {
            if (FWriteQueue != null)
            {
                FWriteQueue.Clear();
                FWriteQueue = null;
            }

            if (FStream != null)
            {
                FStream.Close();
                FStream = null;
            }

            if (FSocket != null)
            {
                FSocket.Close();
                FSocket = null;
            }

            if (FDecryptor != null)
            {
                FDecryptor.Dispose();
                FDecryptor = null;
            }

            if (FEncryptor != null)
            {
                FEncryptor.Dispose();
                FEncryptor = null;
            }

            FHost          = null;
            FCreator       = null;
            FSyncReadCount = null;
            FSyncActive    = null;

            base.Free(canAccessFinalizable);
        }
Пример #6
0
        internal BaseSocketConnection(BaseSocketConnectionHost host, BaseSocketConnectionCreator creator, Socket socket)
        {
            //----- Connection Id!
            FId         = host.GetConnectionId();
            FHost       = host;
            FCreator    = creator;
            FSocket     = socket;
            FActive     = false;
            FSyncActive = new Object();

            FWriteQueue = new Queue <MessageBuffer>();

            FWriteQueueHasItems = false;
            FReadCanEnqueue     = true;

            FReadCount     = 0;
            FSyncReadCount = new object();

            FLastAction = DateTime.Now;

            FCustomData = null;
            FEncryptor  = null;
            FDecryptor  = null;
        }
Пример #7
0
 internal ServerSocketConnection(BaseSocketConnectionHost host, BaseSocketConnectionCreator creator, Socket socket)
   : base(host, creator, socket)
 {
     //-----
 }
Пример #8
0
        internal BaseSocketConnection(BaseSocketConnectionHost host, BaseSocketConnectionCreator creator, Socket socket)
        {

            //----- Connection Id!
            FId = host.GetConnectionId();
            FHost = host;
            FCreator = creator;
            FSocket = socket;
            FActive = false;
            FSyncActive = new Object();

            FWriteQueue = new Queue<MessageBuffer>();

            FWriteQueueHasItems = false;
            FReadCanEnqueue = true;

            FReadCount = 0;
            FSyncReadCount = new object();

            FLastAction = DateTime.Now;

            FCustomData = null;
            FEncryptor = null;
            FDecryptor = null;

        }
Пример #9
0
        protected override void Free(bool canAccessFinalizable)
        {

            if (FWriteQueue != null)
            {
                FWriteQueue.Clear();
                FWriteQueue = null;
            }

            if (FStream != null)
            {
                FStream.Close();
                FStream = null;
            }

            if (FSocket != null)
            {
                FSocket.Close();
                FSocket = null;
            }

            if (FDecryptor != null)
            {
                FDecryptor.Dispose();
                FDecryptor = null;
            }

            if (FEncryptor != null)
            {
                FEncryptor.Dispose();
                FEncryptor = null;
            }

            FHost = null;
            FCreator = null;
            FSyncReadCount = null;
            FSyncActive = null;

            base.Free(canAccessFinalizable);

        }
Пример #10
0
 internal ClientSocketConnection(BaseSocketConnectionHost host, BaseSocketConnectionCreator creator, System.Net.Sockets.Socket socket)
     : base(host, creator, socket)
 {
 }
        protected override void Free(bool canAccessFinalizable)
        {
            if (FWriteQueue != null)
            {
                FWriteQueue.Clear();
                FWriteQueue = null;
            }

            if (FStream != null)
            {
                FStream.Close();
                FStream = null;
            }

            if (FDecryptor != null)
            {
                FDecryptor.Dispose();
                FDecryptor = null;
            }

            if (FEncryptor != null)
            {
                FEncryptor.Dispose();
                FEncryptor = null;
            }

            if (FReadOV != null)
            {
                Type t = typeof(SocketAsyncEventArgs);

                FieldInfo f = t.GetField("m_Completed", BindingFlags.Instance | BindingFlags.NonPublic);
                f.SetValue(FReadOV, null);

                FReadOV.SetBuffer(null, 0, 0);
                FReadOV.Dispose();
                FReadOV = null;
            }

            if (FWriteOV != null)
            {
                Type t = typeof(SocketAsyncEventArgs);

                FieldInfo f = t.GetField("m_Completed", BindingFlags.Instance | BindingFlags.NonPublic);
                f.SetValue(FWriteOV, null);

                FWriteOV.SetBuffer(null, 0, 0);
                FWriteOV.Dispose();
                FWriteOV = null;
            }

            if (FSocket != null)
            {
                FSocket.Close();
                FSocket = null;
            }

            FHost                = null;
            FCreator             = null;
            FSyncReadPending     = null;
            FSyncData            = null;
            FSyncEventProcessing = null;

            base.Free(canAccessFinalizable);
        }
Пример #12
0
        internal ClientSocketConnection(BaseSocketConnectionHost host, BaseSocketConnectionCreator creator, Socket socket)
          : base(host, creator, socket)
        {

        }
        protected BaseSocketConnectionCreator[] GetSocketCreators()
        {

            BaseSocketConnectionCreator[] items = null;

            if (!Disposed)
            {
                lock (FSocketCreators)
                {
                    items = new BaseSocketConnectionCreator[FSocketCreators.Count];
                    FSocketCreators.CopyTo(items, 0);
                }

            }

            return items;

        }
        protected void RemoveCreator(BaseSocketConnectionCreator creator)
        {
            if (!Disposed)
            {
                lock (FSocketCreators)
                {
                    FSocketCreators.Remove(creator);

                    if (FSocketCreators.Count <= 0)
                    {
                        FWaitCreatorsDisposing.Set();
                    }

                }
            }
        }
        protected void AddCreator(BaseSocketConnectionCreator creator)
        {

            if (!Disposed)
            {
                lock (FSocketCreators)
                {
                    FSocketCreators.Add(creator);
                }

            }

        }
 internal ServerSocketConnection(BaseSocketConnectionHost host, BaseSocketConnectionCreator creator, System.Net.Sockets.Socket socket)
     : base(host, creator, socket)
 {
     //-----
 }