ServerDS NewServerDS(IDSI dsiReq) { while (true) { lock (servs) { if (evExit.WaitOne(0, false)) { throw new ExitShotException(); } if (servs.Count >= MaxSim) { Thread.Sleep(25); continue; } else { ushort RId = this.RId++; ServerDS serv = new ServerDS(); serv.dsiReq = dsiReq; serv.RId = RId; servs.Add(serv); return(serv); } } } }
ServerDS NewServerDS(IDSI dsiReq) { while (true) { lock (servs) { if (evExit.WaitOne(0, false)) throw new ExitShotException(); if (servs.Count >= MaxSim) { Thread.Sleep(25); continue; } else { ushort RId = this.RId++; ServerDS serv = new ServerDS(); serv.dsiReq = dsiReq; serv.RId = RId; servs.Add(serv); return serv; } } } }
void Receiver() { Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; try { while (true) { DSIPack res = new DSIPack(st); if (res.Command == 5) // DSITickle { continue; } ServerDS sv = GetServerDS(res.RequestID); if (sv == null) { continue; } sv.dsiRes = res; sv.evRecv.Set(); } } catch (Exception err) { if (!evExit.WaitOne(0, false)) { //Console.Error.WriteLine("# Receiverが故障しました: " + err.Message); } lock (servs) { foreach (ServerDS serv in servs) { serv.evRecv.Set(); serv.err = err; } } if (Sock.Connected) { Sock.Shutdown(SocketShutdown.Both); } } }
void DisconnectServerDS(ServerDS serv) { lock (servs) { servs.Remove(serv); } }