c++winsock2iocp

Can I use std::string in IOCP WSARecv func?


I tried to use std::string in WSARecv (winsock), but it didnt work, can you tell me if it's possibleand and how it works


Solution

  • You could initalize your WSABUF structures that you pass to WSARecv, so that the *buf pointer in each WSA buf points to the buffer of a prepared string opbject, something along the lines:

    std::string myStringBuffer;
    myStringBuffer.resize(1024);
    WSABuf wsaBuffer;
    wsaBuffer.len = 1024;
    wsaBuffer.buf = &myStringBuffer[0];