Unix platforms: Use poll in native socket engine instead of select

Change-Id: I10fde9f446ee17c921ce9cf356a27daac396321d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Louai Al-Khanji 2015-10-19 12:56:31 +03:00
parent d3e6e732c7
commit d28bb50b25

View File

@ -1202,47 +1202,47 @@ qint64 QNativeSocketEnginePrivate::nativeRead(char *data, qint64 maxSize)
int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool selectForRead) const
{
fd_set fds;
FD_ZERO(&fds);
FD_SET(socketDescriptor, &fds);
struct timespec tv;
tv.tv_sec = timeout / 1000;
tv.tv_nsec = (timeout % 1000) * 1000 * 1000;
int retval;
if (selectForRead)
retval = qt_safe_select(socketDescriptor + 1, &fds, 0, 0, timeout < 0 ? 0 : &tv);
else
retval = qt_safe_select(socketDescriptor + 1, 0, &fds, 0, timeout < 0 ? 0 : &tv);
return retval;
bool dummy;
return nativeSelect(timeout, selectForRead, !selectForRead, &dummy, &dummy);
}
int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite,
bool *selectForRead, bool *selectForWrite) const
{
fd_set fdread;
FD_ZERO(&fdread);
if (checkRead)
FD_SET(socketDescriptor, &fdread);
struct timespec tv, *ptv = nullptr;
fd_set fdwrite;
FD_ZERO(&fdwrite);
if (checkWrite)
FD_SET(socketDescriptor, &fdwrite);
struct timespec tv;
if (timeout >= 0) {
tv.tv_sec = timeout / 1000;
tv.tv_nsec = (timeout % 1000) * 1000 * 1000;
ptv = &tv;
}
int ret;
ret = qt_safe_select(socketDescriptor + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv);
struct pollfd pfd;
pfd.fd = socketDescriptor;
pfd.events = 0;
pfd.revents = 0;
if (checkRead)
pfd.events |= POLLIN;
if (checkWrite)
pfd.events |= POLLOUT;
const int ret = qt_safe_poll(&pfd, 1, ptv);
if (ret <= 0)
return ret;
*selectForRead = FD_ISSET(socketDescriptor, &fdread);
*selectForWrite = FD_ISSET(socketDescriptor, &fdwrite);
if (pfd.revents & POLLNVAL) {
errno = EBADF;
return -1;
}
static const short read_flags = POLLIN | POLLHUP | POLLERR;
static const short write_flags = POLLOUT | POLLERR;
*selectForRead = ((pfd.revents & read_flags) != 0);
*selectForWrite = ((pfd.revents & write_flags) != 0);
return ret;
}