|
13 | 13 | #include "ngx_http_lua_socket_tcp.h"
|
14 | 14 | #include "ngx_http_lua_input_filters.h"
|
15 | 15 | #include "ngx_http_lua_util.h"
|
| 16 | +#include "ngx_http_lua_exception.h" |
16 | 17 | #include "ngx_http_lua_uthread.h"
|
17 | 18 | #include "ngx_http_lua_output.h"
|
18 | 19 | #include "ngx_http_lua_contentby.h"
|
@@ -5923,62 +5924,72 @@ ngx_http_lua_socket_push_input_data(ngx_http_request_t *r,
|
5923 | 5924 | size_t nbufs;
|
5924 | 5925 | luaL_Buffer luabuf;
|
5925 | 5926 |
|
5926 |
| - dd("bufs_in: %p, buf_in: %p", u->bufs_in, u->buf_in); |
| 5927 | + /* set Lua VM panic handler */ |
| 5928 | + lua_atpanic(L, ngx_http_lua_atpanic); |
5927 | 5929 |
|
5928 |
| - nbufs = 0; |
5929 |
| - ll = NULL; |
| 5930 | + NGX_LUA_EXCEPTION_TRY { |
5930 | 5931 |
|
5931 |
| - luaL_buffinit(L, &luabuf); |
| 5932 | + dd("bufs_in: %p, buf_in: %p", u->bufs_in, u->buf_in); |
5932 | 5933 |
|
5933 |
| - for (cl = u->bufs_in; cl; cl = cl->next) { |
5934 |
| - b = cl->buf; |
5935 |
| - chunk_size = b->last - b->pos; |
| 5934 | + nbufs = 0; |
| 5935 | + ll = NULL; |
| 5936 | + |
| 5937 | + luaL_buffinit(L, &luabuf); |
5936 | 5938 |
|
5937 |
| - dd("copying input data chunk from %p: \"%.*s\"", cl, |
5938 |
| - (int) chunk_size, b->pos); |
| 5939 | + for (cl = u->bufs_in; cl; cl = cl->next) { |
| 5940 | + b = cl->buf; |
| 5941 | + chunk_size = b->last - b->pos; |
5939 | 5942 |
|
5940 |
| - luaL_addlstring(&luabuf, (char *) b->pos, chunk_size); |
| 5943 | + dd("copying input data chunk from %p: \"%.*s\"", cl, |
| 5944 | + (int) chunk_size, b->pos); |
5941 | 5945 |
|
5942 |
| - if (cl->next) { |
5943 |
| - ll = &cl->next; |
5944 |
| - } |
| 5946 | + luaL_addlstring(&luabuf, (char *) b->pos, chunk_size); |
| 5947 | + |
| 5948 | + if (cl->next) { |
| 5949 | + ll = &cl->next; |
| 5950 | + } |
5945 | 5951 |
|
5946 | 5952 | #if (DDEBUG) || (NGX_DTRACE)
|
5947 |
| - size += chunk_size; |
| 5953 | + size += chunk_size; |
5948 | 5954 | #endif
|
5949 | 5955 |
|
5950 |
| - nbufs++; |
5951 |
| - } |
| 5956 | + nbufs++; |
| 5957 | + } |
5952 | 5958 |
|
5953 |
| - luaL_pushresult(&luabuf); |
| 5959 | + luaL_pushresult(&luabuf); |
5954 | 5960 |
|
5955 | 5961 | #if (DDEBUG)
|
5956 |
| - dd("size: %d, nbufs: %d", (int) size, (int) nbufs); |
| 5962 | + dd("size: %d, nbufs: %d", (int) size, (int) nbufs); |
5957 | 5963 | #endif
|
5958 | 5964 |
|
5959 | 5965 | #if (NGX_DTRACE)
|
5960 |
| - ngx_http_lua_probe_socket_tcp_receive_done(r, u, |
5961 |
| - (u_char *) lua_tostring(L, -1), |
5962 |
| - size); |
| 5966 | + ngx_http_lua_probe_socket_tcp_receive_done( |
| 5967 | + r, u, (u_char *) lua_tostring(L, -1), size); |
5963 | 5968 | #endif
|
5964 | 5969 |
|
5965 |
| - if (nbufs > 1 && ll) { |
5966 |
| - dd("recycle buffers: %d", (int) (nbufs - 1)); |
| 5970 | + if (nbufs > 1 && ll) { |
| 5971 | + dd("recycle buffers: %d", (int) (nbufs - 1)); |
5967 | 5972 |
|
5968 |
| - *ll = ctx->free_recv_bufs; |
5969 |
| - ctx->free_recv_bufs = u->bufs_in; |
5970 |
| - u->bufs_in = u->buf_in; |
5971 |
| - } |
| 5973 | + *ll = ctx->free_recv_bufs; |
| 5974 | + ctx->free_recv_bufs = u->bufs_in; |
| 5975 | + u->bufs_in = u->buf_in; |
| 5976 | + } |
5972 | 5977 |
|
5973 |
| - if (u->buffer.pos == u->buffer.last) { |
5974 |
| - dd("resetting u->buffer pos & last"); |
5975 |
| - u->buffer.pos = u->buffer.start; |
5976 |
| - u->buffer.last = u->buffer.start; |
5977 |
| - } |
| 5978 | + if (u->buffer.pos == u->buffer.last) { |
| 5979 | + dd("resetting u->buffer pos & last"); |
| 5980 | + u->buffer.pos = u->buffer.start; |
| 5981 | + u->buffer.last = u->buffer.start; |
| 5982 | + } |
5978 | 5983 |
|
5979 |
| - if (u->bufs_in) { |
5980 |
| - u->buf_in->buf->last = u->buffer.pos; |
5981 |
| - u->buf_in->buf->pos = u->buffer.pos; |
| 5984 | + if (u->bufs_in) { |
| 5985 | + u->buf_in->buf->last = u->buffer.pos; |
| 5986 | + u->buf_in->buf->pos = u->buffer.pos; |
| 5987 | + } |
| 5988 | + |
| 5989 | + } NGX_LUA_EXCEPTION_CATCH { |
| 5990 | + |
| 5991 | + dd("nginx execution restored"); |
| 5992 | + return NGX_ERROR; |
5982 | 5993 | }
|
5983 | 5994 |
|
5984 | 5995 | return NGX_OK;
|
|
0 commit comments