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"); } }
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"); } }
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(); } }
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); } }