13 #if defined(RESTINIO_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) 23 using file_descriptor_t = HANDLE;
24 using file_offset_t = std::uint64_t;
25 using file_size_t = std::uint64_t;
36 inline file_descriptor_t null_file_descriptor(){
return INVALID_HANDLE_VALUE; }
39 inline file_descriptor_t
40 open_file(
const char * file_path )
42 file_descriptor_t file_descriptor =
51 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
54 if( null_file_descriptor() == file_descriptor )
57 fmt::format(
"unable to openfile '{}': error({})", file_path, GetLastError() ) };
60 return file_descriptor;
64 template <
typename META >
66 get_file_meta( file_descriptor_t fd )
68 file_size_t fsize = 0;
69 std::chrono::system_clock::time_point flastmodified;
71 if( null_file_descriptor() != fd )
73 LARGE_INTEGER file_size;
75 if( GetFileSizeEx( fd, &file_size ) )
77 fsize =
static_cast< file_size_t >( file_size.QuadPart );
82 fmt::format(
"unable to get file size: error code:{}", GetLastError() ) };
86 if( GetFileTime( fd, NULL, NULL, &ftWrite ) )
91 constexpr std::uint64_t nanosec100_in_microsec = 10;
92 constexpr std::uint64_t epoch_difference_in_microsec =
93 11644473600ULL * 1000 *1000;
98 ull.LowPart = ftWrite.dwLowDateTime;
99 ull.HighPart = ftWrite.dwHighDateTime;
102 std::chrono::system_clock::time_point{
103 std::chrono::microseconds(
104 ull.QuadPart / nanosec100_in_microsec - epoch_difference_in_microsec ) };
110 "unable to get file last modification: error code:{}",
115 return META{ fsize, flastmodified};
120 close_file( file_descriptor_t fd )
130 #include <restinio/sendfile_defs_default.hpp>