OCEAN-xyz / datum_gateway

Decentralized Alternative Templates for Universal Mining
Other
32 stars 9 forks source link

Use of epoll is not portable... #22

Open 21M4TW opened 3 days ago

21M4TW commented 3 days ago

Hi,

I tried compiling datum on FreeBSD and the use of epoll is an issue as it is specific to Linux. My understanding is that epoll is built around poll. Is the future plan to switch to poll with some helper functions to add and remove descriptors? I might be able to look into it if this would be an accepted approach...

Thanks!

luke-jr commented 3 days ago

There's definitely work to be done on portability, but I'm not sure what the best approach is. Windows is another mess, with no 1:1 equivalents either.

21M4TW commented 3 days ago

There's definitely work to be done on portability, but I'm not sure what the best approach is. Windows is another mess, with no 1:1 equivalents either.

For the BSD family including macOS there is https://github.com/jiixyj/epoll-shim as another option. I guess it comes down to a design preference of using a local implementation that either uses poll or uses different code depending on the OS (e.g. epoll for Linux, kqueue for BSD), or relying on an additional dependency such as epoll-shim?

luke-jr commented 3 days ago

Definitely prefer to fix portability issues properly.

21M4TW commented 2 days ago

Ok so an update on this, I had the chance to look more at compiling datum on FreeBSD. There was not much missing after all. Here is a list of what I had to do: -Install the libepoll-shim and argp-standalone packages with pkg or from ports (in addition to the listed datum dependencies) -Include <netinet/in.h> in src/datum_protocol.c -Set: CFLAGS to "-I/usr/local/include/libepoll-shim/" LDFLAGS to "-L/usr/local/lib -lepoll-shim -largp"

That's it! So presumably if you did add the netinet/in.h header file to src/datum_protocol.c it would help portability and no additional change would be required to compile datum on FreeBSD, if setting CFLAGS and LDFLAGS variables is not considered to be much of a hack. I have yet to do testing though...

21M4TW commented 1 day ago

Seems to be running fine so far! :)

luke-jr commented 1 day ago

At a minimum, we should use pkg-config or such to detect and use the relevant libraries :)

21M4TW commented 1 day ago

I looked at this. I was able to add support for epoll-shim in CMakeLists.txt for non-Linux OSes. I also modified CMakeLists.txt to add libargp support, but that package does not provide any cmake or pc file. On FreeBSD it is installed in a standard library directory (/usr/local/lib). So I used find_library to locate it, and I test for it. Here is a diff in attachment CMakeLists_diff.txt

21M4TW commented 1 day ago

Created a pull request: https://github.com/OCEAN-xyz/datum_gateway/pull/32