@@ -461,7 +461,19 @@ ngx_http_lua_socket_tcp(lua_State *L)
461
461
return luaL_error (L , "no ctx found" );
462
462
}
463
463
464
- ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_COSOCKET );
464
+ /* only a few events is suppported in init_worker_by_* */
465
+ if (ngx_http_lua_event_inited ) {
466
+ ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_COSOCKET );
467
+
468
+ } else if (ctx -> context & NGX_HTTP_LUA_CONTEXT_BLOCKED_COSOCKET ) {
469
+ return luaL_error (L , "API disabled in the context of %s except when " \
470
+ "using the event handling methods of poll, epoll " \
471
+ "or kqueue" ,
472
+ ngx_http_lua_context_name ((ctx )-> context ));
473
+
474
+ } else {
475
+ ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_YIELDABLE );
476
+ }
465
477
466
478
lua_createtable (L , 5 /* narr */ , 1 /* nrec */ );
467
479
lua_pushlightuserdata (L , ngx_http_lua_lightudata_mask (
@@ -906,7 +918,19 @@ ngx_http_lua_socket_tcp_connect(lua_State *L)
906
918
return luaL_error (L , "no ctx found" );
907
919
}
908
920
909
- ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_COSOCKET );
921
+ /* only a few events is suppported in init_worker_by_* */
922
+ if (ngx_http_lua_event_inited ) {
923
+ ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_COSOCKET );
924
+
925
+ } else if (ctx -> context & NGX_HTTP_LUA_CONTEXT_BLOCKED_COSOCKET ) {
926
+ return luaL_error (L , "API disabled in the context of %s except when " \
927
+ "using the event handling methods of poll, epoll " \
928
+ "or kqueue" ,
929
+ ngx_http_lua_context_name ((ctx )-> context ));
930
+
931
+ } else {
932
+ ngx_http_lua_check_context (L , ctx , NGX_HTTP_LUA_CONTEXT_YIELDABLE );
933
+ }
910
934
911
935
luaL_checktype (L , 1 , LUA_TTABLE );
912
936
@@ -1805,7 +1829,7 @@ ngx_http_lua_socket_tcp_sslhandshake(lua_State *L)
1805
1829
1806
1830
rc = ngx_ssl_handshake (c );
1807
1831
1808
- dd ("ngx_ssl_handshake returned %d" , (int ) rc );
1832
+ dd ("ngx_ssl_handshake returned %d" , (int ) rc );
1809
1833
1810
1834
if (rc == NGX_AGAIN ) {
1811
1835
if (ctx -> context & NGX_HTTP_LUA_CONTEXT_BLOCKED_COSOCKET ) {
0 commit comments