nginx stream模块中增加心跳机制

1、修改文件src/stream/ngx_stream.c

#define SESSION_FLUSH_TIME  1000

static ngx_event_t ev_cleanup;
static ngx_connection_t dummy;
int client_send(char* server_type, char * message);

static void  ngx_heartbeat_timer ( ngx_event_t *ev)
{
   ngx_log_error(NGX_LOG_INFO,ev->log,0," ngx_accesskey_timer  ");
   ngx_log_debug(NGX_LOG_DEBUG_EVENT, ev->log, 0,"ngx_accesskey_timer");
   /*-----------------------增加自己的代码实现------------------------*/
   ngx_add_timer(&ev_cleanup,SESSION_FLUSH_TIME);
}

static ngx_int_t ngx_stream_init_process(ngx_cycle_t *cf)
{
    ngx_memzero(&ev_cleanup,sizeof(ngx_event_t));
    ev_cleanup.handler =  ngx_heartbeat_timer ;
    ev_cleanup.log = cf->log;
    dummy.fd=(ngx_socket_t)-1;
    ev_cleanup.data=&dummy;
    ngx_add_timer(&ev_cleanup,SESSION_FLUSH_TIME);
    return NGX_OK;
}

ngx_module_t  ngx_stream_module = {
    NGX_MODULE_V1,
    &ngx_stream_module_ctx,                /* module context */
    ngx_stream_commands,                   /* module directives */
    NGX_CORE_MODULE,                       /* module type */
    NULL,                                  /* init master */
    NULL,                                  /* init module */
    ngx_stream_init_process,      /* init process */
    //NULL,                                  /* init process */

    NULL,                                  /* init thread */
    NULL,                                  /* exit thread */
    NULL,                                  /* exit process */
    NULL,                                  /* exit master */
    NGX_MODULE_V1_PADDING
};

2、

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值