Example #1
0
    public static bool EvalAll()
    {
        /*
         *  When entering playmode, Unity hangs, this is probalby where.
         *  The entire assembly is unloaded and threads are killed, but even if the ShellPeer-Thread died,
         *  this should not affect reading the linked list at all ( unless it died during lock(), but it happens every time )
         *
         *  this could only really be during unload - as everything is initialized afresh on playmode-enter dll-load
         *
         *  the hang stops as soon as you kill the remote shells
         *  ( unity forcibly aborts the server-listener thread but not the per-Peer threads ? )
         *
         *  vll kann thread, der auf einem socket blockt nicht "aborted" und haengt endlos
         */
        var  remove     = new HashSet <TcpClient>();
        bool had_update = false;


        foreach (var KV in ShellServer.Peers)
        {
            ShellPeer shellPeer = KV.Value;
            if (!shellPeer.thread.IsAlive)
            {
                remove.Add(KV.Key);  continue;
            }
            had_update = had_update || shellPeer.EvalQueuedRequests();
        }
        foreach (var tcp_cl in remove)
        {
            Peers.Remove(tcp_cl); "removing shellPeer ( thread died )".NLSend();
        }
        return(had_update);
    }
Example #2
0
 static void ServerLoop()
 {
     try {
         while (true)
         {
             TcpClient cl = server_listener.AcceptTcpClient();
             lock ( Peers ) {
                 Peers[cl] = new ShellPeer(cl);
             }
         }
     } catch (Exception e) {
         e.Message.NLSend("exception in listener thread");
     } finally {
         server_listener.Stop();
     }
 }