Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a Custom 404 Page #517

Closed
ffreality opened this issue Apr 9, 2024 · 4 comments
Closed

Setting a Custom 404 Page #517

ffreality opened this issue Apr 9, 2024 · 4 comments

Comments

@ffreality
Copy link

ffreality commented Apr 9, 2024

Hi, I have some questions about LibHv after integrating it to Unreal Engine 5.

  1. what is the difference between server.start(); and server.run();

  2. If I use auto Callback_Router_Handler = [this](const HttpRequestPtr& Request, const HttpResponseWriterPtr& Response) {}; as callback

  • Should I use hv::async::cleanup(); even if I use server.stop() ?
    Because project crashes with that callback if I also use that async::cleanup() after restarting UE5 gameplay.
  • I can't use getter functions such as Request->get()->GetParams(); after restarting Unreal Engine 5 gameplay.
    It gives an error about freeing memory. So, I need to directly access variables like
    const hv::QueryParams Querries = this->RequestPtr->get()->query_params;
  1. After setting a static web site with router.Static("/", path_root), How can I set a custom 404 page ?
@ithewei
Copy link
Owner

ithewei commented Apr 9, 2024

1、HttpServer.run() will occupy current thread to run, but HttpServer.start() will create another thread to run.
2、Crash? Do you use /MD or /MT on windows? /MT may cause this case.
3、You can set HttpService::errorHandler to response a custom error page.

@ffreality
Copy link
Author

1、HttpServer.run() will occupy current thread to run, but HttpServer.start() will create another thread to run. 2、Crash? Do you use /MD or /MT on windows? /MT may cause this case. 3、You can set HttpService::errorHandler to response a custom error page.

I use /MD build on Windows. /MT build cause error with UE5.

You used server.setThreadNum(4); with server.run(); If run occupy current thread, what is the goal of giving thread number ?

@ithewei
Copy link
Owner

ithewei commented Apr 9, 2024

If you use server.setThreadNum(4); with server.run(); that will create 3 threads + current thread to run event loops,if server.start(), that will create 4 threads to run event loops, not occupy current thread.

@ffreality
Copy link
Author

ffreality commented Apr 14, 2024

  • I understand server.start() and .run() differences.

  • I solved error page workflow.

auto Callback_Router_Error = [this](const HttpContextPtr& Context)->int
{
	return Context->sendFile(TCHAR_TO_UTF8(*this->Server_Path_404));
};
this->HTTP_LVH_Router.errorHandler = Callback_Router_Error;

gave expected correct result.

Only problems are

  1. hv::async::cleanup(); gave crash after second start.
  2. getter functions gave FMEMORY_INLINE_FUNCTION_DECORATOR void FMemory::Free(void* Original) crash.

I think they are about Unreal Engine 5. Some more exprienced developers said sometimes there could be clashes between third party libraries' memory system and Unreal's.

But I commented out hv::async::cleanup(); and it works normal. So, no need to keep open this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants