|
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" |
@@ -5912,62 +5913,72 @@ ngx_http_lua_socket_push_input_data(ngx_http_request_t *r, |
5912 | 5913 | size_t nbufs; |
5913 | 5914 | luaL_Buffer luabuf; |
5914 | 5915 |
|
5915 | | - dd("bufs_in: %p, buf_in: %p", u->bufs_in, u->buf_in); |
| 5916 | + /* set Lua VM panic handler */ |
| 5917 | + lua_atpanic(L, ngx_http_lua_atpanic); |
5916 | 5918 |
|
5917 | | - nbufs = 0; |
5918 | | - ll = NULL; |
| 5919 | + NGX_LUA_EXCEPTION_TRY { |
5919 | 5920 |
|
5920 | | - luaL_buffinit(L, &luabuf); |
| 5921 | + dd("bufs_in: %p, buf_in: %p", u->bufs_in, u->buf_in); |
5921 | 5922 |
|
5922 | | - for (cl = u->bufs_in; cl; cl = cl->next) { |
5923 | | - b = cl->buf; |
5924 | | - chunk_size = b->last - b->pos; |
| 5923 | + nbufs = 0; |
| 5924 | + ll = NULL; |
| 5925 | + |
| 5926 | + luaL_buffinit(L, &luabuf); |
5925 | 5927 |
|
5926 | | - dd("copying input data chunk from %p: \"%.*s\"", cl, |
5927 | | - (int) chunk_size, b->pos); |
| 5928 | + for (cl = u->bufs_in; cl; cl = cl->next) { |
| 5929 | + b = cl->buf; |
| 5930 | + chunk_size = b->last - b->pos; |
5928 | 5931 |
|
5929 | | - luaL_addlstring(&luabuf, (char *) b->pos, chunk_size); |
| 5932 | + dd("copying input data chunk from %p: \"%.*s\"", cl, |
| 5933 | + (int) chunk_size, b->pos); |
5930 | 5934 |
|
5931 | | - if (cl->next) { |
5932 | | - ll = &cl->next; |
5933 | | - } |
| 5935 | + luaL_addlstring(&luabuf, (char *) b->pos, chunk_size); |
| 5936 | + |
| 5937 | + if (cl->next) { |
| 5938 | + ll = &cl->next; |
| 5939 | + } |
5934 | 5940 |
|
5935 | 5941 | #if (DDEBUG) || (NGX_DTRACE) |
5936 | | - size += chunk_size; |
| 5942 | + size += chunk_size; |
5937 | 5943 | #endif |
5938 | 5944 |
|
5939 | | - nbufs++; |
5940 | | - } |
| 5945 | + nbufs++; |
| 5946 | + } |
5941 | 5947 |
|
5942 | | - luaL_pushresult(&luabuf); |
| 5948 | + luaL_pushresult(&luabuf); |
5943 | 5949 |
|
5944 | 5950 | #if (DDEBUG) |
5945 | | - dd("size: %d, nbufs: %d", (int) size, (int) nbufs); |
| 5951 | + dd("size: %d, nbufs: %d", (int) size, (int) nbufs); |
5946 | 5952 | #endif |
5947 | 5953 |
|
5948 | 5954 | #if (NGX_DTRACE) |
5949 | | - ngx_http_lua_probe_socket_tcp_receive_done(r, u, |
5950 | | - (u_char *) lua_tostring(L, -1), |
5951 | | - size); |
| 5955 | + ngx_http_lua_probe_socket_tcp_receive_done( |
| 5956 | + r, u, (u_char *) lua_tostring(L, -1), size); |
5952 | 5957 | #endif |
5953 | 5958 |
|
5954 | | - if (nbufs > 1 && ll) { |
5955 | | - dd("recycle buffers: %d", (int) (nbufs - 1)); |
| 5959 | + if (nbufs > 1 && ll) { |
| 5960 | + dd("recycle buffers: %d", (int) (nbufs - 1)); |
5956 | 5961 |
|
5957 | | - *ll = ctx->free_recv_bufs; |
5958 | | - ctx->free_recv_bufs = u->bufs_in; |
5959 | | - u->bufs_in = u->buf_in; |
5960 | | - } |
| 5962 | + *ll = ctx->free_recv_bufs; |
| 5963 | + ctx->free_recv_bufs = u->bufs_in; |
| 5964 | + u->bufs_in = u->buf_in; |
| 5965 | + } |
5961 | 5966 |
|
5962 | | - if (u->buffer.pos == u->buffer.last) { |
5963 | | - dd("resetting u->buffer pos & last"); |
5964 | | - u->buffer.pos = u->buffer.start; |
5965 | | - u->buffer.last = u->buffer.start; |
5966 | | - } |
| 5967 | + if (u->buffer.pos == u->buffer.last) { |
| 5968 | + dd("resetting u->buffer pos & last"); |
| 5969 | + u->buffer.pos = u->buffer.start; |
| 5970 | + u->buffer.last = u->buffer.start; |
| 5971 | + } |
5967 | 5972 |
|
5968 | | - if (u->bufs_in) { |
5969 | | - u->buf_in->buf->last = u->buffer.pos; |
5970 | | - u->buf_in->buf->pos = u->buffer.pos; |
| 5973 | + if (u->bufs_in) { |
| 5974 | + u->buf_in->buf->last = u->buffer.pos; |
| 5975 | + u->buf_in->buf->pos = u->buffer.pos; |
| 5976 | + } |
| 5977 | + |
| 5978 | + } NGX_LUA_EXCEPTION_CATCH { |
| 5979 | + |
| 5980 | + dd("nginx execution restored"); |
| 5981 | + return NGX_ERROR; |
5971 | 5982 | } |
5972 | 5983 | } |
5973 | 5984 |
|
|
0 commit comments