100.00% Lines (5/5) 100.00% Functions (3/3)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com)
3   // 3   //
4   // Distributed under the Boost Software License, Version 1.0. (See accompanying 4   // Distributed under the Boost Software License, Version 1.0. (See accompanying
5   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6   // 6   //
7   // Official repository: https://github.com/cppalliance/http 7   // Official repository: https://github.com/cppalliance/http
8   // 8   //
9   9  
10   #ifndef BOOST_HTTP_DETAIL_FILE_POSIX_HPP 10   #ifndef BOOST_HTTP_DETAIL_FILE_POSIX_HPP
11   #define BOOST_HTTP_DETAIL_FILE_POSIX_HPP 11   #define BOOST_HTTP_DETAIL_FILE_POSIX_HPP
12   12  
13   #include <boost/http/detail/config.hpp> 13   #include <boost/http/detail/config.hpp>
14   14  
15   #if ! defined(BOOST_HTTP_NO_POSIX_FILE) 15   #if ! defined(BOOST_HTTP_NO_POSIX_FILE)
16   # if ! defined(__APPLE__) && ! defined(__linux__) && ! defined(__FreeBSD__) && ! defined(__NetBSD__) 16   # if ! defined(__APPLE__) && ! defined(__linux__) && ! defined(__FreeBSD__) && ! defined(__NetBSD__)
17   # define BOOST_HTTP_NO_POSIX_FILE 17   # define BOOST_HTTP_NO_POSIX_FILE
18   # endif 18   # endif
19   #endif 19   #endif
20   20  
21   #if ! defined(BOOST_HTTP_USE_POSIX_FILE) 21   #if ! defined(BOOST_HTTP_USE_POSIX_FILE)
22   # if ! defined(BOOST_HTTP_NO_POSIX_FILE) 22   # if ! defined(BOOST_HTTP_NO_POSIX_FILE)
23   # define BOOST_HTTP_USE_POSIX_FILE 1 23   # define BOOST_HTTP_USE_POSIX_FILE 1
24   # else 24   # else
25   # define BOOST_HTTP_USE_POSIX_FILE 0 25   # define BOOST_HTTP_USE_POSIX_FILE 0
26   # endif 26   # endif
27   #endif 27   #endif
28   28  
29   #if BOOST_HTTP_USE_POSIX_FILE 29   #if BOOST_HTTP_USE_POSIX_FILE
30   30  
31   #include <boost/http/error.hpp> 31   #include <boost/http/error.hpp>
32   #include <boost/http/file_mode.hpp> 32   #include <boost/http/file_mode.hpp>
33   #include <boost/system/error_code.hpp> 33   #include <boost/system/error_code.hpp>
34   #include <cstdint> 34   #include <cstdint>
35   35  
36   namespace boost { 36   namespace boost {
37   namespace http { 37   namespace http {
38   namespace detail { 38   namespace detail {
39   39  
40   // Implementation of File for POSIX systems. 40   // Implementation of File for POSIX systems.
41   class file_posix 41   class file_posix
42   { 42   {
43   int fd_ = -1; 43   int fd_ = -1;
44   44  
45   BOOST_HTTP_DECL 45   BOOST_HTTP_DECL
46   static 46   static
47   int 47   int
48   native_close(int& fd); 48   native_close(int& fd);
49   49  
50   public: 50   public:
51   using native_handle_type = int; 51   using native_handle_type = int;
52   52  
53   BOOST_HTTP_DECL 53   BOOST_HTTP_DECL
54   ~file_posix(); 54   ~file_posix();
55   55  
HITCBC 56   1 file_posix() = default; 56   1 file_posix() = default;
57   57  
58   BOOST_HTTP_DECL 58   BOOST_HTTP_DECL
59   file_posix(file_posix&& other) noexcept; 59   file_posix(file_posix&& other) noexcept;
60   60  
61   BOOST_HTTP_DECL 61   BOOST_HTTP_DECL
62   file_posix& 62   file_posix&
63   operator=(file_posix&& other) noexcept; 63   operator=(file_posix&& other) noexcept;
64   64  
65   native_handle_type 65   native_handle_type
HITCBC 66   4 native_handle() const 66   4 native_handle() const
67   { 67   {
HITCBC 68   4 return fd_; 68   4 return fd_;
69   } 69   }
70   70  
71   BOOST_HTTP_DECL 71   BOOST_HTTP_DECL
72   void 72   void
73   native_handle(native_handle_type fd); 73   native_handle(native_handle_type fd);
74   74  
75   bool 75   bool
HITCBC 76   20 is_open() const 76   20 is_open() const
77   { 77   {
HITCBC 78   20 return fd_ != -1; 78   20 return fd_ != -1;
79   } 79   }
80   80  
81   BOOST_HTTP_DECL 81   BOOST_HTTP_DECL
82   void 82   void
83   close(system::error_code& ec); 83   close(system::error_code& ec);
84   84  
85   BOOST_HTTP_DECL 85   BOOST_HTTP_DECL
86   void 86   void
87   open(char const* path, file_mode mode, system::error_code& ec); 87   open(char const* path, file_mode mode, system::error_code& ec);
88   88  
89   BOOST_HTTP_DECL 89   BOOST_HTTP_DECL
90   std::uint64_t 90   std::uint64_t
91   size(system::error_code& ec) const; 91   size(system::error_code& ec) const;
92   92  
93   BOOST_HTTP_DECL 93   BOOST_HTTP_DECL
94   std::uint64_t 94   std::uint64_t
95   pos(system::error_code& ec) const; 95   pos(system::error_code& ec) const;
96   96  
97   BOOST_HTTP_DECL 97   BOOST_HTTP_DECL
98   void 98   void
99   seek(std::uint64_t offset, system::error_code& ec); 99   seek(std::uint64_t offset, system::error_code& ec);
100   100  
101   BOOST_HTTP_DECL 101   BOOST_HTTP_DECL
102   std::size_t 102   std::size_t
103   read(void* buffer, std::size_t n, system::error_code& ec); 103   read(void* buffer, std::size_t n, system::error_code& ec);
104   104  
105   BOOST_HTTP_DECL 105   BOOST_HTTP_DECL
106   std::size_t 106   std::size_t
107   write(void const* buffer, std::size_t n, system::error_code& ec); 107   write(void const* buffer, std::size_t n, system::error_code& ec);
108   }; 108   };
109   109  
110   } // detail 110   } // detail
111   } // http 111   } // http
112   } // boost 112   } // boost
113   113  
114   #endif 114   #endif
115   115  
116   #endif 116   #endif