~spuul/nginx/trunk

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/src/ngx_http_lua_timer.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-02-15 03:05:42 UTC
  • mfrom: (4.3.10 sid)
  • Revision ID: package-import@ubuntu.com-20140215030542-71ubtowl24vf7nfn
Tags: 1.4.5-1ubuntu1
* Resynchronise with Debian (LP: #1280511).  Remaining changes:
  - debian/patches/ubuntu-branding.patch:
    + Add Ubuntu branding to server_tokens.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    void        **srv_conf;
27
27
    void        **loc_conf;
28
28
 
29
 
    ngx_http_lua_main_conf_t    *lmcf;
 
29
    ngx_http_lua_main_conf_t          *lmcf;
 
30
    ngx_http_lua_vm_state_t           *vm_state;
 
31
 
30
32
} ngx_http_lua_timer_ctx_t;
31
33
 
32
34
 
54
56
{
55
57
    int                      nargs, co_ref;
56
58
    u_char                  *p;
57
 
    lua_State               *mt;  /* the main thread */
 
59
    lua_State               *vm;  /* the main thread */
58
60
    lua_State               *co;
59
61
    ngx_msec_t               delay;
60
62
    ngx_event_t             *ev;
61
63
    ngx_http_request_t      *r;
62
64
    ngx_connection_t        *saved_c = NULL;
 
65
    ngx_http_lua_ctx_t      *ctx;
63
66
#if 0
64
67
    ngx_http_connection_t   *hc;
65
68
#endif
81
84
    luaL_argcheck(L, lua_isfunction(L, 2) && !lua_iscfunction(L, 2), 2,
82
85
                 "Lua function expected");
83
86
 
84
 
    lua_pushlightuserdata(L, &ngx_http_lua_request_key);
85
 
    lua_rawget(L, LUA_GLOBALSINDEX);
86
 
    r = lua_touserdata(L, -1);
87
 
    lua_pop(L, 1);
88
 
 
 
87
    r = ngx_http_lua_get_req(L);
89
88
    if (r == NULL) {
90
89
        return luaL_error(L, "no request");
91
90
    }
92
91
 
93
 
    if (ngx_exiting) {
 
92
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
93
 
 
94
    if (ngx_exiting && delay > 0) {
94
95
        lua_pushnil(L);
95
96
        lua_pushliteral(L, "process exiting");
96
97
        return 2;
124
125
            return luaL_error(L, "no memory");
125
126
        }
126
127
 
127
 
        lmcf->watcher->fd = -2;  /* to work around the -1 check in
128
 
                                    ngx_worker_process_cycle */
 
128
        /* to work around the -1 check in ngx_worker_process_cycle: */
 
129
        lmcf->watcher->fd = (ngx_socket_t) -2;
 
130
 
129
131
        lmcf->watcher->idle = 1;
130
132
        lmcf->watcher->read->handler = ngx_http_lua_abort_pending_timers;
131
133
        lmcf->watcher->data = lmcf;
132
134
    }
133
135
 
134
 
    mt = lmcf->lua;
 
136
    vm = ngx_http_lua_get_lua_vm(r, ctx);
135
137
 
136
 
    co = lua_newthread(mt);
 
138
    co = lua_newthread(vm);
137
139
 
138
140
    /* L stack: time func [args] thread */
139
141
 
156
158
 
157
159
    dd("stack top: %d", lua_gettop(L));
158
160
 
159
 
    lua_xmove(mt, L, 1);    /* move coroutine from main thread to L */
 
161
    lua_xmove(vm, L, 1);    /* move coroutine from main thread to L */
160
162
 
161
163
    /* L stack: time func [args] thread */
162
 
    /* mt stack: empty */
 
164
    /* vm stack: empty */
163
165
 
164
166
    lua_pushvalue(L, 2);    /* copy entry function to top of L*/
165
167
 
221
223
    tctx->loc_conf = r->loc_conf;
222
224
    tctx->lmcf = lmcf;
223
225
 
 
226
    if (ctx && ctx->vm_state) {
 
227
        tctx->vm_state = ctx->vm_state;
 
228
        tctx->vm_state->count++;
 
229
 
 
230
    } else {
 
231
        tctx->vm_state = NULL;
 
232
    }
 
233
 
224
234
    ev->handler = ngx_http_lua_timer_handler;
225
235
    ev->data = tctx;
226
236
    ev->log = ngx_cycle->log;
245
255
    ngx_http_request_t      *r = NULL;
246
256
    ngx_http_lua_ctx_t      *ctx;
247
257
    ngx_http_cleanup_t      *cln;
 
258
    ngx_pool_cleanup_t      *pcln;
248
259
    ngx_http_log_ctx_t      *logctx;
249
260
 
250
261
    ngx_http_lua_timer_ctx_t         tctx;
286
297
        goto abort;
287
298
    }
288
299
 
289
 
    c->fd = -1;
 
300
    c->fd = (ngx_socket_t) -1;
