libc_fdset.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * File : libc_errno.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2017-10-30 Bernard The first version
  23. */
  24. #ifndef LIBC_FDSET_H__
  25. #define LIBC_FDSET_H__
  26. #include <rtconfig.h>
  27. #if defined(RT_USING_NEWLIB) || defined(_WIN32)
  28. #include <sys/types.h>
  29. #if defined(HAVE_SYS_SELECT_H)
  30. #include <sys/select.h>
  31. #endif
  32. #else
  33. #ifdef RT_USING_DFS_NET
  34. #ifdef FD_SETSIZE
  35. #undef FD_SETSIZE
  36. #endif
  37. #define FD_SETSIZE DFS_FD_MAX
  38. #endif
  39. # ifndef FD_SETSIZE
  40. # define FD_SETSIZE 32
  41. # endif
  42. # define NBBY 8 /* number of bits in a byte */
  43. typedef long fd_mask;
  44. # define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
  45. # ifndef howmany
  46. # define howmany(x,y) (((x)+((y)-1))/(y))
  47. # endif
  48. /* We use a macro for fd_set so that including Sockets.h afterwards
  49. can work. */
  50. typedef struct _types_fd_set {
  51. fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
  52. } _types_fd_set;
  53. #define fd_set _types_fd_set
  54. # define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
  55. # define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
  56. # define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
  57. # define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
  58. #endif
  59. #endif