void tcpAcceptedThread(object?param) { Sock s = (Sock)param !; ThreadObj.NoticeInited(); this.AcceptProc(this, s, this.AcceptParam); }
// スレッド public void ListenerThread(object?param) { Sock?new_sock; Sock s; int num_failed; this.thread = ThreadObj.GetCurrentThreadObj() !; this.Status = ListenerStatus.Trying; ThreadObj.NoticeInited(); while (true) { bool firstFailed = true; this.Status = ListenerStatus.Trying; // Listen を試みる while (true) { if (this.halt) { return; } try { s = Sock.Listen(this.Port, this.LocalOnly); this.Sock = s; break; } catch { if (firstFailed) { firstFailed = false; } this.eventObj.Wait(this.ListenRetryTime); if (this.halt) { return; } } } this.Status = ListenerStatus.Listening; if (this.halt) { this.Sock.Disconnect(); break; } num_failed = 0; // Accept ループ while (true) { // Accept する new_sock = this.Sock.Accept(this.GetHostName); if (new_sock != null) { // 成功 tcpAccepted(new_sock); } else { // 失敗 if (this.halt == false) { if ((++num_failed) <= 5) { continue; } } this.Sock.Disconnect(); break; } } if (this.halt) { return; } } }