Skip to content

Commit

Permalink
Added SW_GLOBAL_HOOK_BEFORE_SERVER_CREATE hook type
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Aug 13, 2021
1 parent b5c647c commit 27fee7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/swoole_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ enum swGlobalHookType {
SW_GLOBAL_HOOK_AFTER_SERVER_SHUTDOWN,
SW_GLOBAL_HOOK_BEFORE_WORKER_STOP,
SW_GLOBAL_HOOK_ON_REACTOR_DESTROY,
SW_GLOBAL_HOOK_BEFORE_SERVER_CREATE,
SW_GLOBAL_HOOK_AFTER_SERVER_CREATE,
SW_GLOBAL_HOOK_END = SW_MAX_HOOK_TYPE - 1,
};

Expand Down
15 changes: 13 additions & 2 deletions src/server/master.cc
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,10 @@ int Server::create() {
return SW_ERR;
}

if (swoole_isset_hook(SW_GLOBAL_HOOK_BEFORE_SERVER_CREATE)) {
swoole_call_hook(SW_GLOBAL_HOOK_BEFORE_SERVER_CREATE, this);
}

session_list = (Session *) sw_shm_calloc(SW_SESSION_LIST_SIZE, sizeof(Session));
if (session_list == nullptr) {
swoole_error("sw_shm_calloc(%ld) for session_list failed", SW_SESSION_LIST_SIZE * sizeof(Session));
Expand Down Expand Up @@ -734,13 +738,20 @@ int Server::create() {
return SW_ERR;
}

int retval;
if (is_base_mode()) {
factory = new BaseFactory(this);
return create_reactor_processes();
retval = create_reactor_processes();
} else {
factory = new ProcessFactory(this);
return create_reactor_threads();
retval = create_reactor_threads();
}

if (swoole_isset_hook(SW_GLOBAL_HOOK_AFTER_SERVER_CREATE)) {
swoole_call_hook(SW_GLOBAL_HOOK_AFTER_SERVER_CREATE, this);
}

return retval;
}

void Server::clear_timer() {
Expand Down

0 comments on commit 27fee7f

Please sign in to comment.