samedi 28 septembre 2019

TCP non blocking socket packet loss

It looks like the send() func in this case is too much faster than recv() and recv() never reach 262144-bytes I don't wanna use blocking sockets as there are many messages that have to be processed by the MsgPoc callback, any idea on how to fix this

// peer 1
char buff[262144]; // 265 kb

LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        //...
    case WM_SOCKET:     // #define WM_SOCKET (WM_USER + 1)
        switch (WSAGETSELECTEVENT(lParam))
        {
        case FD_READ:
        {
            nBytes += recv(sock, buff, 262144, 0); // always receiving 5840 bytes max
            fwrite(buff, 1, 262144, file);            
            break;
        }
        //...
    }
    return 0;
}

// peer 2 sends packets from the main loop
while (GetMessage(&msg, nullptr, 0, 0))
{
    TanslateMessage(&msg);
    DispatchMessage(&msg);

    fread(buff, 1, 262144, file);
    nBytes += send(sock, buff, 262144, 0);
}

Aucun commentaire:

Enregistrer un commentaire