Exemplo n.º 1
0
        public static CothreadTimeout NewWithStart(uint ms)
        {
            var rs = new CothreadTimeout();

            rs.Start(ms);
            return(rs);
        }
Exemplo n.º 2
0
        IEnumerator testTimeout2()
        {
            var timeout = CothreadTimeout.NewWithStart(1005);

            yield return(hub.Sleep(1010));

            try {
                timeout.Cancel(true);
                CothreadHub.Log("[testTimeout2] CothreadTimeoutError error");
            } catch (CothreadTimeoutError) {
                CothreadHub.Log("[testTimeout2] CothreadTimeoutError ok");
            }
        }
Exemplo n.º 3
0
        public bool IsTimeout(bool isThrowTimeout)
        {
            var t = Timeout;

            Timeout = null;
            if (t != null)
            {
                if (isThrowTimeout)
                {
                    throw new CothreadTimeoutError(t);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        IEnumerator testJoin()
        {
            var timeout = CothreadTimeout.NewWithStart(1);
            var ct1     = hub.StartCoroutine(_testJoin());

            yield return(ct1.Join());

            if (!timeout.Timeout)
            {
                CothreadHub.Log("[testJoin] error");
            }
            else
            {
                CothreadHub.Log("[testJoin] ok");
            }
        }
Exemplo n.º 5
0
        IEnumerator testSock1(int i)
        {
            string stri = i.ToString();

            CothreadHub.Log("testSock:" + stri);
            CothreadTimeout timeout = CothreadTimeout.NewWithStart(5);
            CothreadSocket  sock    = new CothreadSocket();

            yield return(sock.Connect("192.168.0.210", 81));             //web server

            //yield return sock.Connect("www.baidu.com", 80);  //www.baidu.com
            //yield return sock.Connect("115.239.210.27", 80);  //www.baidu.com
            //yield return hub.Sleep(rt);
            //CothreadHub.Log(stri + "-socket connected:" + sock.Connected);

            yield return(sock.SendString("GET / HTTP/1.0\n\n"));

            //CothreadHub.Log(stri + "-Send ok");
            var recvData = new CothreadSocketRecvData(2048);
            var result   = new CothreadResult <string>();

            yield return(hub.Sleep(1000));

            yield return(sock.RecvString(recvData, result));

            string s1 = (string)result.Result;

            if (string.IsNullOrEmpty(s1))
            {
                CothreadHub.Log("testSock(" + stri + ") error" + "-passTime:" + timeout.PassTime.ToString());
            }
            else
            {
                CothreadHub.Log("testSock(" + stri + ") ok:" + s1.Length.ToString() + "  data:" + s1.Substring(0, Math.Min(500, s1.Length)));
            }
            try {
                timeout.Cancel(true);
            } catch (CothreadTimeoutError) {
                CothreadHub.Log(stri + "-testSock timeout");
            } finally {
                sock.Close();
            }
        }
Exemplo n.º 6
0
        public IEnumerator Wait(uint ms = 0)
        {
            if (Current != NULL)
            {
                yield return(Current);

                yield break;
            }
            CothreadTimeout t = null;

            yields.Add(CothreadHub.Instance.current);
            if (ms > 0)
            {
                t = CothreadTimeout.NewWithStart(ms);
            }
            yield return(CothreadHub.YIELD_CALLBACK);

            if (ms > 0)
            {
                t.Cancel(false);
            }
        }
Exemplo n.º 7
0
 public CothreadTimeoutError(CothreadTimeout t) : base("Timeout")
 {
     Timeout = t;
 }