290
301
 
291
302
    c->pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, c->log);
292
303
    if (c->pool == NULL) {
386
397
    }
387
398
#endif
388
399
 
 
400
    r->connection = c;
 
401
    r->main_conf = tctx.main_conf;
 
402
    r->srv_conf = tctx.srv_conf;
 
403
    r->loc_conf = tctx.loc_conf;
 
404
 
 
405
    dd("lmcf: %p", lmcf);
 
406
 
389
407
    ctx = ngx_http_lua_create_ctx(r);
390
408
    if (ctx == NULL) {
391
409
        goto abort;
392
410
    }
393
411
 
 
412
    if (tctx.vm_state) {
 
413
        ctx->vm_state = tctx.vm_state;
 
414
 
 
415
        pcln = ngx_pool_cleanup_add(r->pool, 0);
 
416
        if (pcln == NULL) {
 
417
            goto abort;
 
418
        }
 
419
 
 
420
        pcln->handler = ngx_http_lua_cleanup_vm;
 
421
        pcln->data = tctx.vm_state;
 
422
    }
 
423
 
394
424
    r->headers_in.content_length_n = 0;
395
425
    c->data = r;
396
426
#if 0
398
428
    r->http_connection = hc;
399
429
#endif
400
430
    r->signature = NGX_HTTP_MODULE;
401
 
    r->connection = c;
402
431
    r->main = r;
403
432
    r->count = 1;
404
433
 
411
440
    r->http_state = NGX_HTTP_PROCESS_REQUEST_STATE;
412
441
    r->discard_body = 1;
413
442
 
414
 
    r->main_conf = tctx.main_conf;
415
 
    r->srv_conf = tctx.srv_conf;
416
 
    r->loc_conf = tctx.loc_conf;
417
 
 
418
443
    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
419
444
    c->log->file = clcf->error_log->file;
420
445
    if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
425
450
 
426
451
    ctx->cur_co_ctx = &ctx->entry_co_ctx;
427
452
 
428
 
    L = lmcf->lua;
 
453
    L = ngx_http_lua_get_lua_vm(r, ctx);
429
454
 
430
455
    cln = ngx_http_cleanup_add(r, 0);
431
456
    if (cln == NULL) {
432
457
        goto abort;
433
458
    }
434
459
 
435
 
    cln->handler = ngx_http_lua_request_cleanup;
436
 
    cln->data = r;
 
460
    cln->handler = ngx_http_lua_request_cleanup_handler;
 
461
    cln->data = ctx;
437
462
    ctx->cleanup = &cln->handler;
438
463
 
439
464
    ctx->entered_content_phase = 1;
448
473
    dd("r connection: %p, log %p", r->connection, r->connection->log);
449
474
 
450
475
    /*  save the request in coroutine globals table */
451
 
    lua_pushvalue(tctx.co, LUA_GLOBALSINDEX);
452
 
    lua_pushlightuserdata(tctx.co, &ngx_http_lua_request_key);
453
 
    lua_pushlightuserdata(tctx.co, r);
454
 
    lua_rawset(tctx.co, -3);
455
 
    lua_pop(tctx.co, 1);
456
 
    /*  }}} */
 
476
    ngx_http_lua_set_req(tctx.co, r);
457
477
 
458
478
    lmcf->running_timers++;
459
479
 
476
496
 
477
497
    } else if (rc == NGX_DONE) {
478
498
        rc = ngx_http_lua_content_run_posted_threads(L, r, ctx, 1);
 
499
 
479
500
    } else {
480
501
        rc = NGX_OK;
481
502
    }
491
512
        lua_settop(tctx.co, 0);
492
513
    }
493
514
 
 
515
    if (tctx.vm_state) {
 
516
        ngx_http_lua_cleanup_vm(tctx.vm_state);
 
517
    }
 
518
 
494
519
    if (r && r->pool) {
495
520
        ngx_destroy_pool(r->pool);
496
521
    }
527
552
    ngx_http_lua_main_conf_t    *lmcf;
528
553
 
529
554
    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
530
 
                   "lua abort pending timers HERE");
 
555
                   "lua abort pending timers");
531
556
 
532
557
    c = ev->data;
533
558
    lmcf = c->data;
551
576
 
552
577
    ngx_free_connection(c);
553
578
 
554
 
    c->fd = -1;
 
579
    c->fd = (ngx_socket_t) -1;
555
580
 
556
581
    if (ngx_cycle->files) {
557
582
        ngx_cycle->files[0] = saved_c;
643
668
        ev->handler(ev);
644
669
    }
645
670
 
646
 
    if (lmcf->pending_timers) {
 
671
#if 0
 
672
    if (pending_timers) {
647
673
        ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
648
674
                      "lua pending timer counter got out of sync: %i",
649
 
                      lmcf->pending_timers);
 
675
                      pending_timers);
650
676
    }
 
677
#endif
651
678
}
652
679
 
653
680
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */