c++ - ReadFile using NamedPipe blocks though using overlapped -


i using namedpipes communicate between different modules of our windows application. @ 1 point possible read operation take long time add timeout. added overlapped-flag this:

pipehandle = createfile(             pipename,             pipe_access_duplex | file_flag_overlapped,             0,             nullptr,             open_existing,             0,             nullptr); 

then read operation looks this:

    overlapped overlapped;         zeromemory(&overlapped, sizeof(overlapped));         overlapped.hevent = createevent(nullptr, true, false, nullptr);     successful = readfile(             pipehandle,             buffer,             4096 * sizeof(wchar_t),             &numbytesread,             &overlapped         );     if (successful == false)     {         log("reading not successful");         if (getlasterror() != error_io_pending)         {             // function call failed. todo: recovery.             log_last_error("failed because of error: ");             return error_read_fault;         }         else         {             // todo: add timeout...             successful = getoverlappedresult(pipehandle, &overlapped, &numbytesread, true);         }     }     else     {         log("reading successful");         // i/o completed:         return error_success;     } 

now expect call readfile return immediatley handle possible timeouts, instead blocks till call returns.

what doing wrong?

in code, file_flag_overlapped in dwdesiredaccess parameter, should specified in dwflagsandattributes parameter.

so, might work better:

pipehandle = createfile(         pipename,         pipe_access_duplex,         0,         nullptr,         open_existing,         file_flag_overlapped,         nullptr); 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -