Skip to main content
GameDev.net gamedev.net
🔒 Locked

I/O Completion Port problem

Started by tiegudanxin Jan 20, 2007 at 8:48 PM 1 replies 950+ views
Original Post
tiegudanxin
tiegudanxin
Hi all I'm a newbie with I/O Completion Port. I'm learning "Network Programming For MS Windows",I don't understand a piece of code with the I/O Completion Port part in the book,as below.

    // Post another WSASend or WSARecv operation.
        
        Flags = 0;

        // Set up the per-I/O operation data for the next
        // overlapped call
        ZeroMemory(&(PerIoData->Overlapped),
            sizeof(OVERLAPPED));

        PerIoData->DataBuf.len = DATA_BUFSIZE;
        PerIoData->DataBuf.buf = PerIoData->Buffer;
        PerIoData->OperationType = RECV_POSTED;

        WSARecv(PerHandleData->Socket, 
            &(PerIoData->DataBuf), 1, &RecvBytes,
            &Flags, &(PerIoData->Overlapped), NULL);

Why does it zero PerIoData->Overlapped' memory?
hplus0603
hplus0603
In programming for Win32, it is always a good idea to zero out all structs you pass to Windows before you fill them out. This will do two things:

1) If there are "reserved" fields or fields that you don't use, they will not have illegal values.
2) If the API is extended in the future, any new fields (when you recompile) will also be set to 0.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.