Skip to content

Commit 90d78bb

Browse files
committed
Merge pull request #6 from thibaultCha/fix/settimeout
fix(settimeout) handle nil timeout argument
2 parents cc10342 + 223b389 commit 90d78bb

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

lib/resty/socket.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ function luasocket_mt.getreusedtimes()
4949
end
5050

5151
function luasocket_mt:settimeout(t)
52-
self.sock:settimeout(t/1000)
52+
if t then
53+
t = t/1000
54+
end
55+
self.sock:settimeout(t)
5356
end
5457

5558
function luasocket_mt:setkeepalive()

t/03-compat.t

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,33 @@ could not receive: timeout
8585
8686
8787
88-
=== TEST 3: luasocket setkeepalive() compat (close)
88+
=== TEST 3: luasocket settimeout() nil
89+
--- wait: 1
90+
--- http_config eval
91+
"$t::Utils::HttpConfig"
92+
--- config
93+
location /t {
94+
return 200;
95+
96+
log_by_lua_block {
97+
local socket = require "resty.socket"
98+
local sock = socket.tcp()
99+
sock:settimeout() -- no errors
100+
ngx.log(ngx.INFO, "ok")
101+
}
102+
}
103+
--- request
104+
GET /t
105+
--- response_body
106+
107+
--- no_error_log
108+
[error]
109+
--- error_log
110+
ok
111+
112+
113+
114+
=== TEST 4: luasocket setkeepalive() compat (close)
89115
--- wait: 1
90116
--- http_config eval
91117
"$t::Utils::HttpConfig"
@@ -137,7 +163,7 @@ could not send after keepalive: closed
137163
138164
139165
140-
=== TEST 4: luasocket sslhandshake() compat
166+
=== TEST 5: luasocket sslhandshake() compat
141167
--- http_config eval
142168
"$t::Utils::HttpConfig"
143169
--- config

0 commit comments

Comments
 (0)