On Friday, 9 April 2021 at 18:37:43 UTC, Jacob Carlborg wrote:
On 2021-04-09 11:00, rashir wrote:
Goodmorning everyone,
I'm trying to understand both Kqueue and Fiber's operation on Mac. Why don't I get the correct data as long as I read from the socket? It seems to be reading too early, but Kquue tells me that the socket is readable.

```D
       const bytesRead = recv(fd, b.ptr, readableAmount < b.length ? readableAmount : b.length, 0);        writeln("read bytesRead: ", bytesRead, "readableAmount:",
                readableAmount, " errno:", errno);
       assert(bytesRead != EAGAIN && bytesRead != EWOULDBLOCK);
```

`recv` returns the number of bytes received or `-1` if an error occurred. `EAGAIN` and `EWOULDBLOCK` are error codes. You should not compare the value returned by `recv` with error codes. The error code will be placed in `errno`.

```D
        assert(eventList[0].filter & EVFILT_READ);
```

The `filter` field of an event is not a flag/bit field. It's just a plain value, you should use `==` to check if it's a read event.

I'm not sure if fixing these things will solve your issue. But at least some problems I noticed.

Thank you

Correcting the asserts I managed to understand the problem.

A EV_ONESHOT was missing in the first EVFILT_WRITE, so I was receiving a notification of Write, interpreting it as a notification of Read.

Cheers

Reply via email to