Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.15k stars 93 forks source link

Compile error under Win32 in UNICODE mode. #19

Closed rcane closed 5 years ago

rcane commented 5 years ago

The open_file() function in sendfile_defs_win.h uses CreateFile to open the requested file path. This does not work if an application is compiled in unicode mode (i.e. UNICODE is defined). In this case CreateFile will be defined as CreateFileW and its first parameter will effectively be a wchar_t*.

There are two options to fix this. i) Just use CreateFileA (the ASCII version of the function) in either unicode and non-unicode mode. ii) Declare that the const char * parameter is a utf8-encoded string and convert it into utf16 in unicode mode.

Option i) is simple to implement but restricts sendfile to ASCII paths. Option ii) is what one would actually want but needs a conversion from utf8 to utf16 (this code needs come from somewhere).

eao197 commented 5 years ago

Hi!

Thanks for reporting this. We know about this issue but have no good solution for it yet.

eao197 commented 5 years ago

And it seems that nobody uses RESTinio on Windows with UNICODE enabled. Until now :)

So we have to address this issue somehow. But it'll take some time because there are holidays in our country from 5 to 9 of May.

rcane commented 5 years ago

I know about the hell you enter once you start trying to support unicode across platforms. ;-)

For now I simply changed the code to use CreateFileA. This does not solve the unicode problem but it also does not make it worse.