chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.92k stars 1.22k forks source link

Asio relies on sys/uio.h which is missing on many platforms, therefore non-portable #455

Open rsn8887 opened 4 years ago

rsn8887 commented 4 years ago

See title and here https://github.com/chriskohlhoff/asio/blob/62c4488abccce5e62b0526bb3f5390f57ab3712c/asio/include/asio/detail/socket_types.hpp

Regarding sys/uio.h:

The functionality described is part of the X/Open Systems Interfaces option.
Functionality marked XSI is an extension to the ISO C standard.
Application developers may confidently make use of such extensions
on all systems supporting the X/Open System Interfaces option.

See: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_uio.h.html

Why does asio depend on such a non-portable and non-standard header? It breaks portability to many embedded platforms and others.

glebm commented 4 years ago

These calls should be quite easy to implement in a portable manner if the header is missing. Not sure how to detect whether this header is present though.

Example from https://www.oreilly.com/library/view/linux-system-programming/0596009585/ch04.html

ssize_t naive_writev(int fd, const struct iovec *iov, int count) {
    ssize_t ret = 0;
    int i;
    for (i = 0; i < count; i++) {
        ssize_t nr;
        nr = write(fd, iov[i].iov_base, iov[i].iov_len);
        if (nr == −1) {
            ret = −1;
            break;
        }
        ret += nr;
    }
    return ret;
}

Known platforms affected: PS Vita, Nintendo Switch, Nintendo 3DS (all newlib-based homebrew environments).