pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.05k stars 2.11k forks source link

Optimize Net module for Android #4517

Closed zhuzeitou closed 3 months ago

zhuzeitou commented 3 months ago
  1. Poco uses epoll_create, epoll_ctl and epoll_wait, and they are always available for NDK. So we can enable epoll for Android platform.
    
    int epoll_create(int __size);

if __ANDROID_API__ >= 21

int epoll_create1(int flags) INTRODUCED_IN(21);

endif / __ANDROID_API__ >= 21 /

int epoll_ctl(int epoll_fd, int op, int fd, struct epoll_event* BIONIC_COMPLICATED_NULLNESS event); int epoll_wait(int __epoll_fd, struct epoll_event* _Nonnull events, int __event_count, int __timeout_ms);

if __ANDROID_API__ >= 21

int epoll_pwait(int epoll_fd, struct epoll_event* _Nonnull events, int event_count, int timeout_ms, const sigset_t* _Nullable mask) INTRODUCED_IN(21);

endif / __ANDROID_API__ >= 21 /

if __ANDROID_API__ >= 28

int epoll_pwait64(int epoll_fd, struct epoll_event* _Nonnull events, int event_count, int timeout_ms, const sigset64_t* _Nullable mask) INTRODUCED_IN(28);

endif / __ANDROID_API__ >= 28 /

2. <ifaddr.h>(`getifaddrs` and `freeifaddrs`) was introduced in android-24, so we can use `__ANDROID_API__ >= 24` to check if they are supported
```c
#if __ANDROID_API__ >= 24
int getifaddrs(struct ifaddrs* _Nullable * _Nonnull __list_ptr) __INTRODUCED_IN(24);

/**
 * [freeifaddrs(3)](http://man7.org/linux/man-pages/man3/freeifaddrs.3.html) frees a linked list
 * of `struct ifaddrs` returned by getifaddrs().
 *
 * Available since API level 24.
 */
void freeifaddrs(struct ifaddrs* _Nullable __ptr) __INTRODUCED_IN(24);
#endif /* __ANDROID_API__ >= 24 */