Exemple #1
0
 private void ListenThread()
 {
     while (true)
     {
         Socket newSocket;
         try { newSocket = Base.Accept(); }
         catch (SocketException) { return; }
         catch (ObjectDisposedException) { return; }
         TcpSocket socket = new TcpSocket(newSocket, this);
     }
 }
Exemple #2
0
 public IOThread EnqueueNew(TcpSocket socket)
 {
     if (socket.Ended)
     {
         gotFirstSocket = true;
         return(this);
     }
     socket.IOHandler     = this;
     socket.Base.NoDelay  = true;
     socket.Base.Blocking = false;
     QueuedNew.Enqueue(socket);
     return(this);
 }
Exemple #3
0
 public IOThread EnqueueClose(TcpSocket socket)
 {
     lock (closeLock)
     {
         if (socket.IsClosing)
         {
             return(this);
         }
         socket.IsClosing = true;
         QueuedClose.Enqueue(socket);
     }
     return(this);
 }
Exemple #4
0
 public IOThread EnqueueTerminate(TcpSocket socket)
 {
     lock (terminateLock)
     {
         if (socket.IsTerminating)
         {
             return(this);
         }
         socket.IsTerminating = true;
         QueuedTerminate.Enqueue(socket);
     }
     return(this);
 }
Exemple #5
0
        public static IOThread Enqueue(TcpSocket socket)
        {
            IOThread best = null;

            lock (_threadModifyLock)
            {
                for (int i = 0; i < _threads.Count; i++)
                {
                    IOThread curr = _threads[i];
                    if (best == null || best.SocketCount > curr.SocketCount)
                    {
                        best = curr;
                    }
                }
                if (best == null || best.SocketCount > THREAD_MAX_SOCKETS)
                {
                    IOThread empty = new IOThread();
                    _threads.Add(empty);
                    best = empty;
                }
            }
            return(best.EnqueueNew(socket));
        }
Exemple #6
0
 internal void FireConnection(TcpSocket socket) => OnConnection?.Invoke(socket);