Skip to content

Commit 4787d24

Browse files
committed
fixup: tokio.rs
1 parent 3f20fb4 commit 4787d24

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

examples/tokio.rs

Lines changed: 12 additions & 12 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,11 +49,11 @@ 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(),
@@ -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;
@@ -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)