mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
libc: reduce file descriptor lookup exceptions in 'select()'
Fixes #3908
This commit is contained in:
parent
058f2e687c
commit
5c47fa0d41
@ -1222,13 +1222,19 @@ int Socket_fs::Plugin::select(int nfds,
|
||||
|
||||
for (int fd = 0; fd < nfds; ++fd) {
|
||||
|
||||
bool fd_in_readfds = FD_ISSET(fd, &in_readfds);
|
||||
bool fd_in_writefds = FD_ISSET(fd, &in_writefds);
|
||||
|
||||
if (!fd_in_readfds && !fd_in_writefds)
|
||||
continue;
|
||||
|
||||
File_descriptor *fdo = file_descriptor_allocator()->find_by_libc_fd(fd);
|
||||
|
||||
/* handle only fds that belong to this plugin */
|
||||
if (!fdo || (fdo->plugin != this))
|
||||
continue;
|
||||
|
||||
if (FD_ISSET(fd, &in_readfds)) {
|
||||
if (fd_in_readfds) {
|
||||
try {
|
||||
Socket_fs::Context *context = dynamic_cast<Socket_fs::Context *>(fdo->context);
|
||||
|
||||
@ -1239,7 +1245,7 @@ int Socket_fs::Plugin::select(int nfds,
|
||||
} catch (Socket_fs::Context::Inaccessible) { }
|
||||
}
|
||||
|
||||
if (FD_ISSET(fd, &in_writefds)) {
|
||||
if (fd_in_writefds) {
|
||||
try {
|
||||
Socket_fs::Context *context = dynamic_cast<Socket_fs::Context *>(fdo->context);
|
||||
|
||||
|
@ -2080,6 +2080,12 @@ int Libc::Vfs_plugin::select(int nfds,
|
||||
auto fn = [&] {
|
||||
for (int fd = 0; fd < nfds; ++fd) {
|
||||
|
||||
bool fd_in_readfds = FD_ISSET(fd, &in_readfds);
|
||||
bool fd_in_writefds = FD_ISSET(fd, &in_writefds);
|
||||
|
||||
if (!fd_in_readfds && !fd_in_writefds)
|
||||
continue;
|
||||
|
||||
File_descriptor *fdo =
|
||||
file_descriptor_allocator()->find_by_libc_fd(fd);
|
||||
|
||||
@ -2090,7 +2096,7 @@ int Libc::Vfs_plugin::select(int nfds,
|
||||
Vfs::Vfs_handle *handle = vfs_handle(fdo);
|
||||
if (!handle) continue;
|
||||
|
||||
if (FD_ISSET(fd, &in_readfds)) {
|
||||
if (fd_in_readfds) {
|
||||
if (handle->fs().read_ready(handle)) {
|
||||
FD_SET(fd, readfds);
|
||||
++nready;
|
||||
@ -2099,7 +2105,7 @@ int Libc::Vfs_plugin::select(int nfds,
|
||||
}
|
||||
}
|
||||
|
||||
if (FD_ISSET(fd, &in_writefds)) {
|
||||
if (fd_in_writefds) {
|
||||
if (true /* XXX always writeable */) {
|
||||
FD_SET(fd, writefds);
|
||||
++nready;
|
||||
|
Loading…
Reference in New Issue
Block a user