netcan / asyncio

asyncio is a c++20 library to write concurrent code using the async/await syntax.
MIT License
812 stars 80 forks source link

OSX compatibility changes #13

Closed Be3y4uu-K0T closed 1 year ago

Be3y4uu-K0T commented 1 year ago

Pull request with regard to issue: #12

Be3y4uu-K0T commented 1 year ago

I don't understand. I tried to pass the check tests on my Ubuntu VM.

$ cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS"
PRETTY_NAME="Ubuntu 22.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.2 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
Codename:   jammy
$ git clone --recursive https://github.com/Be3y4uu-K0T/asyncio.git
$ cd asyncio
$ mkdir build-debug
$ cmake -H. -Bbuild-debug -DCMAKE_BUILD_TYPE=Debug
$ cmake --build build-debug -j2
...
[100%] Built target asyncio_ut

Everything works, but GitHub tests don't pass with the same OS.

Operating System
  Ubuntu
  22.04.1
  LTS

What did I do wrong?

Be3y4uu-K0T commented 1 year ago

I think the problem was in this line:

// file: <asyncio/stream.h>::34L
#if SOCK_NONBLOCK != 0

Due to the definition of the macro, the comparison was always false:

// file: <bits/socket_type.h>::52L
SOCK_NONBLOCK = 00004000      /* Atomically mark descriptor(s) as
                                   non-blocking.  */
#define SOCK_NONBLOCK SOCK_NONBLOCK

So I just replaced with if constexpr:

if constexpr (SOCK_NONBLOCK != 0) {