lim 跨平台网络通信框架

开源网站开源项目 24-03-28 16:43:40

lim 是一套轻量级的高性能通信框架,基于 C/C++ 语言开发,采用全异步通信模式,内部集成了 HTTP、HTTPS、WebSocket 通信协议实现,目前支持 Windows 和 Linux 平台。

示例代码:

#include <lim/base/logger.h>#include <lim/base/bootstrap.h>#include <lim/base/server_channel_session.h>#include <lim/http/http_bootstrap_config.h>#include <lim/http/http_response_session.h>namespace lim { class HttpServer: public HttpFullRequestSession { public: HttpServer(SocketChannel &channel, BootstrapConfig &config): HttpFullRequestSession(channel, config) {  RegistHandleRouter("POST", "/test", std::bind(&HttpsServer::PostTestHandle, this, std::placeholders::_1));} virtual ~HttpsServer() = default; private: bool PostTestHandle(Message &request) {  HttpFullResponse http_response(200, "OK", "HTTP/1.1");  int length = http_response.Content().Content().WriteBytes("{\"aa\":8}", strlen("{\"aa\":8}"));  http_response.Headers().SetHeaderValue("Connection", "close");  http_response.Headers().SetHeaderValue("Content-Type", "application/json");  http_response.Headers().SetHeaderValue("Content-Length", std::to_string(length));  WriteHttpResponse(http_response, [&] {  Signal(ExecuteEvent::KILL_EVENT); //发送完毕关闭连接  });  return true; } };}using namespace lim;int main() { Logger *logger = Logger::GetLogger("demo"); SocketChannel::InitEnviroment(); //服务监听器&处理线程池 EventLoop server_event_loop; ExecuteThread server_execute_thread; //客户端连接监听器&处理线程池 EventLoopGroup worker_event_loop_group; ExecuteThreadGroup worke_execute_thread_group; HttpBootstrapConfig config(worker_event_loop_group, worke_execute_thread_group, server_event_loop, server_execute_thread); //设置处理超时时间 config.SetTimeout(30 * 1000); //异常回掉函数 config.SetLoggerCallback([&](LoggerLevel level, const std::string &message) {  TRACE_ERROR(logger, "%s", message.c_str()); }); Bootstrap strap = Bootstrap(config); strap.Bind<ServerChannelSession<HttpServer>>("0.0.0.0", 8095); while (1) {  std::this_thread::sleep_for(std::chrono::milliseconds(1000 * 5)); } return 0;}

[lim 跨平台网络通信框架]相关推荐
FreeType 字体工具

FreeType 字体工具

FreeType 2被设计为一种占用空间小的、高效的、高度可定制的、并且可以产生可移植的高品质输出(符号图像……...

Servo Mozilla 的浏览器引擎

Servo 是一个 Web 浏览器引擎的原型,使用 Rust 语言开发,当前基于 OS X 和 Linux 开发。 Servo浏览器引……...

Rust Mozilla的编程语言

Rust Mozilla的编程语言

Rust 是 Mozilla 的一个新的编程语言,由web语言的领军人物Brendan Eich(js之父),Dave Herman以及Mozi……...

今日开源
  1. TeamCity 持续集成工具

    TeamCity 持续集成工具

    TeamCity 是一个通用的CI/CD解决方案,可以为各种工作流程和开发实践提供最大的灵活性。TeamCity提供一系列特性可以让团队快速实现持续继承:IDE工具集成、各种消息通知、各种报表、项目的管理、分布式的编译等等……

    开源软件 2024-04-28

  2. Argo 容器本地工作流引擎

    Argo 容器本地工作流引擎

    Argo 是一个开源的容器本地工作流引擎,用于在Kubernetes上完成工作。 Argo实现为Kubernetes CRD(自定义资源定义)。 定义工作流中每个步骤都是容器的工作流。 将多步骤工作流建模为一系列任务,或使用图形(DAG……

    开源软件 2024-04-28

  3. Nimbus IaaS 解决方案

    Nimbus 是一种以科学计算为中心的 IaaS "Infrastructure-as-a-Service" 解决方案。使用 Nimbus,你可以借用远程资源(比如由 Amazon EC2 提供的远端资源)并能对它们进行本地管理(配置、部署 VM、监视等)。Nimbu……

    开源软件 2024-04-28

返回顶部小火箭