Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
CPPHTTPLIB_NAMESPACE::detail::mmap Class Reference

Public Member Functions

 mmap (const char *path)
bool open (const char *path)
void close ()
bool is_open () const
size_t size () const
const char * data () const

Private Attributes

int fd_ = -1
size_t size_ = 0
void * addr_ = nullptr
bool is_open_empty_file = false

Constructor & Destructor Documentation

◆ mmap()

CPPHTTPLIB_NAMESPACE::detail::mmap::mmap ( const char * path)
inline
284589{ open(path); }

◆ ~mmap()

CPPHTTPLIB_NAMESPACE::detail::mmap::~mmap ( )
inline
284591{ close(); }

Member Function Documentation

◆ open()

bool CPPHTTPLIB_NAMESPACE::detail::mmap::open ( const char * path)
inline
284593 {
284594 close();
284595
284596#if defined(_WIN32)
284597#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0A00
284598 // Patch for Windows versions < 10
284599 // used old code from httplib v0.14.3
284600
284601 hFile_ = ::CreateFileA(
284602 path,
284603 GENERIC_READ,
284604 FILE_SHARE_READ,
284605 NULL,
284606 OPEN_EXISTING,
284607 FILE_ATTRIBUTE_NORMAL,
284608 NULL);
284609
284610 if (hFile_ == INVALID_HANDLE_VALUE) {
284611 return false;
284612 }
284613
284614 size_ = ::GetFileSize(hFile_, NULL);
284615
284616 hMapping_ = ::CreateFileMapping(
284617 hFile_,
284618 NULL,
284619 PAGE_READONLY,
284620 0,
284621 0,
284622 NULL);
284623
284624 if (hMapping_ == NULL) {
284625 close();
284626 return false;
284627 }
284628
284629 addr_ = ::MapViewOfFile(
284630 hMapping_,
284631 FILE_MAP_READ,
284632 0,
284633 0,
284634 0);
284635
284636 if (addr_ == NULL) {
284637 close();
284638 return false;
284639 }
284640
284641#else
284642 auto wpath = u8string_to_wstring(path);
284643 if (wpath.empty()) { return false; }
284644
284645 hFile_ = ::CreateFile2(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ,
284646 OPEN_EXISTING, NULL);
284647
284648 if (hFile_ == INVALID_HANDLE_VALUE) { return false; }
284649
284650 LARGE_INTEGER size{};
284651 if (!::GetFileSizeEx(hFile_, &size)) { return false; }
284652 // If the following line doesn't compile due to QuadPart, update Windows SDK.
284653 // See:
284654 // https://github.com/yhirose/cpp-httplib/issues/1903#issuecomment-2316520721
284655 if (static_cast<ULONGLONG>(size.QuadPart) >
284656 (std::numeric_limits<decltype(size_)>::max)()) {
284657 // `size_t` might be 32-bits, on 32-bits Windows.
284658 return false;
284659 }
284660 size_ = static_cast<size_t>(size.QuadPart);
284661
284662 hMapping_ =
284663 ::CreateFileMappingFromApp(hFile_, NULL, PAGE_READONLY, size_, NULL);
284664
284665 // Special treatment for an empty file...
284666 if (hMapping_ == NULL && size_ == 0) {
284667 close();
284668 is_open_empty_file = true;
284669 return true;
284670 }
284671
284672 if (hMapping_ == NULL) {
284673 close();
284674 return false;
284675 }
284676
284677 addr_ = ::MapViewOfFileFromApp(hMapping_, FILE_MAP_READ, 0, 0);
284678
284679 if (addr_ == nullptr) {
284680 close();
284681 return false;
284682 }
284683#endif
284684#else
284685 fd_ = ::open(path, O_RDONLY);
284686 if (fd_ == -1) { return false; }
284687
284688 struct stat sb;
284689 if (fstat(fd_, &sb) == -1) {
284690 close();
284691 return false;
284692 }
284693 size_ = static_cast<size_t>(sb.st_size);
284694
284695 addr_ = ::mmap(NULL, size_, PROT_READ, MAP_PRIVATE, fd_, 0);
284696
284697 // Special treatment for an empty file...
284698 if (addr_ == MAP_FAILED && size_ == 0) {
284699 close();
284700 is_open_empty_file = true;
284701 return false;
284702 }
284703#endif
284704
284705 return true;
284706}
static softfloat max()
GOpaque< Size > size(const GMat &src)

◆ close()

void CPPHTTPLIB_NAMESPACE::detail::mmap::close ( )
inline
284718 {
284719#if defined(_WIN32)
284720 if (addr_) {
284721 ::UnmapViewOfFile(addr_);
284722 addr_ = nullptr;
284723 }
284724
284725 if (hMapping_) {
284726 ::CloseHandle(hMapping_);
284727 hMapping_ = NULL;
284728 }
284729
284730 if (hFile_ != INVALID_HANDLE_VALUE) {
284731 ::CloseHandle(hFile_);
284732 hFile_ = INVALID_HANDLE_VALUE;
284733 }
284734
284735 is_open_empty_file = false;
284736#else
284737 if (addr_ != nullptr) {
284738 munmap(addr_, size_);
284739 addr_ = nullptr;
284740 }
284741
284742 if (fd_ != -1) {
284743 ::close(fd_);
284744 fd_ = -1;
284745 }
284746#endif
284747 size_ = 0;
284748}

◆ is_open()

bool CPPHTTPLIB_NAMESPACE::detail::mmap::is_open ( ) const
inline
284708 {
284709 return is_open_empty_file ? true : addr_ != nullptr;
284710}

◆ size()

size_t CPPHTTPLIB_NAMESPACE::detail::mmap::size ( ) const
inline
284712{ return size_; }

◆ data()

const char * CPPHTTPLIB_NAMESPACE::detail::mmap::data ( ) const
inline
284714 {
284715 return is_open_empty_file ? "" : static_cast<const char *>(addr_);
284716}

The documentation for this class was generated from the following file: