Changeset 4545:ba39af7274ed in nginx


Ignore:
Timestamp:
03/16/12 19:15:33 (8 years ago)
Author:
Ruslan Ermilov <ru@…>
Branch:
default
Phase:
public
Convert:
svn:c3fe7df1-7212-e011-8a91-001109144009/trunk@4546
Message:

Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
$tcpinfo_rcv_space variables. Supported on Linux and FreeBSD.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • auto/unix

    r4543 r4545  
    341341                  setsockopt(0, IPPROTO_TCP, TCP_KEEPINTVL, NULL, 0);
    342342                  setsockopt(0, IPPROTO_TCP, TCP_KEEPCNT, NULL, 0)"
     343. auto/feature
     344
     345
     346ngx_feature="TCP_INFO"
     347ngx_feature_name="NGX_HAVE_TCP_INFO"
     348ngx_feature_run=no
     349ngx_feature_incs="#include <sys/socket.h>
     350                  #include <netinet/in.h>
     351                  #include <netinet/tcp.h>"
     352ngx_feature_path=
     353ngx_feature_libs=
     354ngx_feature_test="socklen_t optlen = sizeof(struct tcp_info);
     355                  getsockopt(0, IPPROTO_TCP, TCP_INFO, NULL, &optlen)"
    343356. auto/feature
    344357
  • src/http/ngx_http_variables.c

    r4540 r4545  
    3535static ngx_int_t ngx_http_variable_argument(ngx_http_request_t *r,
    3636    ngx_http_variable_value_t *v, uintptr_t data);
     37#if (NGX_HAVE_TCP_INFO)
     38static ngx_int_t ngx_http_variable_tcpinfo(ngx_http_request_t *r,
     39    ngx_http_variable_value_t *v, uintptr_t data);
     40#endif
    3741
    3842static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r,
     
    260264      0, 0, 0 },
    261265
     266#if (NGX_HAVE_TCP_INFO)
     267    { ngx_string("tcpinfo_rtt"), NULL, ngx_http_variable_tcpinfo,
     268      0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
     269
     270    { ngx_string("tcpinfo_rttvar"), NULL, ngx_http_variable_tcpinfo,
     271      1, NGX_HTTP_VAR_NOCACHEABLE, 0 },
     272
     273    { ngx_string("tcpinfo_snd_cwnd"), NULL, ngx_http_variable_tcpinfo,
     274      2, NGX_HTTP_VAR_NOCACHEABLE, 0 },
     275
     276    { ngx_string("tcpinfo_rcv_space"), NULL, ngx_http_variable_tcpinfo,
     277      3, NGX_HTTP_VAR_NOCACHEABLE, 0 },
     278#endif
     279
    262280    { ngx_null_string, NULL, NULL, 0, 0, 0 }
    263281};
     
    883901    return NGX_OK;
    884902}
     903
     904
     905#if (NGX_HAVE_TCP_INFO)
     906
     907static ngx_int_t
     908ngx_http_variable_tcpinfo(ngx_http_request_t *r, ngx_http_variable_value_t *v,
     909    uintptr_t data)
     910{
     911    struct tcp_info  ti;
     912    socklen_t        len;
     913    uint32_t         value;
     914
     915    len = sizeof(struct tcp_info);
     916    if (getsockopt(r->connection->fd, IPPROTO_TCP, TCP_INFO, &ti, &len) == -1) {
     917        v->not_found = 1;
     918        return NGX_OK;
     919    }
     920
     921    v->data = ngx_pnalloc(r->pool, NGX_INT32_LEN);
     922    if (v->data == NULL) {
     923        return NGX_ERROR;
     924    }
     925
     926    switch (data) {
     927    case 0:
     928        value = ti.tcpi_rtt;
     929        break;
     930
     931    case 1:
     932        value = ti.tcpi_rttvar;
     933        break;
     934
     935    case 2:
     936        value = ti.tcpi_snd_cwnd;
     937        break;
     938
     939    case 3:
     940        value = ti.tcpi_rcv_space;
     941        break;
     942
     943    /* suppress warning */
     944    default:
     945        value = 0;
     946        break;
     947    }
     948
     949    v->len = ngx_sprintf(v->data, "%uD", value) - v->data;
     950    v->valid = 1;
     951    v->no_cacheable = 0;
     952    v->not_found = 0;
     953
     954    return NGX_OK;
     955}
     956
     957#endif
    885958
    886959
Note: See TracChangeset for help on using the changeset viewer.