2
3
6
7
8
9
19#if defined(RESTINIO_ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
27
29using file_descriptor_t = HANDLE;
30using file_offset_t = std::uint64_t;
31using file_size_t = std::uint64_t;
35
36
37
38
39
43inline file_descriptor_t null_file_descriptor(){
return INVALID_HANDLE_VALUE; }
47inline file_descriptor_t
48open_file(
const char * file_path )
50 file_descriptor_t file_descriptor =
59 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
62 if( null_file_descriptor() == file_descriptor )
66 RESTINIO_FMT_FORMAT_STRING(
"unable to openfile '{}': error({})" ),
67 file_path, GetLastError() )
71 return file_descriptor;
75
76
77
78
79
80
81
82
83
84
85
86
88inline file_descriptor_t
89open_file(
const std::filesystem::path & file_path )
91 const auto wide_file_path = file_path.wstring();
92 file_descriptor_t file_descriptor =
95 wide_file_path.c_str(),
100 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
103 if( null_file_descriptor() == file_descriptor )
112 RESTINIO_FMT_FORMAT_STRING(
113 "open_file(std::filesystem::path) "
114 "unable to openfile: error({})" ),
119 return file_descriptor;
124template <
typename META >
127get_file_meta( file_descriptor_t fd )
129 file_size_t fsize = 0;
130 std::chrono::system_clock::time_point flastmodified;
132 if( null_file_descriptor() != fd )
134 LARGE_INTEGER file_size;
136 if( GetFileSizeEx( fd, &file_size ) )
138 fsize =
static_cast< file_size_t >( file_size.QuadPart );
144 RESTINIO_FMT_FORMAT_STRING(
145 "unable to get file size: error code:{}" ),
151 if( GetFileTime( fd, NULL, NULL, &ftWrite ) )
156 constexpr std::uint64_t nanosec100_in_microsec = 10;
157 constexpr std::uint64_t epoch_difference_in_microsec =
158 11644473600ULL * 1000 *1000;
163 ull.LowPart = ftWrite.dwLowDateTime;
164 ull.HighPart = ftWrite.dwHighDateTime;
167 std::chrono::system_clock::time_point{
168 std::chrono::microseconds(
169 ull.QuadPart / nanosec100_in_microsec - epoch_difference_in_microsec ) };
175 RESTINIO_FMT_FORMAT_STRING(
176 "unable to get file last modification: error code:{}" ),
182 return META{ fsize, flastmodified};
187close_file( file_descriptor_t fd )
197#include <restinio/sendfile_defs_default.hpp>