--- embedaddon/mpd/src/contrib/libpdel/io/timeout_fp.c 2013/07/22 08:44:30 1.1.1.1 +++ embedaddon/mpd/src/contrib/libpdel/io/timeout_fp.c 2021/03/17 00:39:23 1.1.1.2 @@ -140,7 +140,27 @@ timeout_fp_write(void *cookie, const char *buf, int le { struct fdt_info *const fdt = cookie; - return (timeout_fp_readwrite(fdt, (char *)buf, len, 1)); + struct pollfd pfd; + int nfds; + + /* Set up write poll(2) event */ + memset(&pfd, 0, sizeof(pfd)); + pfd.fd = fdt->fd; + pfd.events = POLLWRNORM; + + /* Wait for writability */ + if ((nfds = poll(&pfd, 1, fdt->timeout * 1000)) == -1) + return (-1); + + /* Check for timeout */ + if (nfds == 0) { + errno = ETIMEDOUT; + return (-1); + } + + /* Do I/O */ + return write(fdt->fd, buf, len); + } /*