本文是根据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

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

被折叠的 条评论
为什么被折叠?



