hi all How to understand some codes in the function of __FD_SET?
hi all: the codes of functions is: 51 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L51> #undef __FD_SET <http://lxr.oss.org.cn/ident?v=2.6.16;i=__FD_SET> 52 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L52> static __inline__ void __FD_SET <http://lxr.oss.org.cn/ident?v=2.6.16;i=__FD_SET>(unsigned long __fd, __kernel_fd_set <http://lxr.oss.org.cn/ident?v=2.6.16;i=__kernel_fd_set> *__fdsetp) 53 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L53> { 54 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L54> unsigned long __tmp = __fd / __NFDBITS <http://lxr.oss.org.cn/ident?v=2.6.16;i=__NFDBITS>; 55 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L55> unsigned long __rem = __fd % __NFDBITS <http://lxr.oss.org.cn/ident?v=2.6.16;i=__NFDBITS>; 56 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L56> __fdsetp->fds_bits[__tmp] |= (1UL<<__rem); 57 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L57> } I can't understand the usage of __rem,How to understand it? thank you. PS: 21 <http://lxr.oss.org.cn/source/include/linux/posix_types.h?v=2.6.16#L21> #undef __NFDBITS <http://lxr.oss.org.cn/ident?v=2.6.16;i=__NFDBITS> 22 <http://lxr.oss.org.cn/source/include/linux/posix_types.h?v=2.6.16#L22> #define __NFDBITS <http://lxr.oss.org.cn/ident?v=2.6.16;i=__NFDBITS> (8 * sizeof(unsigned long))
Hi, On Sat, Nov 2, 2013 at 11:35 PM, lx <lxlenovostar@gmail.com> wrote:
hi all: the codes of functions is:
51 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L51> #undef __FD_SET <http://lxr.oss.org.cn/ident?v=2.6.16;i=__FD_SET> 52 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L52> static __inline__ void __FD_SET <http://lxr.oss.org.cn/ident?v=2.6.16;i=__FD_SET>(unsigned long __fd, __kernel_fd_set <http://lxr.oss.org.cn/ident?v=2.6.16;i=__kernel_fd_set> *__fdsetp) 53 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L53> { 54 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L54> unsigned long __tmp = __fd / __NFDBITS <http://lxr.oss.org.cn/ident?v=2.6.16;i=__NFDBITS>; 55 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L55> unsigned long __rem = __fd % __NFDBITS <http://lxr.oss.org.cn/ident?v=2.6.16;i=__NFDBITS>; 56 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L56> __fdsetp->fds_bits[__tmp] |= (1UL<<__rem); 57 <http://lxr.oss.org.cn/source/include/asm-sh/posix_types.h?v=2.6.16#L57> }
I can't understand the usage of __rem,How to understand it? thank you.
fds_bits is an array of entries which are each __NFDBITS long (in your example, each entry is 32-bits). __tmp gives you the index into the array. __rem is the remainder of the division, and gets you the bit number within the 32-bit entry. -- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com
participants (2)
-
Dave Hylands -
lx