Permalink
Browse files

feature: tcpsock:connect(): allows the options_table argument being nil.

Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent 5fdbb56 commit 39783100f5b7e821dd929a9426c459e72dcf9361 @doujiang24 doujiang24 committed with agentzh Sep 3, 2016
Showing with 57 additions and 1 deletion.
  1. +6 −0 src/ngx_http_lua_socket_tcp.c
  2. +51 −1 t/058-tcp-socket.t
@@ -501,6 +501,12 @@ ngx_http_lua_socket_tcp_connect(lua_State *L)
n--;
}
+ /* the fourth argument is not a table */
+ if (n == 4) {
+ lua_pop(L, 1);
+ n--;
+ }
+
if (n == 3) {
port = luaL_checkinteger(L, 3);
View
@@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua;
repeat_each(2);
-plan tests => repeat_each() * 187;
+plan tests => repeat_each() * 190;
our $HtmlDir = html_dir;
@@ -3640,3 +3640,53 @@ failed to receive a line: closed []
close: 1 nil
--- error_log
lua http cleanup reuse
+
+
+
+=== TEST 60: options_table is nil
+--- config
+ location /t {
+ set $port $TEST_NGINX_MEMCACHED_PORT;
+
+ content_by_lua_block {
+ local sock = ngx.socket.tcp()
+ local port = ngx.var.port
+
+ local ok, err = sock:connect("127.0.0.1", port, nil)
+ if not ok then
+ ngx.say("failed to connect: ", err)
+ return
+ end
+
+ ngx.say("connected: ", ok)
+
+ local req = "flush_all\r\n"
+
+ local bytes, err = sock:send(req)
+ if not bytes then
+ ngx.say("failed to send request: ", err)
+ return
+ end
+ ngx.say("request sent: ", bytes)
+
+ local line, err, part = sock:receive()
+ if line then
+ ngx.say("received: ", line)
+
+ else
+ ngx.say("failed to receive a line: ", err, " [", part, "]")
+ end
+
+ ok, err = sock:close()
+ ngx.say("close: ", ok, " ", err)
+ }
+ }
+--- request
+GET /t
+--- response_body
+connected: 1
+request sent: 11
+received: OK
+close: 1 nil
+--- no_error_log
+[error]

0 comments on commit 3978310

Please sign in to comment.