MCPcopy Create free account
hub / github.com/F-Stack/f-stack / selrescan

Function selrescan

freebsd/kern/sys_generic.c:1312–1356  ·  view source on GitHub ↗

* Traverse the list of fds attached to this thread's seltd and check for * completion. */

Source from the content-addressed store, hash-verified

1310 * completion.
1311 */
1312static int
1313selrescan(struct thread *td, fd_mask **ibits, fd_mask **obits)
1314{
1315 struct filedesc *fdp;
1316 struct selinfo *si;
1317 struct seltd *stp;
1318 struct selfd *sfp;
1319 struct selfd *sfn;
1320 struct file *fp;
1321 fd_mask bit;
1322 int fd, ev, n, idx;
1323 int error;
1324 bool only_user;
1325
1326 fdp = td->td_proc->p_fd;
1327 stp = td->td_sel;
1328 n = 0;
1329 only_user = FILEDESC_IS_ONLY_USER(fdp);
1330 STAILQ_FOREACH_SAFE(sfp, &stp->st_selq, sf_link, sfn) {
1331 fd = (int)(uintptr_t)sfp->sf_cookie;
1332 si = sfp->sf_si;
1333 selfdfree(stp, sfp);
1334 /* If the selinfo wasn't cleared the event didn't fire. */
1335 if (si != NULL)
1336 continue;
1337 if (only_user)
1338 error = fget_only_user(fdp, fd, &cap_event_rights, &fp);
1339 else
1340 error = fget_unlocked(fdp, fd, &cap_event_rights, &fp);
1341 if (__predict_false(error != 0))
1342 return (error);
1343 idx = fd / NFDBITS;
1344 bit = (fd_mask)1 << (fd % NFDBITS);
1345 ev = fo_poll(fp, selflags(ibits, idx, bit), td->td_ucred, td);
1346 if (only_user)
1347 fput_only_user(fdp, fp);
1348 else
1349 fdrop(fp, td);
1350 if (ev != 0)
1351 n += selsetbits(ibits, obits, idx, bit, ev);
1352 }
1353 stp->st_flags = 0;
1354 td->td_retval[0] = n;
1355 return (0);
1356}
1357
1358/*
1359 * Perform the initial filedescriptor scan and register ourselves with

Callers 1

kern_selectFunction · 0.85

Calls 6

selfdfreeFunction · 0.85
fget_only_userFunction · 0.85
fget_unlockedFunction · 0.85
fo_pollFunction · 0.85
selflagsFunction · 0.85
selsetbitsFunction · 0.85

Tested by

no test coverage detected