Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Pipe ReadFile function set timeout in Windows XP

Tags:

timeout

winapi

Is there a way to perform ReadFile with timeout in Windows XP?

If not, is there a way to break the pipe from other thread?

like image 690
Erik Sapir Avatar asked Apr 01 '26 21:04

Erik Sapir


2 Answers

Set up an asynchronous ReadFile using Overlapped I/O. You can then use CancelIOEx to cancel the read at any time.

like image 88
Goz Avatar answered Apr 03 '26 17:04

Goz


Assuming you're talking about a named pipe, the usual way is to do an overlapped read, and specify a timeout when you call WaitForSingleObject (or WaitForMultipleObjects). When/if the timeout expires, the wait will return WAIT_TIMEOUT instead of WAIT_OBJECT_0.

like image 30
Jerry Coffin Avatar answered Apr 03 '26 17:04

Jerry Coffin