Langage D build on Windows package tinyredis-2.1.1 Error: undefined identifier `EWOULDBLOCK` dmd failed with exit code 1

66 views Asked by At

I'm trying to build a D project on my Windows machine. It works on mac but I have the following error when building in Windows, I use the command "dub" inside the project and get this at some point :

C:\Users\USER\AppData\Local\dub\packages\tinyredis-2.1.1\tinyredis\source\tinyredis\connection.d(145,30): Error: undefined identifier `EWOULDBLOCK`
dmd failed with exit code 1.      

Any ideas why this EWOULDBLOCK variable is not recognized on Windows ?

Here is the part of connection.d where this identifier appears :

private :

void receive(TcpSocket conn, ref byte[] buffer)
{
    byte[1024 * 16] buff;
    size_t len = conn.receive(buff);

    if (conn.blocking)
    {
        if(len == 0)
            throw new ConnectionException("Server closed the connection!");
        else if(len == TcpSocket.ERROR)
            throw new ConnectionException("A socket error occurred!");
    }
    else
    {
        if (len == -1)
        {
            import core.stdc.errno;

            if (errno == EWOULDBLOCK)
            {
                len = 0;
                errno = 0;
            }
            else
                throw new ConnectionException(format("A socket error occurred! errno: %s", errno));
        }
    }

    buffer ~= buff[0 .. len];
    debug(tinyredis) { writeln("Response : ", "'" ~ escape(cast(string)buffer) ~ "'", " Length : ", len); }
}
2

There are 2 answers

0
Richard Andrew Cattermole On

It is not a variable, it is a constant.

The simple answer is, it has not been declared.

But looks to be 'required' as per MSDN for compatibility purposes.

The problem is however, while MSVC's libc may support it, DMC's which is the default (-m32) probably won't. Either way this is a bug and should be reported to both the dependency and to D's bug tracker.

2
DejanLekic On

EWOULDBLOCK is not defined on Windows (in core.stdc.errno), so you need to wrap that problematic part of code in a version block and handle the Windows properly. On Windows core.sys.windows.winsock2 defines EWOULDBLOCK

However, the std.socket module has a helper function wouldHaveBlocked() that works on Windows as expected:

Something like the following would do:

if (wouldHaveBlocked()) {
  len = 0;
  errno = 0;
} else {
  throw new ConnectionException(format("A socket error occurred! errno: %s", errno));
}