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

Function selsocket

freebsd/kern/sys_generic.c:1680–1728  ·  view source on GitHub ↗

* XXX This was created specifically to support netncp and netsmb. This * allows the caller to specify a socket to wait for events on. It returns * 0 if any events matched and an error otherwise. There is no way to * determine which events fired. */

Source from the content-addressed store, hash-verified

1678 * determine which events fired.
1679 */
1680int
1681selsocket(struct socket *so, int events, struct timeval *tvp, struct thread *td)
1682{
1683 struct timeval rtv;
1684 sbintime_t asbt, precision, rsbt;
1685 int error;
1686
1687 precision = 0; /* stupid gcc! */
1688 if (tvp != NULL) {
1689 rtv = *tvp;
1690 if (rtv.tv_sec < 0 || rtv.tv_usec < 0 ||
1691 rtv.tv_usec >= 1000000)
1692 return (EINVAL);
1693 if (!timevalisset(&rtv))
1694 asbt = 0;
1695 else if (rtv.tv_sec <= INT32_MAX) {
1696 rsbt = tvtosbt(rtv);
1697 precision = rsbt;
1698 precision >>= tc_precexp;
1699 if (TIMESEL(&asbt, rsbt))
1700 asbt += tc_tick_sbt;
1701 if (asbt <= SBT_MAX - rsbt)
1702 asbt += rsbt;
1703 else
1704 asbt = -1;
1705 } else
1706 asbt = -1;
1707 } else
1708 asbt = -1;
1709 seltdinit(td);
1710 /*
1711 * Iterate until the timeout expires or the socket becomes ready.
1712 */
1713 for (;;) {
1714 selfdalloc(td, NULL);
1715 error = sopoll(so, events, NULL, td);
1716 /* error here is actually the ready events. */
1717 if (error)
1718 return (0);
1719 error = seltdwait(td, asbt, precision);
1720 if (error)
1721 break;
1722 }
1723 seltdclear(td);
1724 /* XXX Duplicates ncp/smb behavior. */
1725 if (error == ERESTART)
1726 error = 0;
1727 return (error);
1728}
1729
1730/*
1731 * Preallocate two selfds associated with 'cookie'. Some fo_poll routines

Callers

nothing calls this directly

Calls 6

tvtosbtFunction · 0.85
seltdinitFunction · 0.85
selfdallocFunction · 0.85
sopollFunction · 0.85
seltdwaitFunction · 0.85
seltdclearFunction · 0.85

Tested by

no test coverage detected