1 Star 2 Fork 1

Barry / tcp-nginx-module

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-2-Clause

tcp-nginx-module

Use nginx as a common TCP server framework

Description

The motivation for writing these is to use nginx as a common TCP server framework, So it called ngxtcp.The ngxtcp.jpg illustrates this framework.Most of the code is modificationed from nginx mail modules.I developed an application protocol that is named command protocol over the TCP.
Command Protocol Format


    0                 1                   2                   3    
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                            size                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                            cmd                                |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                           spare0                              |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                           spare1                              |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                           spare2                              |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                           spare3                              |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                           spare4                              |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                           spare5                              |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                            body                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Command Protocol Header Filed “size == head + body”

Develop Command Protocol Server

example in the ping_pong dir

Synopsis

tcp {
    max_socketfd_value          100000;
    worker_process_unix_listen  logs/tcp;
    # keys_zone size must >= (max_socketfd_value * 16 + worker_processes * 512)
    socketfd_shm                /tmp/socketfd_shm keys_zone=cache_socketfd_shm:10m;
    max_pkg_size 2m;
    # error_log logs/tcp_err.log debug;
    server {
        timeout 240;
        protocol cmd;
        listen 9190;
    }
}

Installation And Test

Download the latest stable version of the release tarball of this module
from github ()

Grab the nginx source code from nginx.org (<http://nginx.org/>), extract the source and go into the dir.

    # ./configure --prefix=/path/to/$build_prefix --add-module=/path/to/tcp_module
    # make
    # make install
    # mkdir /path/to/$build_prefix/cmdso
    # cd /path/to/tcp_module/ping_pong
    # make
    # cp  /path/to/tcp_module/ping_pong/svr/pp.so /path/to/$build_prefix/cmdso/
    # cd /path/to/$build_prefix/sbin/
    # ./nginx
    # cd /path/to/tcp_module/ping_pong/cli/
    # ./pp_cmd_cli

FIXME

*   How to support nginx reload in ngx_tcp
*   Only support linux

TODO

1.   test ssl 
2.   exploit more nginx/ngx_tcp to develop Command Protocol Shared Dynamic Library, for example shared memory and so on.
3.   add doc or blob
Copyright (c) 2014, 柳老蔡<1722659493@qq.com> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

Use nginx as a common TCP server framework 展开 收起
C
BSD-2-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/Barryda/tcp-nginx-module.git
git@gitee.com:Barryda/tcp-nginx-module.git
Barryda
tcp-nginx-module
tcp-nginx-module
master

搜索帮助