void run() { #if ! BEAST_NO_STD_FUNCTION_CONSTRUCTIBLE static_assert (! std::is_constructible < std::function <void(void)>, int&&>::value, "Cannot construct std::function from int&&"); static_assert (! std::is_constructible < std::function <void(void)>, int>::value, "Cannot construct std::function from int"); static_assert (! std::is_constructible < asio::shared_handler <void(void)>, int>::value, "Cannot construct shared_handler from int"); #endif static_assert (std::is_constructible < asio::shared_handler <void(int)>, asio::shared_handler <void(int)>>::value, "Should construct <void(int)> from <void(int)>"); static_assert (! std::is_constructible < asio::shared_handler <void(int)>, asio::shared_handler <void(void)>>::value, "Can't construct <void(int)> from <void(void)>"); // Hooks called when using the raw handler { test_results r; test_handler h (r); async_op (h); expect (r.call); expect (r.alloc); expect (r.dealloc); expect (r.cont); test_invokable f; boost_asio_handler_invoke_helpers::invoke (std::ref (f), h); expect (r.invoke); expect (f.call); } // Use of std::function shows the hooks not getting called { test_results r; std::function <void(void)> fh ((test_handler) (r)); async_op (fh); expect (r.call); unexpected (r.alloc); unexpected (r.dealloc); unexpected (r.cont); test_invokable f; boost_asio_handler_invoke_helpers::invoke (std::ref (f), fh); unexpected (r.invoke); expect (f.call); } // Make sure shared_handler calls the hooks { test_results r; asio::shared_handler <void(void)> sh ((test_handler)(r)); async_op (sh); expect (r.call); expect (r.alloc); expect (r.dealloc); expect (r.cont); test_invokable f; boost_asio_handler_invoke_helpers::invoke (std::ref (f), sh); expect (r.invoke); expect (f.call); } // Make sure shared_handler via implicit conversion calls hooks { test_results r; test_handler h (r); virtual_async_op ((test_handler) (r)); expect (r.call); expect (r.alloc); expect (r.dealloc); expect (r.cont); } }
static int do_io(const char *disk_path, bool async, bool write, uint64_t offset, uint64_t size_in_bytes) { int exa_rdev_fd; int disk_fd; exa_rdev_handle_t *dev_req; uint64_t disk_size; int ret; /* Get disk size */ disk_fd = os_disk_open_raw(disk_path, OS_DISK_READ); if (disk_fd < 0) { fprintf(stderr, "Can not open disk %s\n", disk_path); return -1; } ret = os_disk_get_size(disk_fd, &disk_size); if (ret < 0) { fprintf(stderr, "Can not get the size of disk %s\n", disk_path); return -1; } fprintf(stderr, "Disk %s has a size of %"PRIu64" bytes\n", disk_path, disk_size); /* Initialise exa_rdev */ exa_rdev_fd = exa_rdev_init(); if (exa_rdev_fd <= 0) { fprintf(stderr, "exa_rdev_init() failed\n"); return -1; } dev_req = exa_rdev_handle_alloc(disk_path); if (dev_req == NULL) { fprintf(stderr, "exa_rdev_request_init() failed, disk_path = %s\n", disk_path); close(exa_rdev_fd); return -1; } /* Carry on requests to exa_rdev */ if (async) { fprintf(stderr, "Asynchronous mode\n"); if (write) async_op(RDEV_OP_WRITE, offset, size_in_bytes, dev_req); else async_op(RDEV_OP_READ, offset, size_in_bytes, dev_req); } else { fprintf(stderr, "Synchronous mode\n"); if (write) sync_op(RDEV_OP_WRITE, offset, size_in_bytes, dev_req); else sync_op(RDEV_OP_READ, offset, size_in_bytes, dev_req); } fprintf(stderr, "Finished %s %"PRIu64 " bytes on disk %s at offset %"PRIu64 "\n", (write == true) ? "writing" : "reading", size_in_bytes, disk_path, offset); close(exa_rdev_fd); return 0; }
void virtual_async_op (asio::shared_handler <void(void)> handler) { async_op (handler); }