lacewing简介

Liblacewing是一个跨平台的C/C++网络库,提供高级功能如IOCP/kqueue/epoll支持,适用于游戏、Web服务器等应用。本文介绍其核心组件eventpump和webserver,以及文件操作和加密等实用函数。

本文是根据lacewing官网的介绍并结合自己的使用经验,挑比较常用到的内容提取归纳而成

lacewing简介

liblacewing是一个跨平台的,为C/C++提供的高级网络开源库,旨在提供一个简明的类,做到能够扩展并且可以平台优化(支持IOCP/EPOLL/KQUEUE等)。

Classes

lacewing::eventpump

eventpump is a default implementation of pump provided by the library, powered by IOCP, kqueue or epoll.

As there is no single model for event handling that would suit every application, eventpump provides several different modes of operation:

  • tick polls aggressively, suited to a game loop;

  • start_eventloop starts a simple “block forever” event loop, suited to console applications and daemons;

  • start_sleepy_ticking enables a threaded callback to request the application call tick as soon as possible, suited to applications with an existing message pump (such as Win32 GUI applications)

lacewing::webserver

webserver aims to provide an embeddable, flexible HTTP server using liblacewing classes as a base.

Ease of embedding makes webserver ideal for things such as remote administration interfaces, and through the use of eventpump, webserver is able to scale well and adapt transparently to different ways of handling I/O.

Features of webserver include:

  • Simple hooks for requests, with easy access to GET and POST data
  • Support for cookies and sessions
  • Support for HTTPS (see host_secure)
  • HTTP file upload

webserver uses server as a base for socket communication.

on_get (webserver)
// C++ style
void on_get (lacewing::webserver webserver, lacewing::webserver_request request)
{
   
   
/*on_get的响应*/
}

webserver->on_get (on_get); /* to register the hook */
// C style
void on_get (lw_ws webserver, lw_ws_request)
{
   
   
/*on_get的响应*/
}

lw_ws_on_get (webserver, on_get); /* to register the hook */

Description
The on_get hook is triggered for an incoming HTTP GET request.

This hook marks the beginning of the lifetime of a request object. If enable_manual_finish has been called, the request object will be valid until either request::finish is called OR the on_disconnect hook triggers. Otherwise, the request object is only valid until the hook returns.

The application may configure a response in this hook with functions such as request::header, and request::cookie, and write the response data with stream::write and stream::write_file.

Nothing will actually be written to the socket while the request object is still valid. This ensures that an accurate Content-Length header can be generated, and that headers can be changed throughout the lifetime of the request.

on_post (webserver)
// C++ style
void on_get (lacewing::webserver webserver, lacewing::webserver_request &request)
{
   
   
}

webserver->on_post (on_post); /* to register the hook */
// C style
void on_post (lw_ws webserver, lw_ws_request)
{
   
   
}

lw_ws_on_post (webserver, on_post); /* to register the hook */

Description
The on_post hook is triggered for an incoming HTTP POST request.

This hook marks the beginning of the lifetime of a request object. If enable_manual_finish has been called, the

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值