io_uring_operation.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // detail/io_uring_operation.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_IO_URING_OPERATION_HPP
  11. #define BOOST_ASIO_DETAIL_IO_URING_OPERATION_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_IO_URING)
  17. #include <liburing.h>
  18. #include <boost/asio/detail/cstdint.hpp>
  19. #include <boost/asio/detail/operation.hpp>
  20. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. namespace detail {
  24. class io_uring_operation
  25. : public operation
  26. {
  27. public:
  28. // The error code to be passed to the completion handler.
  29. boost::system::error_code ec_;
  30. // The number of bytes transferred, to be passed to the completion handler.
  31. std::size_t bytes_transferred_;
  32. // The operation key used for targeted cancellation.
  33. void* cancellation_key_;
  34. // Prepare the operation.
  35. void prepare(::io_uring_sqe* sqe)
  36. {
  37. return prepare_func_(this, sqe);
  38. }
  39. // Perform actions associated with the operation. Returns true when complete.
  40. bool perform(bool after_completion)
  41. {
  42. return perform_func_(this, after_completion);
  43. }
  44. protected:
  45. typedef void (*prepare_func_type)(io_uring_operation*, ::io_uring_sqe*);
  46. typedef bool (*perform_func_type)(io_uring_operation*, bool);
  47. io_uring_operation(const boost::system::error_code& success_ec,
  48. prepare_func_type prepare_func, perform_func_type perform_func,
  49. func_type complete_func)
  50. : operation(complete_func),
  51. ec_(success_ec),
  52. bytes_transferred_(0),
  53. cancellation_key_(0),
  54. prepare_func_(prepare_func),
  55. perform_func_(perform_func)
  56. {
  57. }
  58. private:
  59. prepare_func_type prepare_func_;
  60. perform_func_type perform_func_;
  61. };
  62. } // namespace detail
  63. } // namespace asio
  64. } // namespace boost
  65. #include <boost/asio/detail/pop_options.hpp>
  66. #endif // defined(BOOST_ASIO_HAS_IO_URING)
  67. #endif // BOOST_ASIO_DETAIL_IO_URING_OPERATION_HPP