Skip to content

Commit 22fdab4

Browse files
committed
fixup: tokio.rs
1 parent 3f20fb4 commit 22fdab4

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

examples/t/tokio.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ $t->run();
5151

5252
###############################################################################
5353

54-
like(http_get('/index.html'), qr/X-Async-Time:/, 'async handler');
54+
like(http_get('/index.html'), qr/X-Tokio-Time:/, 'tokio handler');
5555

5656
###############################################################################

examples/tokio.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl http::HttpModule for Module {
3535
return core::Status::NGX_ERROR.into();
3636
}
3737
// set an Access phase handler
38-
*h = Some(async_access_handler);
38+
*h = Some(tokio_access_handler);
3939
core::Status::NGX_OK.into()
4040
}
4141
}
@@ -49,19 +49,19 @@ unsafe impl HttpModuleLocationConf for Module {
4949
type LocationConf = ModuleConfig;
5050
}
5151

52-
static mut NGX_HTTP_ASYNC_COMMANDS: [ngx_command_t; 2] = [
52+
static mut NGX_HTTP_TOKIO_COMMANDS: [ngx_command_t; 2] = [
5353
ngx_command_t {
5454
name: ngx_string!("tokio"),
5555
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),
5757
conf: NGX_HTTP_LOC_CONF_OFFSET,
5858
offset: 0,
5959
post: std::ptr::null_mut(),
6060
},
6161
ngx_command_t::empty(),
6262
];
6363

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 {
6565
preconfiguration: Some(Module::preconfiguration),
6666
postconfiguration: Some(Module::postconfiguration),
6767
create_main_conf: None,
@@ -81,8 +81,8 @@ ngx::ngx_modules!(ngx_http_tokio_module);
8181
#[allow(non_upper_case_globals)]
8282
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
8383
pub static mut ngx_http_tokio_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 _ },
84+
ctx: std::ptr::addr_of!(NGX_HTTP_TOKIO_MODULE_CTX) as _,
85+
commands: unsafe { &NGX_HTTP_TOKIO_COMMANDS[0] as *const _ as *mut _ },
8686
type_: NGX_HTTP_MODULE as _,
8787
..ngx_module_t::default()
8888
};
@@ -96,12 +96,12 @@ impl http::Merge for ModuleConfig {
9696
}
9797
}
9898

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) {
100100
let ctx = ngx::ngx_container_of!(event, RequestCTX, event);
101101
let c: *mut ngx_connection_t = (*event).data.cast();
102102

103103
if (*ctx).done.load(Ordering::Relaxed) {
104-
// Triggering async_access_handler again
104+
// Triggering tokio_access_handler again
105105
ngx_post_event((*c).write, addr_of_mut!(ngx_posted_events));
106106
} else {
107107
// this doesn't have have good performance but works as a simple thread-safe example and
@@ -139,10 +139,10 @@ impl Drop for RequestCTX {
139139
}
140140
}
141141

142-
http_request_handler!(async_access_handler, |request: &mut http::Request| {
142+
http_request_handler!(tokio_access_handler, |request: &mut http::Request| {
143143
let co = Module::location_conf(request).expect("module config is none");
144144

145-
ngx_log_debug_http!(request, "async module enabled: {}", co.enable);
145+
ngx_log_debug_http!(request, "tokio module enabled: {}", co.enable);
146146

147147
if !co.enable {
148148
return core::Status::NGX_DECLINED;
@@ -165,7 +165,7 @@ http_request_handler!(async_access_handler, |request: &mut http::Request| {
165165
request.set_module_ctx(ctx.cast(), unsafe { &*addr_of!(ngx_http_tokio_module) });
166166

167167
let ctx = unsafe { &mut *ctx };
168-
ctx.event.handler = Some(check_async_work_done);
168+
ctx.event.handler = Some(check_tokio_work_done);
169169
ctx.event.data = request.connection().cast();
170170
ctx.event.log = unsafe { (*request.connection()).log };
171171
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| {
174174
let req = AtomicPtr::new(request.into());
175175
let done_flag = ctx.done.clone();
176176

177-
let rt = ngx_http_async_runtime();
177+
let rt = ngx_http_tokio_runtime();
178178
ctx.task = Some(rt.spawn(async move {
179179
let start = Instant::now();
180180
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
@@ -183,7 +183,7 @@ http_request_handler!(async_access_handler, |request: &mut http::Request| {
183183
// but this is just an example. proper way would be storing these headers in the request ctx
184184
// and apply them when we get back to the nginx thread.
185185
req.add_header_out(
186-
"X-Async-Time",
186+
"X-Tokio-Time",
187187
start.elapsed().as_millis().to_string().as_str(),
188188
);
189189

@@ -197,7 +197,7 @@ http_request_handler!(async_access_handler, |request: &mut http::Request| {
197197
core::Status::NGX_AGAIN
198198
});
199199

200-
extern "C" fn ngx_http_async_commands_set_enable(
200+
extern "C" fn ngx_http_tokio_commands_set_enable(
201201
cf: *mut ngx_conf_t,
202202
_cmd: *mut ngx_command_t,
203203
conf: *mut c_void,
@@ -208,7 +208,7 @@ extern "C" fn ngx_http_async_commands_set_enable(
208208
let val = match args[1].to_str() {
209209
Ok(s) => s,
210210
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");
212212
return ngx::core::NGX_CONF_ERROR;
213213
}
214214
};
@@ -226,7 +226,7 @@ extern "C" fn ngx_http_async_commands_set_enable(
226226
ngx::core::NGX_CONF_OK
227227
}
228228

229-
fn ngx_http_async_runtime() -> &'static Runtime {
229+
fn ngx_http_tokio_runtime() -> &'static Runtime {
230230
// Should not be called from the master process
231231
assert_ne!(
232232
unsafe { ngx::ffi::ngx_process },

0 commit comments

Comments
 (0)