123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- #ifndef ASIO_DETAIL_WIN_IOCP_FILE_SERVICE_HPP
- #define ASIO_DETAIL_WIN_IOCP_FILE_SERVICE_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include "asio/detail/config.hpp"
- #if defined(ASIO_HAS_IOCP) && defined(ASIO_HAS_FILE)
- #include <string>
- #include "asio/detail/cstdint.hpp"
- #include "asio/detail/win_iocp_handle_service.hpp"
- #include "asio/error.hpp"
- #include "asio/execution_context.hpp"
- #include "asio/file_base.hpp"
- #include "asio/detail/push_options.hpp"
- namespace asio {
- namespace detail {
- class win_iocp_file_service :
- public execution_context_service_base<win_iocp_file_service>
- {
- public:
-
- typedef win_iocp_handle_service::native_handle_type native_handle_type;
-
- class implementation_type : win_iocp_handle_service::implementation_type
- {
- private:
-
- friend class win_iocp_file_service;
- uint64_t offset_;
- bool is_stream_;
- };
-
- ASIO_DECL win_iocp_file_service(execution_context& context);
-
- ASIO_DECL void shutdown();
-
- void construct(implementation_type& impl)
- {
- handle_service_.construct(impl);
- impl.offset_ = 0;
- impl.is_stream_ = false;
- }
-
- void move_construct(implementation_type& impl,
- implementation_type& other_impl)
- {
- handle_service_.move_construct(impl, other_impl);
- impl.offset_ = other_impl.offset_;
- impl.is_stream_ = other_impl.is_stream_;
- other_impl.offset_ = 0;
- }
-
- void move_assign(implementation_type& impl,
- win_iocp_file_service& other_service,
- implementation_type& other_impl)
- {
- handle_service_.move_assign(impl,
- other_service.handle_service_, other_impl);
- impl.offset_ = other_impl.offset_;
- impl.is_stream_ = other_impl.is_stream_;
- other_impl.offset_ = 0;
- }
-
- void destroy(implementation_type& impl)
- {
- handle_service_.destroy(impl);
- }
-
- void set_is_stream(implementation_type& impl, bool is_stream)
- {
- impl.is_stream_ = is_stream;
- }
-
- ASIO_DECL asio::error_code open(implementation_type& impl,
- const char* path, file_base::flags open_flags,
- asio::error_code& ec);
-
- asio::error_code assign(implementation_type& impl,
- const native_handle_type& native_handle,
- asio::error_code& ec)
- {
- return handle_service_.assign(impl, native_handle, ec);
- }
-
- bool is_open(const implementation_type& impl) const
- {
- return handle_service_.is_open(impl);
- }
-
- asio::error_code close(implementation_type& impl,
- asio::error_code& ec)
- {
- return handle_service_.close(impl, ec);
- }
-
- native_handle_type native_handle(const implementation_type& impl) const
- {
- return handle_service_.native_handle(impl);
- }
-
- native_handle_type release(implementation_type& impl,
- asio::error_code& ec)
- {
- return handle_service_.release(impl, ec);
- }
-
- asio::error_code cancel(implementation_type& impl,
- asio::error_code& ec)
- {
- return handle_service_.cancel(impl, ec);
- }
-
- ASIO_DECL uint64_t size(const implementation_type& impl,
- asio::error_code& ec) const;
-
- ASIO_DECL asio::error_code resize(implementation_type& impl,
- uint64_t n, asio::error_code& ec);
-
- ASIO_DECL asio::error_code sync_all(implementation_type& impl,
- asio::error_code& ec);
-
- ASIO_DECL asio::error_code sync_data(implementation_type& impl,
- asio::error_code& ec);
-
- ASIO_DECL uint64_t seek(implementation_type& impl, int64_t offset,
- file_base::seek_basis whence, asio::error_code& ec);
-
- template <typename ConstBufferSequence>
- size_t write_some(implementation_type& impl,
- const ConstBufferSequence& buffers, asio::error_code& ec)
- {
- uint64_t offset = impl.offset_;
- impl.offset_ += asio::buffer_size(buffers);
- return handle_service_.write_some_at(impl, offset, buffers, ec);
- }
-
-
- template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
- void async_write_some(implementation_type& impl,
- const ConstBufferSequence& buffers,
- Handler& handler, const IoExecutor& io_ex)
- {
- uint64_t offset = impl.offset_;
- impl.offset_ += asio::buffer_size(buffers);
- handle_service_.async_write_some_at(impl, offset, buffers, handler, io_ex);
- }
-
-
- template <typename ConstBufferSequence>
- size_t write_some_at(implementation_type& impl, uint64_t offset,
- const ConstBufferSequence& buffers, asio::error_code& ec)
- {
- return handle_service_.write_some_at(impl, offset, buffers, ec);
- }
-
-
- template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
- void async_write_some_at(implementation_type& impl,
- uint64_t offset, const ConstBufferSequence& buffers,
- Handler& handler, const IoExecutor& io_ex)
- {
- handle_service_.async_write_some_at(impl, offset, buffers, handler, io_ex);
- }
-
- template <typename MutableBufferSequence>
- size_t read_some(implementation_type& impl,
- const MutableBufferSequence& buffers, asio::error_code& ec)
- {
- uint64_t offset = impl.offset_;
- impl.offset_ += asio::buffer_size(buffers);
- return handle_service_.read_some_at(impl, offset, buffers, ec);
- }
-
-
- template <typename MutableBufferSequence,
- typename Handler, typename IoExecutor>
- void async_read_some(implementation_type& impl,
- const MutableBufferSequence& buffers,
- Handler& handler, const IoExecutor& io_ex)
- {
- uint64_t offset = impl.offset_;
- impl.offset_ += asio::buffer_size(buffers);
- handle_service_.async_read_some_at(impl, offset, buffers, handler, io_ex);
- }
-
- template <typename MutableBufferSequence>
- size_t read_some_at(implementation_type& impl, uint64_t offset,
- const MutableBufferSequence& buffers, asio::error_code& ec)
- {
- return handle_service_.read_some_at(impl, offset, buffers, ec);
- }
-
-
- template <typename MutableBufferSequence,
- typename Handler, typename IoExecutor>
- void async_read_some_at(implementation_type& impl,
- uint64_t offset, const MutableBufferSequence& buffers,
- Handler& handler, const IoExecutor& io_ex)
- {
- handle_service_.async_read_some_at(impl, offset, buffers, handler, io_ex);
- }
- private:
-
- win_iocp_handle_service handle_service_;
-
- struct io_status_block
- {
- union u
- {
- LONG Status;
- void* Pointer;
- };
- ULONG_PTR Information;
- };
-
- enum { flush_flags_file_data_sync_only = 4 };
-
- typedef LONG (NTAPI *nt_flush_buffers_file_ex_fn)(
- HANDLE, ULONG, void*, ULONG, io_status_block*);
-
- nt_flush_buffers_file_ex_fn nt_flush_buffers_file_ex_;
- };
- }
- }
- #include "asio/detail/pop_options.hpp"
- #if defined(ASIO_HEADER_ONLY)
- # include "asio/detail/impl/win_iocp_file_service.ipp"
- #endif
- #endif
- #endif
|