Exemplo n.º 1
0
            protected override void OnRunThread()
            {
                Ip ip = null;

                try{
                    ip = new Ip(_addr);
                } catch (ValidObjException ex) {
                    Assert.Fail(ex.Message);
                }
                if (_sockServer.Bind(ip, _port))
                {
                    //[C#]
                    ThreadBaseKind = ThreadBaseKind.Running;

                    while (IsLife())
                    {
                        var child = (SockUdp)_sockServer.Select(this);
                        if (child == null)
                        {
                            break;
                        }
                        while (IsLife() && child.SockState == SockState.Connect)
                        {
                            var len = child.Length();
                            if (len > 0)
                            {
                                byte[] buf = child.RecvBuf;
                                child.Send(buf);
                                //送信が完了したら、この処理は終了
                                break;
                            }
                        }
                    }
                }
            }
Exemplo n.º 2
0
        private void RunTcpServer(int port)
        {
            const int listenMax = 5;

            //[C#]
            ThreadBaseKind = ThreadBaseKind.Running;

            if (!_sockServer.Bind(_oneBind.Addr, port, listenMax))
            {
                Logger.Set(LogKind.Error, _sockServer, 9000006, _sockServer.GetLastEror());
            }
            else
            {
                while (IsLife())
                {
                    var child = (SockTcp)_sockServer.Select(this);
                    if (child == null)
                    {
                        break;
                    }
                    if (Count() >= _multiple)
                    {
                        Logger.Set(LogKind.Secure, _sockServer, 9000004, string.Format("count:{0}/multiple:{1}", Count(), _multiple));
                        //同時接続数を超えたのでリクエストをキャンセルします
                        child.Close();
                        continue;
                    }

                    // ACL制限のチェック
                    if (AclCheck(child) == AclKind.Deny)
                    {
                        child.Close();
                        continue;
                    }
                    lock (SyncObj){
                        var t = new Thread(SubThread)
                        {
                            IsBackground = true
                        };
                        t.Start(child);
                        _childThreads.Add(t);
                    }
                }
            }
        }