/// <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;
        }
Beispiel #2
0
        protected override void Free(bool canAccessFinalizable)
        {
            FLocalEndPoint = null;
            FCryptoService = null;
            FHost          = null;

            base.Free(canAccessFinalizable);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseSocketConnectionCreator"/> class.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="name">The name.</param>
        /// <param name="localEndPoint">The local end point.</param>
        /// <param name="encryptType">Type of the encrypt.</param>
        /// <param name="compressionType">Type of the compression.</param>
        /// <param name="cryptoService">The crypto service.</param>
        protected BaseSocketConnectionCreator(BaseSocketConnectionHost host, string name, IPEndPoint localEndPoint, EncryptType encryptType, CompressionType compressionType, ICryptoService cryptoService)
        {
            FHost            = host;
            FName            = name;
            FLocalEndPoint   = localEndPoint;
            FCompressionType = compressionType;
            FEncryptType     = encryptType;

            FCryptoService = cryptoService;
        }
        public BaseSocketConnectionCreator(BaseSocketConnectionHost host, string name, IPEndPoint localEndPoint, EncryptType encryptType, CompressionType compressionType, ICryptoService cryptoService)
        {

            FHost = host;
            FName = name;
            FLocalEndPoint = localEndPoint;
            FCompressionType = compressionType;
            FEncryptType = encryptType;

            FCryptoService = cryptoService;

        }
        /// <summary>
        /// Base SocketConnector creator.
        /// </summary>
        /// <param name="host">
        /// Host.
        /// </param>
        /// <param name="remoteEndPoint">
        /// The remote endpoint to connect.
        /// </param>
        /// <param name="encryptType">
        /// Encrypt type.
        /// </param>
        /// <param name="compressionType">
        /// Compression type.
        /// </param>
        /// <param name="cryptoService">
        /// CryptoService. if null, will not be used.
        /// </param>
        /// <param name="localEndPoint">
        /// Local endpoint. if null, will be any address/port.
        /// </param>
        public SocketConnector(BaseSocketConnectionHost host, string name, IPEndPoint remoteEndPoint, ProxyInfo proxyData, EncryptType encryptType, CompressionType compressionType, ICryptoService cryptoService, int reconnectAttempts, int reconnectAttemptInterval, IPEndPoint localEndPoint)
            : base(host, name, localEndPoint, encryptType, compressionType, cryptoService)
        {
            FReconnectTimer = new Timer(new TimerCallback(ReconnectConnectionTimerCallBack));
            FRemoteEndPoint = remoteEndPoint;

            FReconnectAttempts        = reconnectAttempts;
            FReconnectAttemptInterval = reconnectAttemptInterval;

            FReconnectAttempted = 0;

            FProxyInfo = proxyData;
        }
Beispiel #6
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);
        }
Beispiel #7
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;
        }
        protected override void Free(bool canAccessFinalizable)
        {

            FLocalEndPoint = null;
            FCryptoService = null;
            FHost = null;

            base.Free(canAccessFinalizable);

        }
 internal ServerSocketConnection(BaseSocketConnectionHost host, BaseSocketConnectionCreator creator, 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 (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);

        }
Beispiel #11
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);
        }
Beispiel #13
0
        /// <summary>
        /// Base SocketConnector creator.
        /// </summary>
        /// <param name="host">
        /// Host.
        /// </param>
        /// <param name="remoteEndPoint">
        /// The remote endpoint to connect.
        /// </param>
        /// <param name="encryptType">
        /// Encrypt type.
        /// </param>
        /// <param name="compressionType">
        /// Compression type.
        /// </param>
        /// <param name="cryptoService">
        /// CryptoService. if null, will not be used.
        /// </param>
        /// <param name="localEndPoint">
        /// Local endpoint. if null, will be any address/port.
        /// </param>
        public SocketConnector(BaseSocketConnectionHost host, string name, IPEndPoint remoteEndPoint, ProxyInfo proxyData, EncryptType encryptType, CompressionType compressionType, ICryptoService cryptoService, int reconnectAttempts, int reconnectAttemptInterval, IPEndPoint localEndPoint)
            : base(host, name, localEndPoint, encryptType, compressionType, cryptoService)
        {

            FReconnectTimer = new Timer(new TimerCallback(ReconnectSocketConnection));
            FRemoteEndPoint = remoteEndPoint;

            FReconnectAttempts = reconnectAttempts;
            FReconnectAttemptInterval = reconnectAttemptInterval;

            FReconnectAttempted = -1;

            FProxyInfo = proxyData;

        }
        internal ClientSocketConnection(BaseSocketConnectionHost host, BaseSocketConnectionCreator creator, Socket socket)
          : base(host, creator, socket)
        {

        }
Beispiel #15
0
 /// <summary>
 /// Base SocketListener creator.
 /// </summary>
 /// <param name="host">
 /// Host.
 /// </param>
 /// <param name="localEndPoint">
 /// Local endpoint to be used.
 /// </param>
 /// <param name="encryptType">
 /// Encryption to be used.
 /// </param>
 /// <param name="compressionType">
 /// Compression to be used.
 /// </param>
 /// <param name="cryptoService">
 /// CryptoService. if null, will not be used.
 /// </param>
 /// <param name="backLog">
 /// Socket backlog queue number.
 /// </param>
 /// <param name="acceptThreads">
 /// Number of accept events to be used.
 /// </param>
 public SocketListener(BaseSocketConnectionHost host, string name, IPEndPoint localEndPoint, EncryptType encryptType, CompressionType compressionType, ICryptoService cryptoService, byte backLog, byte acceptThreads)
     : base(host, name, localEndPoint, encryptType, compressionType, cryptoService)
 {
     FBackLog       = backLog;
     FAcceptThreads = acceptThreads;
 }
        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;

        }
Beispiel #17
0
        /// <summary>
        /// Base SocketListener creator.
        /// </summary>
        /// <param name="host">
        /// Host.
        /// </param>
        /// <param name="localEndPoint">
        /// Local endpoint to be used.
        /// </param>
        /// <param name="encryptType">
        /// Encryption to be used.
        /// </param>
        /// <param name="compressionType">
        /// Compression to be used.
        /// </param>
        /// <param name="cryptoService">
        /// CryptoService. if null, will not be used.
        /// </param>
        /// <param name="backLog">
        /// Socket backlog queue number.
        /// </param>
        /// <param name="acceptThreads">
        /// Number of accept events to be used.
        /// </param>
        public SocketListener(BaseSocketConnectionHost host, string name, IPEndPoint localEndPoint, EncryptType encryptType, CompressionType compressionType, ICryptoService cryptoService, byte backLog, byte acceptThreads)
            : base(host, name, localEndPoint, encryptType, compressionType, cryptoService)
        {

            FBackLog = backLog;
            FAcceptThreads = acceptThreads;

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