nlib
AsyncFileIo.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_THREADING_ASYNCFILEIO_H_
4 #define INCLUDE_NN_NLIB_THREADING_ASYNCFILEIO_H_
5 
6 #include "nn/nlib/UniquePtr.h"
7 
8 NLIB_NAMESPACE_BEGIN
9 namespace threading {
10 
11 class AsyncFileIoService;
12 template <class R>
13 class Future;
14 
16  public:
17  enum Mode {
18  ASYNCFILEIO_READ = NLIB_FD_O_RDONLY,
19  ASYNCFILEIO_WRITE = NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC
20  };
21  static bool HasNativeAsyncFileIo() NLIB_NOEXCEPT;
24  errno_t Init() NLIB_NOEXCEPT;
25  errno_t Open(const char* path, unsigned int flags) NLIB_NOEXCEPT;
26  errno_t FdOpen(nlib_fd fd) NLIB_NOEXCEPT;
27  NLIB_ALWAYS_INLINE nlib_fd GetFd() const NLIB_NOEXCEPT { return m_Fd; }
28  errno_t Close() NLIB_NOEXCEPT;
29  errno_t Read(Future<size_t>* future, void* buf, size_t nbytes, nlib_offset ofs,
30  AsyncFileIoService* ioservice) NLIB_NOEXCEPT;
31  errno_t Read(size_t* readBytes, void* buf, size_t nbytes, nlib_offset ofs,
32  AsyncFileIoService* ioservice) NLIB_NOEXCEPT;
33  errno_t Write(Future<size_t>* future, const void* buf, size_t nbytes, nlib_offset ofs,
34  AsyncFileIoService* ioservice) NLIB_NOEXCEPT;
35  errno_t Write(size_t* writeBytes, const void* buf, size_t nbytes, nlib_offset ofs,
36  AsyncFileIoService* ioservice) NLIB_NOEXCEPT;
37  errno_t Cancel(AsyncFileIoService* ioservice) NLIB_NOEXCEPT;
38 
39  private:
40  nlib_fd m_Fd;
42 };
43 
44 struct AsyncFileIoServiceData;
46  public:
47  NLIB_VIS_PUBLIC AsyncFileIoService() NLIB_NOEXCEPT;
48  NLIB_VIS_PUBLIC ~AsyncFileIoService() NLIB_NOEXCEPT;
50 
51  private:
53  NLIB_DISALLOW_COPY_AND_ASSIGN(AsyncFileIoService);
54  friend class AsyncFileIo;
55 };
56 
57 } // namespace threading
58 NLIB_NAMESPACE_END
59 
60 #endif // INCLUDE_NN_NLIB_THREADING_ASYNCFILEIO_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Platform.h:2151
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:126
#define NLIB_FD_O_CREAT
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1020
Class that controls asynchronous file I/O.
Definition: AsyncFileIo.h:45
Defines that class that is corresponding to std::unique_ptr.
bool Write(BinaryWriter *w, T x)
You can write user-defined class objects by specializing this function template.
Definition: BinaryWriter.h:121
#define NLIB_FD_O_WRONLY
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1008
int nlib_fd
The original file descriptor of nlib (a 32-bit integer value).
Definition: Platform.h:1051
nlib_fd GetFd() const noexcept
Gets nlib_fd.
Definition: AsyncFileIo.h:27
#define NLIB_FD_O_TRUNC
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1026
Class that gets the output of a different thread executing in a thread safe manner. This class is similar to the std::shared_future class of C++11.
Definition: AsyncFileIo.h:13
#define NLIB_ALWAYS_INLINE
Indicates that the compiler is forced to perform inline expansion of functions.
Definition: Platform_unix.h:59
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:51
bool Read(BinaryReader *r, T *x)
You can read to user-defined class objects by specializing this function template.
Definition: BinaryReader.h:158
int64_t nlib_offset
The offset to the file. A 64-bit integer.
Definition: Platform.h:1050
Class that wraps asynchronous file I/O.
Definition: AsyncFileIo.h:15
#define NLIB_FD_O_RDONLY
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1002
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:24