Re: Помогите с обратным вызовом.
От: NavuhodonosoR Россия  
Дата: 06.09.02 11:23
Оценка:
Здравствуйте F.A.V., Вы писали:

FAV>Проблема в следующем — не вызываются обработчики завершения (в WSARecv и WSASend параметр lpCompletionRoutine) отсылки/принятия данных, хотя создаю и устанавливаю вроде всё правильно.

FAV>Сокет создаю вот так
FAV>m_sockWork = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_IP, NULL, 0, WSA_FLAG_OVERLAPPED);
FAV>вызов фунок примерно такой:
FAV>int nRet = WSASend(
FAV> m_sockWork,
FAV> &wsaBuff,
FAV> 1,
FAV> &dwSendNumBytes,
FAV> 0,
FAV> &overlap,
FAV> m_lpfSendComplete);
FAV>где m_lpfSendComplete — валидная указилка на статическую ф-цию член класса.
FAV>Может кто сталкивался или может прислать сампл?

Тут два варианта. Во-первых
===8<-- MSDN:WSASend ---
If an overlapped operation completes immediately, WSASend returns a value of zero and the lpNumberOfBytesSent parameter is updated with the number of bytes sent. If the overlapped operation is successfully initiated and will complete later, WSASend returns SOCKET_ERROR and indicates error code WSA_IO_PENDING. In this case, lpNumberOfBytesSent is not updated. When the overlapped operation completes the amount of data transferred is indicated either through the cbTransferred parameter in the completion routine (if specified), or through the lpcbTransfer parameter in WSAGetOverlappedResult.
------- MSDN ---
Так что если nRet == 0, то обработчик завершения и не вызовется.

Во-вторых
===8<-- MSDN:WSASend ---
The completion routine follows the same rules as stipulated for Win32 file I/O completion routines. The completion routine will not be invoked until the thread is in an alertable wait state such as can occur when the function WSAWaitForMultipleEvents with the fAlertable parameter set to TRUE is invoked.
===8<-- MSDN:WSAWaitForMultipleEvents ---
fAlertable
[in] An indicator specifying whether the function returns when the system queues an I/O completion routine for execution by the calling thread. If TRUE, the completion routine is executed and the function returns. If FALSE, the completion routine is not executed when the function returns.
------- MSDN ---
Так что если ты вызвал WSAWaitForMultipleEvents с fAlertable = FALSE, то опять же обработчик не сработает.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.