When using blocking sockets, all I had to do to send a file was to open the file and loop through it and send it in chunks.
But I find sending a file using overlapped sockets to be more challenging. I can think of the following approach to do it:
- I open the file and send the first chunk, and I keep track of the file handle and file position (I store these data somewhere in memory).
- Now when I get a completion packet indicating that some data has been sent, I retrieve the file handle and file position and send the next chunk.
- I repeat step 2 until I reach the last chunk in the file, and then I close the file.
Is this approach correct?
Note: I don't want to use TransmitFile().
Edit: I have updated my question.