Esempio n. 1
0
        public static Func <int> OwnerCreationFunc     = null;                      // Function to create new Client Owners.

        /// <summary>
        /// Add a TCP Client to the Acceptor.
        /// </summary>
        /// <param name="tcpClient">TCP Client to add.</param>
        public static void AddTCPClient(TcpClient tcpClient)
        {
            if (acceptQueue.Count > 0) // ... If there are Owners waiting...
            {
                // ... Take the first owner in the queue and hand over Client.
                ClientOwner nextOwner = acceptQueue[0];
                Client      newClient = new Client(tcpClient);
                clients.Add(newClient);
                nextOwner.Give(newClient);
                newClient.HandedTo(nextOwner);

                // If the Owner can't accept anymore Clients, remove it.
                if (!nextOwner.CanAcceptClient())
                {
                    acceptQueue.Remove(nextOwner);
                }
            }
            else // ... Otherwise...
            {
                // Create new Owner and assign Client.
                OwnerCreationFunc();
                AddTCPClient(tcpClient);
            }
        }