Пример #1
0
        private void IncomingConnectionsTick()
        {
            TcpSocket incomingConnection = this._serverSocket.GetLastIncomingConnection();

            if (incomingConnection == null)
            {
                return;
            }
            ServersideSession serversideSession = this.OnNewConnection();

            ++this._lastUniqueClientId;
            serversideSession.InitializeSocket(this._lastUniqueClientId, incomingConnection);
            this._peers[this._lastUniqueClientId % this._readWriteThreadCount].TryAdd(this._lastUniqueClientId, serversideSession);
        }
Пример #2
0
 public void Activate(
     ushort port,
     ServersideSessionManager.ThreadType threadType = ServersideSessionManager.ThreadType.Single,
     int readWriteThreadCount = 1)
 {
     this._threadType           = threadType;
     this._readWriteThreadCount = readWriteThreadCount;
     this._listenPort           = port;
     this._serverSocket         = new TcpSocket();
     this._serverSocket.Listen((int)this._listenPort);
     if (this._threadType == ServersideSessionManager.ThreadType.Single)
     {
         this._peers.Add(new ConcurrentDictionary <int, ServersideSession>(this._readWriteThreadCount * 3, 8192));
         this._incomingMessages.Add(new ConcurrentQueue <IncomingServerSessionMessage>());
         this._disconnectedPeers.Add(new ConcurrentDictionary <int, ServersideSession>());
         this._readWriteThreadCount      = 1;
         this._serverThread              = new Thread(new ThreadStart(this.ProcessSingle));
         this._serverThread.IsBackground = true;
         this._serverThread.Name         = this.ToString() + " - Server Thread";
         this._serverThread.Start();
     }
     else
     {
         for (int index = 0; index < this._readWriteThreadCount; ++index)
         {
             this._peers.Add(new ConcurrentDictionary <int, ServersideSession>(this._readWriteThreadCount * 4, 8192));
             this._incomingMessages.Add(new ConcurrentQueue <IncomingServerSessionMessage>());
             this._disconnectedPeers.Add(new ConcurrentDictionary <int, ServersideSession>());
         }
         for (int index = 0; index < this._readWriteThreadCount; ++index)
         {
             if (this._threadType == ServersideSessionManager.ThreadType.MultipleSeperateIOAndListener)
             {
                 Thread thread1 = new Thread(new ParameterizedThreadStart(this.ProcessRead))
                 {
                     IsBackground = true,
                     Name         = this.ToString() + " - Server Reader Thread - " + (object)index
                 };
                 thread1.IsBackground = true;
                 thread1.Start((object)index);
                 Thread thread2 = new Thread(new ParameterizedThreadStart(this.ProcessWriter))
                 {
                     IsBackground = true,
                     Name         = this.ToString() + " - Server Writer Thread" + (object)index
                 };
                 thread2.IsBackground = true;
                 thread2.Start((object)index);
                 this._readerThreads.Add(thread1);
                 this._writerThreads.Add(thread2);
             }
             else
             {
                 Thread thread = new Thread(new ParameterizedThreadStart(this.ProcessReaderWriter));
                 thread.Name         = this.ToString() + " - Server ReaderWriter Thread - " + (object)index;
                 thread.IsBackground = true;
                 thread.Start((object)index);
                 this._singleThreads.Add(thread);
             }
         }
         this._serverThread = new Thread(new ThreadStart(this.ProcessListener));
         this._serverThread.IsBackground = true;
         this._serverThread.Name         = this.ToString() + " - Server Listener Thread";
         this._serverThread.Start();
     }
 }