~ubuntu-branches/ubuntu/quantal/nginx/quantal-updates

« back to all changes in this revision

Viewing changes to debian/modules/nginx-echo/src/ngx_http_echo_sleep.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Lustfield, Micheal Lustfield, Kartik Mistry
  • Date: 2011-03-03 23:39:07 UTC
  • mfrom: (4.2.29 sid)
  • Revision ID: james.westby@ubuntu.com-20110303233907-y48yifhfnn5qjuxz
Tags: 0.8.54-4
[Micheal Lustfield]
* debian/nginx-{full,light,extras}.default:
  + Added comment about alternative to ULIMIT.
* debian/nginx-{full,light,extras}.init.d:
  + Added quotes around a test variable. (Closes: #610946, LP: #699736)
* debian/patches/609343-log-time-iso8601.diff:
  + Added patch to add $time_iso8601 variable to logs. (Closes: #609343)
* Clean up old logrotate files. (Closes: #608983, Closes: #610289)
  + Added Files:
    - debian/nginx-common.preinst
  + Modified Files:
    - debian/rules
  + Moved debian/nginx-common.logrotate to debian/logrotate.
* Added common files to nginx-common package. (Closes: #610290)
  + Removed Files:
    - debian/nginx-full.dirs
    - debian/nginx-light.dirs
    - debian/nginx-full.install
    - debian/nginx-light.install
    - debian/nginx-extras.install
    - debian/nginx.*
  + Added Files:
    - debian/nginx-common.default
    - debian/nginx-common.dirs
    - debian/nginx-common.init.d
    - debian/nginx-common.install
    - debian/nginx-common.manpages
    - debian/logrotate
  + Modified Files:
    - debian/nginx-extras.dirs
    - debian/control
    - debian/rules
* debian/nginx-*.install: (Closes: #609797)
  + Removed NEWS.Debian from nginx-{full,light,extras}.install.
  + Added NEWS.Debian to nginx-common.install.
* nginx-common.postinst:
  + Enforce /var/log/nginx mode and user:group. (Closes: #610983)
  + Enforce /var/log/nginx/*.log mode and user:group. (Closes: #612832)
* debian/rules:
  + Added --with-file-aio to nginx-extras. (Closes: #613175)
  + Removed split clients and user id modules from nginx-light.
* debian/conf/sites-available/default:
  + Fixed a minor typo ( s/Quickstart/QuickStart/ ). (Closes: #613355)
* debian/conf/mime.types:
  + Changed xml type to application/xhtml+xml. (Closes: #613851)
* debian/help/docs/fcgiwrap:
  + Removed Ubuntu specific line in docs. (Closes: #614987)
* debian/conf/sites-available/default:
  + Fixed a pointer to a file. (Closes: #614980)

[Kartik Mistry]
* debian/*.lintian-overrides:
  + Add Lintian overrides for nginx man page. We've manpage in nginx-common
    binary

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) agentzh */
 
2
 
 
3
#define DDEBUG 0
 
4
#include "ddebug.h"
 
5
 
 
6
#include "ngx_http_echo_sleep.h"
 
7
#include "ngx_http_echo_handler.h"
 
8
 
 
9
#include <nginx.h>
 
10
#include <ngx_log.h>
 
11
 
 
12
/* event handler for echo_sleep */
 
13
 
 
14
static void ngx_http_echo_post_sleep(ngx_http_request_t *r);
 
15
 
 
16
static void ngx_http_echo_sleep_cleanup(void *data);
 
17
 
 
18
 
 
19
ngx_int_t
 
20
ngx_http_echo_exec_echo_sleep(
 
21
        ngx_http_request_t *r, ngx_http_echo_ctx_t *ctx,
 
22
        ngx_array_t *computed_args)
 
23
{
 
24
    ngx_str_t                   *computed_arg;
 
25
    ngx_str_t                   *computed_arg_elts;
 
26
    float                        delay; /* in sec */
 
27
    ngx_http_cleanup_t          *cln;
 
28
 
 
29
    computed_arg_elts = computed_args->elts;
 
30
    computed_arg = &computed_arg_elts[0];
 
31
 
 
32
    delay = atof( (char*) computed_arg->data );
 
33
 
 
34
    if (delay < 0.001) { /* should be bigger than 1 msec */
 
35
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
 
36
                   "invalid sleep duration \"%V\"", &computed_arg_elts[0]);
 
37
 
 
38
        return NGX_HTTP_BAD_REQUEST;
 
39
    }
 
40
 
 
41
    dd("DELAY = %.02lf sec", delay);
 
42
 
 
43
    ngx_add_timer(&ctx->sleep, (ngx_msec_t) (1000 * delay));
 
44
 
 
45
    /* we don't check broken downstream connections
 
46
     * ourselves so even if the client shuts down
 
47
     * the connection prematurely, nginx will still
 
48
     * go on waiting for our timers to get properly
 
49
     * expired. However, we'd still register a
 
50
     * cleanup handler for completeness. */
 
51
 
 
52
    cln = ngx_http_cleanup_add(r, 0);
 
53
    if (cln == NULL) {
 
54
        return NGX_ERROR;
 
55
    }
 
56
 
 
57
    cln->handler = ngx_http_echo_sleep_cleanup;
 
58
    cln->data = r;
 
59
 
 
60
    return NGX_AGAIN;
 
61
}
 
62
 
 
63
 
 
64
static void
 
65
ngx_http_echo_post_sleep(ngx_http_request_t *r)
 
66
{
 
67
    ngx_http_echo_ctx_t         *ctx;
 
68
    /* ngx_int_t                    rc; */
 
69
 
 
70
    dd("entered echo post sleep...(r->done: %d)", r->done);
 
71
 
 
72
    dd("sleep: before get module ctx");
 
73
 
 
74
    ctx = ngx_http_get_module_ctx(r, ngx_http_echo_module);
 
75
 
 
76
    if (ctx == NULL) {
 
77
        return;
 
78
    }
 
79
 
 
80
    ctx->waiting = 0;
 
81
    ctx->done = 1;
 
82
 
 
83
    dd("sleep: after get module ctx");
 
84
 
 
85
    dd("timed out? %d", ctx->sleep.timedout);
 
86
    dd("timer set? %d", ctx->sleep.timer_set);
 
87
 
 
88
    if ( ! ctx->sleep.timedout ) {
 
89
        dd("HERE reached!");
 
90
        return;
 
91
    }
 
92
 
 
93
    ctx->sleep.timedout = 0;
 
94
 
 
95
    if (ctx->sleep.timer_set) {
 
96
        dd("deleting timer for echo_sleep");
 
97
 
 
98
        ngx_del_timer(&ctx->sleep);
 
99
    }
 
100
 
 
101
    /* r->write_event_handler = ngx_http_request_empty_handler; */
 
102
 
 
103
    ngx_http_echo_wev_handler(r);
 
104
}
 
105
 
 
106
 
 
107
void
 
108
ngx_http_echo_sleep_event_handler(ngx_event_t *ev)
 
109
{
 
110
    ngx_connection_t        *c;
 
111
    ngx_http_request_t      *r;
 
112
    ngx_http_log_ctx_t      *ctx;
 
113
 
 
114
    r = ev->data;
 
115
    c = r->connection;
 
116
 
 
117
    if (c->destroyed) {
 
118
        return;
 
119
    }
 
120
 
 
121
    ctx = c->log->data;
 
122
    ctx->current_request = r;
 
123
 
 
124
    /* XXX when r->done == 1 we should do cleaning immediately
 
125
     * and delete our timer and then quit. */
 
126
 
 
127
    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
 
128
            "echo sleep handler: \"%V?%V\"", &r->uri, &r->args);
 
129
 
 
130
    /*
 
131
    if (r->done) {
 
132
        return;
 
133
    }
 
134
    */
 
135
 
 
136
    ngx_http_echo_post_sleep(r);
 
137
 
 
138
#if defined(nginx_version)
 
139
 
 
140
    dd("before run posted requests");
 
141
 
 
142
    ngx_http_run_posted_requests(c);
 
143
 
 
144
    dd("after run posted requests");
 
145
 
 
146
#endif
 
147
 
 
148
}
 
149
 
 
150
 
 
151
ngx_int_t
 
152
ngx_http_echo_exec_echo_blocking_sleep(ngx_http_request_t *r,
 
153
        ngx_http_echo_ctx_t *ctx, ngx_array_t *computed_args)
 
154
{
 
155
    ngx_str_t                   *computed_arg;
 
156
    ngx_str_t                   *computed_arg_elts;
 
157
    float                       delay; /* in sec */
 
158
 
 
159
    computed_arg_elts = computed_args->elts;
 
160
    computed_arg = &computed_arg_elts[0];
 
161
 
 
162
    delay = atof( (char*) computed_arg->data );
 
163
 
 
164
    if (delay < 0.001) { /* should be bigger than 1 msec */
 
165
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
 
166
                   "invalid sleep duration \"%V\"", &computed_arg_elts[0]);
 
167
        return NGX_HTTP_BAD_REQUEST;
 
168
    }
 
169
 
 
170
    dd("blocking DELAY = %.02lf sec", delay);
 
171
 
 
172
    ngx_msleep((ngx_msec_t) (1000 * delay));
 
173
 
 
174
    return NGX_OK;
 
175
}
 
176
 
 
177
 
 
178
static void
 
179
ngx_http_echo_sleep_cleanup(void *data)
 
180
{
 
181
    ngx_http_request_t      *r = data;
 
182
    ngx_http_echo_ctx_t         *ctx;
 
183
 
 
184
    dd("echo sleep cleanup");
 
185
 
 
186
    ctx = ngx_http_get_module_ctx(r, ngx_http_echo_module);
 
187
    if (ctx == NULL) {
 
188
        return;
 
189
    }
 
190
 
 
191
    if (ctx->sleep.timer_set) {
 
192
        dd("cleanup: deleting timer for echo_sleep");
 
193
 
 
194
        ngx_del_timer(&ctx->sleep);
 
195
        return;
 
196
    }
 
197
 
 
198
    dd("cleanup: timer not set");
 
199
}
 
200