Exemple #1
0
	bool Read(void *buf, size_t len)
	{
		//ReadFile
		//If the function succeeds, the return value is nonzero (TRUE).
		//If the function fails, or is completing asynchronously, the return value is zero (FALSE). To get extended error information, call the GetLastError function.
		//Note  The GetLastError code ERROR_IO_PENDING is not a failure; it designates the read operation is pending completion asynchronously. For more information, see Remarks.
		//Comments:
		//On Windows XP (at least) we have ReadFile returning TRUE and still initiating async iocp operation.

		if(log_level) std::cerr << "BlockwiseImpl::Read " << timeout.time_left()<< std::endl;
		BOOL read_ret = ReadFile(hCom, buf, len, 0, (OVERLAPPED*)&read_over);
		if(!read_ret && GetLastError() != ERROR_IO_PENDING) {
			HandleLastError("ReadFile");
			return true;
		} 
		return false;;
	}