コード例 #1
0
        void tcpAcceptedThread(object param)
        {
            Sock s = (Sock)param;

            ThreadObj.NoticeInited();

            this.acceptProc(this, s, this.acceptParam);
        }
コード例 #2
0
        // スレッド
        public void ListenerThread(object param)
        {
            Sock new_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;
                }
            }
        }