MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / lwip_selscan

Function lwip_selscan

components/net/lwip/lwip-2.1.2/src/api/sockets.c:1856–1921  ·  view source on GitHub ↗

* Go through the readset and writeset lists and see which socket of the sockets * set in the sets has events. On return, readset, writeset and exceptset have * the sockets enabled that had events. * * @param maxfdp1 the highest socket index in the sets * @param readset_in set of sockets to check for read events * @param writeset_in set of sockets to check for write events * @param exce

Source from the content-addressed store, hash-verified

1854 * @return number of sockets that had events (read/write/exception) (>= 0)
1855 */
1856static int
1857lwip_selscan(int maxfdp1, fd_set *readset_in, fd_set *writeset_in, fd_set *exceptset_in,
1858 fd_set *readset_out, fd_set *writeset_out, fd_set *exceptset_out)
1859{
1860 int i, nready = 0;
1861 fd_set lreadset, lwriteset, lexceptset;
1862 struct lwip_sock *sock;
1863 SYS_ARCH_DECL_PROTECT(lev);
1864
1865 FD_ZERO(&lreadset);
1866 FD_ZERO(&lwriteset);
1867 FD_ZERO(&lexceptset);
1868
1869 /* Go through each socket in each list to count number of sockets which
1870 currently match */
1871 for (i = LWIP_SOCKET_OFFSET; i < maxfdp1; i++) {
1872 /* if this FD is not in the set, continue */
1873 if (!(readset_in && FD_ISSET(i, readset_in)) &&
1874 !(writeset_in && FD_ISSET(i, writeset_in)) &&
1875 !(exceptset_in && FD_ISSET(i, exceptset_in))) {
1876 continue;
1877 }
1878 /* First get the socket's status (protected)... */
1879 SYS_ARCH_PROTECT(lev);
1880 sock = tryget_socket_unconn_locked(i);
1881 if (sock != NULL) {
1882 void *lastdata = sock->lastdata.pbuf;
1883 s16_t rcvevent = sock->rcvevent;
1884 u16_t sendevent = sock->sendevent;
1885 u16_t errevent = sock->errevent;
1886 SYS_ARCH_UNPROTECT(lev);
1887
1888 /* ... then examine it: */
1889 /* See if netconn of this socket is ready for read */
1890 if (readset_in && FD_ISSET(i, readset_in) && ((lastdata != NULL) || (rcvevent > 0))) {
1891 FD_SET(i, &lreadset);
1892 LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for reading\n", i));
1893 nready++;
1894 }
1895 /* See if netconn of this socket is ready for write */
1896 if (writeset_in && FD_ISSET(i, writeset_in) && (sendevent != 0)) {
1897 FD_SET(i, &lwriteset);
1898 LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for writing\n", i));
1899 nready++;
1900 }
1901 /* See if netconn of this socket had an error */
1902 if (exceptset_in && FD_ISSET(i, exceptset_in) && (errevent != 0)) {
1903 FD_SET(i, &lexceptset);
1904 LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for exception\n", i));
1905 nready++;
1906 }
1907 done_socket(sock);
1908 } else {
1909 SYS_ARCH_UNPROTECT(lev);
1910 /* no a valid open socket */
1911 return -1;
1912 }
1913 }

Callers 1

lwip_selectFunction · 0.70

Calls 2

done_socketFunction · 0.85

Tested by

no test coverage detected