Example #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);
            }
        }
Example #2
0
 /// <summary>
 /// Queue the given Owner.
 /// </summary>
 /// <param name="owner">Owner to queue.</param>
 public static void QueueOwner(ClientOwner owner)
 {
     acceptQueue.Add(owner);
 }
Example #3
0
 /// <summary>
 /// Hand the Client to a Client Owner.
 /// </summary>
 /// <param name="processor">Client's Client Owner.</param>
 public void HandedTo(ClientOwner processor)
 {
     Owner = processor;
 }