c++ - Using boost asio stream_handle with sequential like file based devices -


i considering using asio perform "overlapped" (completion ports) style io on windows "device handle" created createfile(...overlapped...)

i have quite particular design though, because of specifics of application must maintain different thread pool performing actual processing of data(work pool) , pool (a small one, 1 thread maybe) of actual io completions triggered processing pool.

basically, @ beginning want trigger handful of io requests device initiated io pool. when these complete notify scheduling component posts completion packets content different threads in work pool. these completion notifications return because actual processing happen in work pool -> , particular work pool thread after processing takes place new "read" initiated should trigger completion on io pool.

is dissociation possible using windows::stream_handle ? in general seems asio api associates read completions same io_service associated stream object.

edit been long time now, i've implemented approach. i've updated response reflect choices.

  1. i create "device" handle using windows specific function:

    handle file_handle = createfile(... file_flag_overlapped ...);

  2. i can associate/register handle ioservice overlapped requests device handled 1 of ioservice thread(s).

    error_code ec; auto &io_service_impl = use_service(ioservice); io_service_impl.register_handle(file_handle, ec);

  3. then can use asio overlapped initiate async io different thread ioservice.run(), making trigger completion in io service thread(s):

        void iopool::initiatenewread()     {      service.post([this]() {auto handler = interceptorreadhandler::create(bufferpool, data, service);                 handler->setcontext(context);                  return device.read(std::move(handler));             });         }     } 
  4. for reference device read implementation:

    bool device::read(std::shared_ptr<interceptorreadhandler> handler) { auto handlerwrapper = [handler](const boost::system::error_code &ec, std::size_t len) {     handler->completion(ec, len); }; win::overlapped_ptr overlapped(handler->getservice(), handlerwrapper);   unsigned long bytesread = 0; auto& packet = handler->getbuffer(); auto ok = ::readfile(handle,                      packet.data,                      static_cast<dword> (packet.length),                      &bytesread,                      overlapped.get()) ? true : false;  auto lasterror = ::getlasterror(); if (!ok && lasterror != error_io_pending) {     boost::system::error_code errcode(lasterror, boost::system::get_system_category());     overlapped.complete(errcode, 0);     return false; } else {     overlapped.release(); }  return true; 

    }


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -