-
Notifications
You must be signed in to change notification settings - Fork 18
/
stream-lua-readpartial.patch
59 lines (56 loc) · 1.93 KB
/
stream-lua-readpartial.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
diff --git a/src/ngx_stream_lua_socket_tcp.c b/src/ngx_stream_lua_socket_tcp.c
index 4680811..4da1ac6 100644
--- a/src/ngx_stream_lua_socket_tcp.c
+++ b/src/ngx_stream_lua_socket_tcp.c
@@ -88,6 +88,7 @@ static int ngx_stream_lua_socket_write_error_retval_handler(
ngx_stream_session_t *s, ngx_stream_lua_socket_tcp_upstream_t *u,
lua_State *L);
static ngx_int_t ngx_stream_lua_socket_read_all(void *data, ssize_t bytes);
+static ngx_int_t ngx_stream_lua_socket_read_partial(void *data, ssize_t bytes);
static ngx_int_t ngx_stream_lua_socket_read_until(void *data, ssize_t bytes);
static ngx_int_t ngx_stream_lua_socket_read_chunk(void *data, ssize_t bytes);
static int ngx_stream_lua_socket_tcp_receiveuntil(lua_State *L);
@@ -1736,6 +1737,10 @@ ngx_stream_lua_socket_tcp_receive(lua_State *L)
u->input_filter = ngx_stream_lua_socket_read_all;
break;
+ case 'p':
+ u->input_filter = ngx_stream_lua_socket_read_partial;
+ break;
+
default:
return luaL_argerror(L, 2, "bad pattern argument");
break;
@@ -1918,6 +1923,35 @@ ngx_stream_lua_socket_read_all(void *data, ssize_t bytes)
static ngx_int_t
+ngx_stream_lua_socket_read_partial(void *data, ssize_t bytes)
+{
+ ngx_stream_lua_socket_tcp_upstream_t *u = data;
+
+ ngx_buf_t *b;
+#if (NGX_DEBUG)
+ ngx_stream_session_t *s;
+
+ s = u->request;
+#endif
+
+ ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0,
+ "stream lua tcp socket read partial");
+
+ if (bytes == 0) {
+ u->ft_type |= NGX_STREAM_LUA_SOCKET_FT_CLOSED;
+ return NGX_ERROR;
+ }
+
+ b = &u->buffer;
+
+ u->buf_in->buf->last += bytes;
+ b->pos += bytes;
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
ngx_stream_lua_socket_read_line(void *data, ssize_t bytes)
{
ngx_stream_lua_socket_tcp_upstream_t *u = data;