Code Monkey home page Code Monkey logo

ngx_cpp_dev's Introduction

Name

ngx_cpp_dev

Nginx cpp development kit, with the power of C++11 and Boost Library.

Build Status

Table of Contents

Status

Experimental but works well.

Now support Nginx 1.13.10 and later.

See Also

Requirements

  • Linux or other UNIX like
  • C++11(gcc 4.6 or later)
  • Boost(1.57 or later)
  • Nginx 1.13.10 or later

Please see directiory "setup".

Usage

At first, you must patch nginx/auto/make to enable g++ compiler and C++11.

Please see directory "patch/auto".

For example:

patch -b make make.patch

Then configure nginx with:

./configure --add-module=path/to/ngxpp	\	            # ngx cpp module
			--add-module=xxxx			                # other modules
make

ngx_cpp_module is a pure header library, you should use ngx_cpp_module like this:

#include "NgxAll.hpp"	// include all C++ tools for http modules

Or

#include "NgxStreamAll.hpp"	// include all C++ tools for stream modules

Examples

Please see directory http, including echo/filter/variables and so on.

C++ APIs

common tools

Class Name Description
NgxUnsetValue generic unset value -1.
NgxValue wrapper for nginx int, include init/merge/unset.
NgxException wrapper for nginx error code.
NgxPool wrapper for nginx memory pool.
NgxAlloctor adapter to C++ allocator.
NgxString wrapper for nginx ngx_str_t.
NgxClock wrapper for nginx time functions.
NgxDatetime wrapper for nginx date functions.
NgxLog wrapper for nginx error log.

data structure

Class Name Description
NgxArray wrapper for nginx ngx_array_t.
NgxList wrapper for nginx ngx_list_t.
NgxQueue wrapper for nginx ngx_queue_t.
NgxBuf deprecated, wrapper for nginx ngx_buf_t.
NgxChain deprecated, wrapper for nginx ngx_chain_t.
NgxRbtree wrapper for nginx ngx_rbtree_t.

modules

Class Name Description
NgxModuleConfig easy to access nginx module confing info.
NgxModule get module's config and ctx data.
NgxCommand deprecated, DO NOT USE IT.
NgxTake deprecated
NgxModuleCtx easy to access nginx module's ctx data.
NgxHttpCoreModule wrapper for ngx_http_core_module
NgxFilter wrapper for nginx filter mechanism.

http process

Class Name Description
NgxHeaders
NgxRequest
NgxResponse
NgxUpstreamHelper
NgxLoadBalance
NgxSubRequest

others

Class Name Description
NgxVariables
NgxVarManager
NgxDigest
NgxTimer

TODO

  • more test suites
  • nginx datagram
  • ...

ngx_cpp_dev's People

Contributors

chronolaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx_cpp_dev's Issues

cannot compile cpp files

 #cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -O0  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I /home/svandex/Repositories/ngx_cpp_dev/ngxpp \
	-o objs/addon/echo/ModNdgEcho.o \
	/home/svandex/Repositories/ngx_cpp_dev/http/echo/ModNdgEcho.cpp
/bin/sh: line 1: -o: command not found
make[1]: *** [objs/addon/echo/ModNdgEcho.o] Error 127
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory `/home/svandex/Repositories/nginx'
make: *** [build] Error 2

I have followed instructions on editing auto/make file, add CXX and CXXFLAGS, LINK variables but it doesn't work. Seems like #cc is not correct, I have set CXX = g++

I am using CentOS 7 with gcc 4.8.5.

源码编译

你好,请问nginx源码需要安装到哪个目录吗?

编译错误

环境:CentOS7
Boost:1.60
错误提示如下:(我只编译http/test模板)

g++ -c -g -O0 -std=c++11 -Wall -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I /home/developer/ngx_cpp_dev/ngxpp -I src/stream
-o objs/addon/test/ModNdgTest.o
/home/developer/ngx_cpp_dev/http/test/ModNdgTest.cpp
In file included from /usr/local/include/boost/optional/optional.hpp:49:0,
from /usr/local/include/boost/optional.hpp:15,
from /usr/local/include/boost/format/internals.hpp:20,
from /usr/local/include/boost/format.hpp:38,
from /home/developer/ngx_cpp_dev/ngxpp/NgxVariable.hpp:6,
from /home/developer/ngx_cpp_dev/ngxpp/NgxAll.hpp:32,
from /home/developer/ngx_cpp_dev/http/test/NdgTestConf.hpp:6,
from /home/developer/ngx_cpp_dev/http/test/NdgTestInit.hpp:6,
from /home/developer/ngx_cpp_dev/http/test/ModNdgTest.cpp:3:
/usr/local/include/boost/detail/reference_content.hpp:74:24: error: expected type-specifier before ‘mpl’
template struct make_reference_content;
^
/usr/local/include/boost/detail/reference_content.hpp:74:24: error: expected ‘>’ before ‘mpl’
/usr/local/include/boost/detail/reference_content.hpp:91:32: error: ‘mpl’ was not declared in this scope
struct make_reference_content< mpl::void_ >
^
......

overload std::ostream<< for ngx_str_t

Please add overload function for std::ostream << to take ngx_str_t as input.

inline std::ostream& operator<<( std::ostream& o, const ngx_str_t& t)
{
    o.write( reinterpret_cast<const char*>(t.data), t.len);
    return o;
}

nginx的stream模块可以实现包的处理,然后转发吗?

TCP是一个流协议。 通常开发时会在TCP载荷部分使用自定义协议来表示包的概念。 比如 length + data的模式。 客户端按照协议进行打包,然后发送。服务器则收到一个完整的包后,解包,处理,发送响应。

我在《Nginx完全开发指南》 一书中,看到了定制的stream模块,包括 discard 、 time、 chargen。 这几个例子的服务器都没有从客户端接收包的动作。

那么,通过修改nginx的stream模块是否可以实现如下的功能: 收到一个完整的包,然后对这个包进行处理,然后再proxy_pass出去吗。 是否有相关的例子?

谢谢~~

@chronolaw

编译失败,想请问一下

你好,
你在这个文件ngx_cpp_dev/http/test/NdgTestHandler.hpp 中有大量的std::cout来测试输出,
但是凭着直觉,一个ngx_str_t应该是不能直接std::cout<<ngx_str 这样用的吧?

在编译的时候确实遇到了这样的问题,编译错误。
std::cout << NgxDatetime::today() << std::endl; //就是这一行报错了。

把所有的cout都注释掉,编译就成功了。

请问我是哪里没有配置好才会这样的吗?
虽然只是cout,无伤大雅,但很好奇为什么作者这样写没有问题。
望解答,谢谢Chrono。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.