IOCP and ERROR_IO_PENDING
-
Hi, Im creating a server using UDP and IOCP. I've red some articles about it and i understand the most of it ( the basic anyway. not saying im a IOCP master ) anyway, since i got a lot of ERROR_IO_PENDING returns when doing a WSASendTo or WSARecvFrom, i got myself wondering what hapends when i get this error. I know what it means but i dont quit seem to get or find any information about how to process it. What hapends when a send or recv function returns this and what is the best way of processing it? Thanks already!
-
Hi, Im creating a server using UDP and IOCP. I've red some articles about it and i understand the most of it ( the basic anyway. not saying im a IOCP master ) anyway, since i got a lot of ERROR_IO_PENDING returns when doing a WSASendTo or WSARecvFrom, i got myself wondering what hapends when i get this error. I know what it means but i dont quit seem to get or find any information about how to process it. What hapends when a send or recv function returns this and what is the best way of processing it? Thanks already!
Most, if not all, of of your overlapped operations on a socket associated with an IOCP should return this "error". It means that the overlapped operation was queued for processing by the IOCP and when the operation is complete then one of the threads waiting on the IOCP (via GetQueuedCompletionStatus()) will be released. When a thread receives the completion notification (GetQueuedCompletionStatus() returns) then you can check if an error occurred. If the operation was successful do whatever processing needs to be done (perhaps destroying the send/recv buffer, returning it to a buffer pool, queuing up another overlapped operation, etc). Any other error than ERROR_IO_PENDING means the operation was NOT queued so you'll never get a completion notification. In other words, the operation failed immediately. Mark
-
Most, if not all, of of your overlapped operations on a socket associated with an IOCP should return this "error". It means that the overlapped operation was queued for processing by the IOCP and when the operation is complete then one of the threads waiting on the IOCP (via GetQueuedCompletionStatus()) will be released. When a thread receives the completion notification (GetQueuedCompletionStatus() returns) then you can check if an error occurred. If the operation was successful do whatever processing needs to be done (perhaps destroying the send/recv buffer, returning it to a buffer pool, queuing up another overlapped operation, etc). Any other error than ERROR_IO_PENDING means the operation was NOT queued so you'll never get a completion notification. In other words, the operation failed immediately. Mark
ok, i see that makes it all clear. In a related question, when i have multiple threads and when i do a WSASendTo or whatever, it returns -1 so i use WSAGetLastError(). to retrieve the error. Does WSAGetLastError() returns the last error associated with that specific thread, or could it happen that 2 threads at the same time store an error and that i might retrieve an error from another thread with WSAGetLastError()? ( doest seems likely but who knows)
-
ok, i see that makes it all clear. In a related question, when i have multiple threads and when i do a WSASendTo or whatever, it returns -1 so i use WSAGetLastError(). to retrieve the error. Does WSAGetLastError() returns the last error associated with that specific thread, or could it happen that 2 threads at the same time store an error and that i might retrieve an error from another thread with WSAGetLastError()? ( doest seems likely but who knows)
Yes WSAGetLastError() returns the error code for the last socket API called on the calling thread. Mark
-
ok, i see that makes it all clear. In a related question, when i have multiple threads and when i do a WSASendTo or whatever, it returns -1 so i use WSAGetLastError(). to retrieve the error. Does WSAGetLastError() returns the last error associated with that specific thread, or could it happen that 2 threads at the same time store an error and that i might retrieve an error from another thread with WSAGetLastError()? ( doest seems likely but who knows)
And....especially for overlapped calls, you should check the error EVERY time the API indicates an error. Otherwise there's no way to effectively manage the overlapped buffers. :) Mark
-
And....especially for overlapped calls, you should check the error EVERY time the API indicates an error. Otherwise there's no way to effectively manage the overlapped buffers. :) Mark