You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A module to reconcile [ngx_lua]'s cosockets and LuaSocket.
3
+
Graceful fallback to LuaSocket for [ngx_lua].
4
4
5
5
**Important note**: The use of LuaSocket inside ngx_lua is **strongly** discouraged due to the blocking nature of LuaSocket's `receive`. However, it does come handy at certain times when one is developing a lua-resty module and wants it to run in contexts that do not support cosockets (such as `init`). This module allows for a better compatibility between the APIs of both implementations, and should be used wisely.
6
6
@@ -24,23 +24,19 @@ local sock = socket.tcp()
24
24
localis_luasocket=getmetatable(sock) ==socket.luasocket_mt-- depends on surrounding context
25
25
26
26
localtimes, err=sock:getreusedtimes() -- 0 if underlying socket is LuaSocket
27
-
-- ...
28
27
29
28
sock:settimeout(1000) -- converted to seconds if LuaSocket
30
29
31
30
localok, err=sock:connect(host, port)
32
-
-- ...
33
31
34
32
localok, err=sock:sslhandshake(false, nil, false) -- cosocket signature, will use LuaSec if LuaSocket
35
-
-- ...
36
33
37
34
localok, err=sock:setkeepalive() -- close() if LuaSocket
38
-
-- ...
39
35
```
40
36
41
37
## Installation
42
38
43
-
This module is mainly intended to be copied and tweaked in a lua-resty library if its author is mad enough.
39
+
This module is mainly intended to be copied in a lua-resty library and eventually modified to one's needs (such as desired supported contexts).
0 commit comments