Overlapped (async) ReadFile/win32
2 отговора
138 прегледа
Overlapped (async) ReadFile/win32
abre ora iskam da naburkam koda tuka da wzema greshkata ot ReadFile sled asynchronen dostup (do DVD za w momenta) problema e che Microsoft sa dali slednia primer:
problema e che tova
// do something else for a while
GoDoSomethingElse() ;
ich ne e jasno - wuobshte mnogo nejasno. Ne moga da lockwam prilozhenieto w cikul - ne mi se puska oshte edin thread samo zaradi tazi prostotia - wseki frame (60fps sme) tova se pollwa i mozhe da go provejra - obache kak?
njakoi imal li e opit sus ReadFile (to e sushtoto i pod xbox i pod Win2K - pone taka kazwam Mikronsoft).
tirulirutatuutuu
// set up overlapped structure fields
gOverLapped.Offset = 0;
gOverLapped.OffsetHigh = 0;
gOverLapped.hEvent = hEvent;
// attempt an asynchronous read operation
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead,
&gOverlapped) ;
// if there was a problem, or the async. operation's still pending ...
if (!bResult)
{
// deal with the error code
switch (dwError = GetLastError())
{
case ERROR_HANDLE_EOF:
{
// we're reached the end of the file
// during the call to ReadFile
// code to handle that
}
case ERROR_IO_PENDING:
{
// asynchronous i/o is still in progress
// do something else for a while
GoDoSomethingElse() ;
// check on the results of the asynchronous read
bResult = GetOverlappedResult(hFile, &gOverlapped,
&nBytesRead, FALSE) ;
// if there was a problem ...
if (!bResult)
{
// deal with the error code
switch (dwError = GetLastError())
{
case ERROR_HANDLE_EOF:
{
// we're reached the end of the file
//during asynchronous operation
}
// deal with other error cases
}
}
} // end case
// deal with other error cases
} // end switch
} // end if
problema e che tova
// do something else for a while
GoDoSomethingElse() ;
ich ne e jasno - wuobshte mnogo nejasno. Ne moga da lockwam prilozhenieto w cikul - ne mi se puska oshte edin thread samo zaradi tazi prostotia - wseki frame (60fps sme) tova se pollwa i mozhe da go provejra - obache kak?
njakoi imal li e opit sus ReadFile (to e sushtoto i pod xbox i pod Win2K - pone taka kazwam Mikronsoft).
tirulirutatuutuu
Re: Overlapped (async) ReadFile/win32
Kakvo tochno te pritesniava? Ne triabva da pollvash nisto.
ERROR_IO_PENDING oznachava che operaciata ne e svurshila -- sinhronno -- i po princip nishto ne tiabva da pravish v toia case, prosto go ostaviash trhread-a da si vurshi druga rabota. Kogato operaciata svurshi hEventa stava signaled state. Mojesh da pravish WaitForSingleObject(hEvent ...) za da proveriavash. Na tebe mai po skoro ti traibva ReadFileEx kudeto mojesh da podavash i completion routine t.e. callback koito se vika ot sustia thread kogato operaciata svurhsi.
ERROR_IO_PENDING oznachava che operaciata ne e svurshila -- sinhronno -- i po princip nishto ne tiabva da pravish v toia case, prosto go ostaviash trhread-a da si vurshi druga rabota. Kogato operaciata svurshi hEventa stava signaled state. Mojesh da pravish WaitForSingleObject(hEvent ...) za da proveriavash. Na tebe mai po skoro ti traibva ReadFileEx kudeto mojesh da podavash i completion routine t.e. callback koito se vika ot sustia thread kogato operaciata svurhsi.
Re: Overlapped (async) ReadFile/win32
use Io Completion Port ?
or GetOverlappedResult(.... , TRUE) ?
or GetOverlappedResult(.... , TRUE) ?