Forum OpenACS Development: Re: NaviServer on windows - 6th of June

Collapse
Posted by Maurizio Martignano on
I believe I found the issue that has stopped NaviServer from working in Windows since the 12th of June.
Till the 12th of June in the file sock.c, function Ns_SockSendBufs2, there was a portion of code that was specific to Windows.

#ifdef _WIN32
{
DWORD bytesSent;
int rc;

rc = WSASend(sock, (LPWSABUF)bufs, nbufs, &bytesSent, flags,
NULL, NULL);
...

This portion has disappeared during the normalization/refactoring work.
Replacing the current sock.c file with the old one (6th of June, previous to the changes of the 12th) fixes the issue.
Best regards,
Maurizio

Collapse
Posted by Maurizio Martignano on

To be more precise the portion of Windows specific code has changed from:

#ifdef _WIN32
    {
        DWORD bytesSent;
        int   rc;

        rc = WSASend(sock, (LPWSABUF)bufs, nbufs, &bytesSent, flags,
                     NULL, NULL);
        if (rc == -1) {
            if (GetLastError() == WSAEWOULDBLOCK) {
                sent = 0;
            } else {
                sent = -1;
            }
        } else {
            sent = (ssize_t)bytesSent;
        }
    }
#else

to:

#ifdef _WIN32
    DWORD SendBytes = 0, Flags = (DWORD)flags;

    if (WSASend(sock, (LPWSABUF)bufs, (unsigned long)nbufs, &SendBytes,
                &Flags, NULL, NULL) == -1) {
        numBytes = -1;
    } else {
        numBytes = (ssize_t)SendBytes;
    }
#else

and the logic is not exactly the same.

Hope it helps, Maurizio

Collapse
Posted by Maurizio Martignano on

This is my last input on this topic, eventually I updated the latest version on the file sock.c with this modified function:

static ssize_t
SockSend(NS_SOCKET sock, struct iovec *bufs, int nbufs, unsigned int flags)
{
    ssize_t numBytes = 0;

#ifdef _WIN32
    DWORD SendBytes = 0, Flags = (DWORD)flags;
    int rc;

    rc = WSASend(sock, (LPWSABUF)bufs, (unsigned long)nbufs, &SendBytes, Flags, NULL, NULL);
    if (rc == -1) {
        if (GetLastError() == WSAEWOULDBLOCK) {
            numBytes = 0;
        }
        else {
            numBytes = -1;
        }
    } else {
        numBytes = (ssize_t)SendBytes;
    }
#else
    struct msghdr msg;

    memset(&msg, 0, sizeof(msg));
    msg.msg_iov = bufs;
    msg.msg_iovlen = (NS_MSG_IOVLEN_T)nbufs;
    numBytes = sendmsg(sock, &msg, (int)flags);
#endif

    if (numBytes == -1) {
        Ns_Log(Debug, "SockSend: %d, %s", sock, ns_sockstrerror(ns_sockerrno));
    }

    return numBytes;
}

Hope it helps, Maurizio