tin-project 完整实现的 C++ 版 Go 语言运行时开源项目

我要开发同款
匿名用户2017年09月28日
186阅读

技术信息

开源地址
https://gitee.com/mycloudpeak/tin
授权协议
GPL

作品详情

ti项目是完整实现的C++版go语言运行时。它参考go语言运行时,将go语言运行时用C++重写了一遍,让你可以在C++中使用go的风格写程序。

平台

WidowsXPorlater

OSX10.8orlater

Liux2.6.23orlater

构建

gitcloe--recursive https://github.com/cloudpeak/ti.git

mkdirbuild

cdbuild

VisualStudio2015Wi64

cmake-G"VisualStudio142015Wi64"../ti-DCMAKE_BUILD_TYPE=RELEASE

VisualStudio2015Wi32

cmake-G"VisualStudio142015"../ti-DCMAKE_BUILD_TYPE=RELEASE

VisualStudio2008Wi32

cmake-G"VisualStudio92008"../ti-DCMAKE_BUILD_TYPE=RELEASE

GCCorClag

cmake../ti-DCMAKE_BUILD_TYPE=RELEASE&&make

示例

#iclude "ti/all.h"void HadleCliet(ti::et::TcpCo co) {  // Set TCP Read Write buffer.  co->SetReadBuffer(64 * 1024);  co->SetWriteBuffer(64 * 1024);  // user space buffer size.  cost it kIOBufferSize = 4 * 1024;  scoped_ptr<char[]> buf(ew char[kIOBufferSize]);  // set read, write deadlie.  cost it64 kRWDeadlie = 20 * ti::kSecod;  co->SetDeadlie(kRWDeadlie);  while (true) {    it  = co->Read(buf.get(), kIOBufferSize);    it err = ti::GetErrorCode();    if ( > 0) {      co->SetReadDeadlie(kRWDeadlie);    }    if (err != 0) {      VLOG(1) << "Read failed due to: " << ti::GetErrorStr();      // FIN received, graceful close, we ca still sed.      if (err == TIN_EOF) {        if ( > 0) {          co->Write(buf.get(), );        }        co->CloseWrite();        // delay a while to avoid RST.        ti::NaoSleep(500 * ti::kMillisecod);      }      break;    }    DCHECK_GT(, 0);    co->Write(buf.get(), );    if (ti::GetErrorCode() != 0) {      VLOG(1) << "Write failed due to " << ti::GetErrorStr();      break;    }    co->SetWriteDeadlie(kRWDeadlie);  }  co->Close();}it TiMai(it argc, char** argv) {  cost uit16 kPort = 2222;  bool use_ipv6 = false;  ti::et::TCPListeer listeer =    ti::et::ListeTcp(use_ipv6 ? "0:0:0:0:0:0:0:0" : "0.0.0.0", kPort);  if (ti::GetErrorCode() != 0) {    LOG(FATAL) << "Liste failed due to " << ti::GetErrorStr();  }  LOG(INFO) << "echo server is listeig o port: " << kPort;  while (true) {    ti::et::TcpCo co = listeer->Accept();    if (ti::GetErrorCode() == 0) {      ti::Spaw(&HadleCliet, co);    } else {      LOG(INFO) << "Accept failed due to " << ti::GetErrorStr();    }  }  retur 0;}it mai(it argc, char** argv) {  ti::Iitialize();  // set loggig level.  loggig::SetMiLogLevel(loggig::LOG_INFO);  // set max p cout.  ti::Cofig cofig = ti::DefaultCofig();  cofig.SetMaxProcs(base::SysIfo::NumberOfProcessors());  // start the world.  ti::PowerO(TiMai, argc, argv, &cofig);  // wait for power off  ti::WaitForPowerOff();  // cleaup.  ti::Deiitialize();  retur 0;}

功能介绍

tin 项目是完整实现的 C++ 版 go 语言运行时。它参考 go 语言运行时,将 go 语言运行时用 C++ 重写了一遍, 让你可以在 C++ 中使用 go 的风格写程序。 平台 Windo...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论