|
最近在unix network programming,看到了select,用fd_set来表示要监视套接字的结合,我觉得fd-set后面一定大有文章,可是当我看到代码以后,我发觉我看不懂,代码倒不是很长。部分代码我找出来了,希望大哥大姐们帮忙看看,让大家进步进步啊,谢谢
- #define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
- ---------------------------------------------------------------------------------------------------
- typedef struct
- {
- /* XPG4.2 requires this member name. Otherwise avoid the name from the global namespace. */
- #ifdef __USE_XOPEN
- __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
- # define __FDS_BITS(set) ((set)->fds_bits)
- #else
- __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
- //sys/select.h: typedef long int __fd_mask;
- //bits/typesizes.h: #define __FD_SETSIZE 1024
- //sys/select.h: #define __NFDBITS (8 * sizeof (__fd_mask))
- //__fds_bits是1024bits的数组
- # define __FDS_BITS(set) ((set)->__fds_bits)
- //返回fd_set结构的数据fd_set->__fds_bits
- #endif
- } fd_set;
- ---------------------------------------------------------------------------------------------------------
- # define __FD_ZERO(fdsp) \
- do { \
- int __d0, __d1; \
- __asm__ __volatile__ ("cld; rep; stosl" \
- : "=c" (__d0), "=D" (__d1) \
- : "a" (0), "0" (sizeof (fd_set) \
- / sizeof (__fd_mask)), \
- "1" (&__FDS_BITS (fdsp)[0]) \
- : "memory"); \
- } while (0)
- # define __FD_SET(fd, fdsp) \
- __asm__ __volatile__ ("btsl %1,%0" \
- : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
- : "r" (((int) (fd)) % __NFDBITS) \
- : "cc","memory")
- # define __FD_CLR(fd, fdsp) \
- __asm__ __volatile__ ("btrl %1,%0" \
- : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
- : "r" (((int) (fd)) % __NFDBITS) \
- : "cc","memory")
- # define __FD_ISSET(fd, fdsp) \
- (__extension__ \
- ({register char __result; \
- __asm__ __volatile__ ("btl %1,%2 ; setcb %b0" \
- : "=q" (__result) \
- : "r" (((int) (fd)) % __NFDBITS), \
- "m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
- : "cc"); \
- __result; }))
复制代码 |
|