@@ -459,7 +459,19 @@ ngx_http_lua_socket_tcp(lua_State *L)
459
459
return luaL_error (L , "no ctx found" );
460
460
}
461
461
462
- ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_COSOCKET );
462
+ /* only a few events is suppported in init_worker_by_* */
463
+ if (ngx_http_lua_event_inited ) {
464
+ ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_COSOCKET );
465
+
466
+ } else if (ctx -> context & NGX_HTTP_LUA_CONTEXT_BLOCKED_COSOCKET ) {
467
+ return luaL_error (L , "API disabled in the context of %s except when " \
468
+ "using the event handling methods of poll, epoll " \
469
+ "or kqueue" ,
470
+ ngx_http_lua_context_name ((ctx )-> context ));
471
+
472
+ } else {
473
+ ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_YIELDABLE );
474
+ }
463
475
464
476
lua_createtable (L , 5 /* narr */ , 1 /* nrec */ );
465
477
lua_pushlightuserdata (L , ngx_http_lua_lightudata_mask (
@@ -904,7 +916,19 @@ ngx_http_lua_socket_tcp_connect(lua_State *L)
904
916
return luaL_error (L , "no ctx found" );
905
917
}
906
918
907
- ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_COSOCKET );
919
+ /* only a few events is suppported in init_worker_by_* */
920
+ if (ngx_http_lua_event_inited ) {
921
+ ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_COSOCKET );
922
+
923
+ } else if (ctx -> context & NGX_HTTP_LUA_CONTEXT_BLOCKED_COSOCKET ) {
924
+ return luaL_error (L , "API disabled in the context of %s except when " \
925
+ "using the event handling methods of poll, epoll " \
926
+ "or kqueue" ,
927
+ ngx_http_lua_context_name ((ctx )-> context ));
928
+
929
+ } else {
930
+ ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_YIELDABLE );
931
+ }
908
932
909
933
luaL_checktype (L , 1 , LUA_TTABLE );
910
934
@@ -1796,7 +1820,7 @@ ngx_http_lua_socket_tcp_sslhandshake(lua_State *L)
1796
1820
1797
1821
rc = ngx_ssl_handshake (c );
1798
1822
1799
- dd ("ngx_ssl_handshake returned %d" , (int ) rc );
1823
+ dd ("ngx_ssl_handshake returned %d" , (int ) rc );
1800
1824
1801
1825
if (rc == NGX_AGAIN ) {
1802
1826
if (ctx -> context & NGX_HTTP_LUA_CONTEXT_BLOCKED_COSOCKET ) {
0 commit comments