@@ -20,7 +20,7 @@ struct Module;
20
20
21
21
impl http:: HttpModule for Module {
22
22
fn module ( ) -> & ' static ngx_module_t {
23
- unsafe { & * :: core:: ptr:: addr_of!( ngx_http_async_module ) }
23
+ unsafe { & * :: core:: ptr:: addr_of!( ngx_http_tokio_module ) }
24
24
}
25
25
26
26
unsafe extern "C" fn postconfiguration ( cf : * mut ngx_conf_t ) -> ngx_int_t {
@@ -35,7 +35,7 @@ impl http::HttpModule for Module {
35
35
return core:: Status :: NGX_ERROR . into ( ) ;
36
36
}
37
37
// set an Access phase handler
38
- * h = Some ( async_access_handler ) ;
38
+ * h = Some ( tokio_access_handler ) ;
39
39
core:: Status :: NGX_OK . into ( )
40
40
}
41
41
}
@@ -49,19 +49,19 @@ unsafe impl HttpModuleLocationConf for Module {
49
49
type LocationConf = ModuleConfig ;
50
50
}
51
51
52
- static mut NGX_HTTP_ASYNC_COMMANDS : [ ngx_command_t ; 2 ] = [
52
+ static mut NGX_HTTP_TOKIO_COMMANDS : [ ngx_command_t ; 2 ] = [
53
53
ngx_command_t {
54
- name : ngx_string ! ( "async " ) ,
54
+ name : ngx_string ! ( "tokio " ) ,
55
55
type_ : ( NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1 ) as ngx_uint_t ,
56
- set : Some ( ngx_http_async_commands_set_enable ) ,
56
+ set : Some ( ngx_http_tokio_commands_set_enable ) ,
57
57
conf : NGX_HTTP_LOC_CONF_OFFSET ,
58
58
offset : 0 ,
59
59
post : std:: ptr:: null_mut ( ) ,
60
60
} ,
61
61
ngx_command_t:: empty ( ) ,
62
62
] ;
63
63
64
- static NGX_HTTP_ASYNC_MODULE_CTX : ngx_http_module_t = ngx_http_module_t {
64
+ static NGX_HTTP_TOKIO_MODULE_CTX : ngx_http_module_t = ngx_http_module_t {
65
65
preconfiguration : Some ( Module :: preconfiguration) ,
66
66
postconfiguration : Some ( Module :: postconfiguration) ,
67
67
create_main_conf : None ,
@@ -75,14 +75,14 @@ static NGX_HTTP_ASYNC_MODULE_CTX: ngx_http_module_t = ngx_http_module_t {
75
75
// Generate the `ngx_modules` table with exported modules.
76
76
// This feature is required to build a 'cdylib' dynamic module outside of the NGINX buildsystem.
77
77
#[ cfg( feature = "export-modules" ) ]
78
- ngx:: ngx_modules!( ngx_http_async_module ) ;
78
+ ngx:: ngx_modules!( ngx_http_tokio_module ) ;
79
79
80
80
#[ used]
81
81
#[ allow( non_upper_case_globals) ]
82
82
#[ cfg_attr( not( feature = "export-modules" ) , no_mangle) ]
83
- pub static mut ngx_http_async_module : ngx_module_t = ngx_module_t {
84
- ctx : std:: ptr:: addr_of!( NGX_HTTP_ASYNC_MODULE_CTX ) as _ ,
85
- commands : unsafe { & NGX_HTTP_ASYNC_COMMANDS [ 0 ] as * const _ as * mut _ } ,
83
+ pub static mut ngx_http_tokio_module : ngx_module_t = ngx_module_t {
84
+ ctx : std:: ptr:: addr_of!( NGX_HTTP_TOKIO_MODULE_CTX ) as _ ,
85
+ commands : unsafe { & NGX_HTTP_TOKIO_COMMANDS [ 0 ] as * const _ as * mut _ } ,
86
86
type_ : NGX_HTTP_MODULE as _ ,
87
87
..ngx_module_t:: default ( )
88
88
} ;
@@ -96,12 +96,12 @@ impl http::Merge for ModuleConfig {
96
96
}
97
97
}
98
98
99
- unsafe extern "C" fn check_async_work_done ( event : * mut ngx_event_t ) {
99
+ unsafe extern "C" fn check_tokio_work_done ( event : * mut ngx_event_t ) {
100
100
let ctx = ngx:: ngx_container_of!( event, RequestCTX , event) ;
101
101
let c: * mut ngx_connection_t = ( * event) . data . cast ( ) ;
102
102
103
103
if ( * ctx) . done . load ( Ordering :: Relaxed ) {
104
- // Triggering async_access_handler again
104
+ // Triggering tokio_access_handler again
105
105
ngx_post_event ( ( * c) . write , addr_of_mut ! ( ngx_posted_events) ) ;
106
106
} else {
107
107
// this doesn't have have good performance but works as a simple thread-safe example and
@@ -139,17 +139,17 @@ impl Drop for RequestCTX {
139
139
}
140
140
}
141
141
142
- http_request_handler ! ( async_access_handler , |request: & mut http:: Request | {
142
+ http_request_handler ! ( tokio_access_handler , |request: & mut http:: Request | {
143
143
let co = Module :: location_conf( request) . expect( "module config is none" ) ;
144
144
145
- ngx_log_debug_http!( request, "async module enabled: {}" , co. enable) ;
145
+ ngx_log_debug_http!( request, "tokio module enabled: {}" , co. enable) ;
146
146
147
147
if !co. enable {
148
148
return core:: Status :: NGX_DECLINED ;
149
149
}
150
150
151
151
if let Some ( ctx) =
152
- unsafe { request. get_module_ctx:: <RequestCTX >( & * addr_of!( ngx_http_async_module ) ) }
152
+ unsafe { request. get_module_ctx:: <RequestCTX >( & * addr_of!( ngx_http_tokio_module ) ) }
153
153
{
154
154
if !ctx. done. load( Ordering :: Relaxed ) {
155
155
return core:: Status :: NGX_AGAIN ;
@@ -162,10 +162,10 @@ http_request_handler!(async_access_handler, |request: &mut http::Request| {
162
162
if ctx. is_null( ) {
163
163
return core:: Status :: NGX_ERROR ;
164
164
}
165
- request. set_module_ctx( ctx. cast( ) , unsafe { & * addr_of!( ngx_http_async_module ) } ) ;
165
+ request. set_module_ctx( ctx. cast( ) , unsafe { & * addr_of!( ngx_http_tokio_module ) } ) ;
166
166
167
167
let ctx = unsafe { & mut * ctx } ;
168
- ctx. event. handler = Some ( check_async_work_done ) ;
168
+ ctx. event. handler = Some ( check_tokio_work_done ) ;
169
169
ctx. event. data = request. connection( ) . cast( ) ;
170
170
ctx. event. log = unsafe { ( * request. connection( ) ) . log } ;
171
171
unsafe { ngx_post_event( & mut ctx. event, addr_of_mut!( ngx_posted_next_events) ) } ;
@@ -174,7 +174,7 @@ http_request_handler!(async_access_handler, |request: &mut http::Request| {
174
174
let req = AtomicPtr :: new( request. into( ) ) ;
175
175
let done_flag = ctx. done. clone( ) ;
176
176
177
- let rt = ngx_http_async_runtime ( ) ;
177
+ let rt = ngx_http_tokio_runtime ( ) ;
178
178
ctx. task = Some ( rt. spawn( async move {
179
179
let start = Instant :: now( ) ;
180
180
tokio:: time:: sleep( std:: time:: Duration :: from_secs( 2 ) ) . await ;
@@ -183,7 +183,7 @@ http_request_handler!(async_access_handler, |request: &mut http::Request| {
183
183
// but this is just an example. proper way would be storing these headers in the request ctx
184
184
// and apply them when we get back to the nginx thread.
185
185
req. add_header_out(
186
- "X-Async -Time" ,
186
+ "X-Tokio -Time" ,
187
187
start. elapsed( ) . as_millis( ) . to_string( ) . as_str( ) ,
188
188
) ;
189
189
@@ -197,7 +197,7 @@ http_request_handler!(async_access_handler, |request: &mut http::Request| {
197
197
core:: Status :: NGX_AGAIN
198
198
} ) ;
199
199
200
- extern "C" fn ngx_http_async_commands_set_enable (
200
+ extern "C" fn ngx_http_tokio_commands_set_enable (
201
201
cf : * mut ngx_conf_t ,
202
202
_cmd : * mut ngx_command_t ,
203
203
conf : * mut c_void ,
@@ -208,7 +208,7 @@ extern "C" fn ngx_http_async_commands_set_enable(
208
208
let val = match args[ 1 ] . to_str ( ) {
209
209
Ok ( s) => s,
210
210
Err ( _) => {
211
- ngx_conf_log_error ! ( NGX_LOG_EMERG , cf, "`async ` argument is not utf-8 encoded" ) ;
211
+ ngx_conf_log_error ! ( NGX_LOG_EMERG , cf, "`tokio ` argument is not utf-8 encoded" ) ;
212
212
return ngx:: core:: NGX_CONF_ERROR ;
213
213
}
214
214
} ;
@@ -226,7 +226,7 @@ extern "C" fn ngx_http_async_commands_set_enable(
226
226
ngx:: core:: NGX_CONF_OK
227
227
}
228
228
229
- fn ngx_http_async_runtime ( ) -> & ' static Runtime {
229
+ fn ngx_http_tokio_runtime ( ) -> & ' static Runtime {
230
230
// Should not be called from the master process
231
231
assert_ne ! (
232
232
unsafe { ngx:: ffi:: ngx_process } ,
0 commit comments