Commit 6c0b382b authored by jan.koester's avatar jan.koester
Browse files

tet

parent 68a89752
Loading
Loading
Loading
Loading
+24 −7
Changes for src/windows/udp.cpp: 24 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -129,21 +129,38 @@ void udp::accept(std::unique_ptr<socket>& csock, bool nonblock) {
}

size_t udp::sendData(buffer& data, int flags) {
    int ret = ::send(_Socket, data.data.buf, (int)data.size, flags);
    size_t sendlen = data.size;

    if (!_SendBuffer) {
        _SendBuffer = std::make_unique<buffer>(sendlen);
    }
    if (_SendBuffer->size < sendlen) {
        _SendBuffer = std::make_unique<buffer>(sendlen);
    }

    std::memcpy(_SendBuffer->data.buf, data.data.buf, sendlen);
    _SendBuffer->data.len = (ULONG)sendlen;
    std::memset(&_SendBuffer->overlapped, 0, sizeof(WSAOVERLAPPED));
    _SendBuffer->operation = OP_WRITE;

    _pendingIocpWrite.store(true);

    DWORD bytesSent = 0;
    int ret = ::WSASend(_Socket, &_SendBuffer->data, 1, &bytesSent, flags,
                        &_SendBuffer->overlapped, nullptr);

    if (ret == SOCKET_ERROR) {
        int err = ::WSAGetLastError();
        if (err == WSAEWOULDBLOCK) {
            NetException e;
            e[NetException::Note] << "udp::sendData would block";
            throw e;
        if (err == WSA_IO_PENDING) {
            return sendlen;
        }
        _pendingIocpWrite.store(false);
        NetException e;
        e[NetException::Error] << "udp::sendData failed: " << err;
        e[NetException::Error] << "udp::sendData WSASend failed: " << err;
        throw e;
    }

    return (size_t)ret;
    return sendlen;
}

size_t udp::recvData(buffer& data, int flags) {