diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-02-25 08:05:42 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-02-25 08:05:42 -0600 |
commit | ee5b0f81118f1e199a7a24906764c96156a7a83d (patch) | |
tree | e6b4d211c1f7ce465c735cf3a6941437eec9bbca | |
parent | f82b6d2871c926b64c9676c8ef89206a7d2aa314 (diff) | |
download | px4-nuttx-ee5b0f81118f1e199a7a24906764c96156a7a83d.tar.gz px4-nuttx-ee5b0f81118f1e199a7a24906764c96156a7a83d.tar.bz2 px4-nuttx-ee5b0f81118f1e199a7a24906764c96156a7a83d.zip |
Extend the fd_set type definition so that it can handle more than 32 descriptors (if so configured). From Max Neklyudov
-rw-r--r-- | nuttx/include/sys/select.h | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/nuttx/include/sys/select.h b/nuttx/include/sys/select.h index 7617b6a53..df93cbc85 100644 --- a/nuttx/include/sys/select.h +++ b/nuttx/include/sys/select.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/sys/select.h * - * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -53,49 +53,58 @@ /* Get the total number of descriptors that we will have to support */ -#define __SELECT_NDESCRIPTORS (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS) +#define FD_SETSIZE (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS) /* We will use a 32-bit bitsets to represent the set of descriptors. How * many uint32_t's do we need to span all descriptors? */ -#if __SELECT_NDESCRIPTORS <= 32 +#if FD_SETSIZE <= 32 # define __SELECT_NUINT32 1 -#elif __SELECT_NDESCRIPTORS <= 64 +#elif FD_SETSIZE <= 64 # define __SELECT_NUINT32 2 -#elif __SELECT_NDESCRIPTORS <= 96 +#elif FD_SETSIZE <= 96 # define __SELECT_NUINT32 3 -#elif __SELECT_NDESCRIPTORS <= 128 +#elif FD_SETSIZE <= 128 # define __SELECT_NUINT32 4 -#elif __SELECT_NDESCRIPTORS <= 160 +#elif FD_SETSIZE <= 160 # define __SELECT_NUINT32 5 -#elif __SELECT_NDESCRIPTORS <= 192 +#elif FD_SETSIZE <= 192 # define __SELECT_NUINT32 6 -#elif __SELECT_NDESCRIPTORS <= 224 +#elif FD_SETSIZE <= 224 # define __SELECT_NUINT32 7 -#elif __SELECT_NDESCRIPTORS <= 256 +#elif FD_SETSIZE <= 256 # define __SELECT_NUINT32 8 #else -# warning "Large fd_set needed" +# warning "Larger fd_set needed" #endif -/* These macros map a file descripto to an index and bit number */ +/* These macros map a file descriptor to an index and bit number */ #define _FD_NDX(fd) ((fd) >> 5) #define _FD_BIT(fd) ((fd) & 0x1f) /* Standard helper macros */ -#define FD_CLR(fd,set) (((uint32_t*)(set))[_FD_NDX(fd)] &= ~(1 << _FD_BIT(fd))) -#define FD_SET(fd,set) (((uint32_t*)(set))[_FD_NDX(fd)] |= (1 << _FD_BIT(fd))) -#define FD_ISSET(fd,set) ((((uint32_t*)(set))[_FD_NDX(fd)] & (1 << _FD_BIT(fd))) != 0) -#define FD_ZERO(set) memset(set, 0, sizeof(fd_set)) +#define FD_CLR(fd,set) \ + ((((fd_set*)(set))->arr)[_FD_NDX(fd)] &= ~(1 << _FD_BIT(fd))) +#define FD_SET(fd,set) \ + ((((fd_set*)(set))->arr)[_FD_NDX(fd)] |= (1 << _FD_BIT(fd))) +#define FD_ISSET(fd,set) \ + (((((fd_set*)(set))->arr)[_FD_NDX(fd)] & (1 << _FD_BIT(fd))) != 0) +#define FD_ZERO(set) \ + memset((set), 0, sizeof(fd_set)) /**************************************************************************** * Type Definitions ****************************************************************************/ -typedef uint32_t fd_set[__SELECT_NUINT32]; +struct fd_set_s +{ + uint32_t arr[__SELECT_NUINT32]; +}; + +typedef struct fd_set_s fd_set; /**************************************************************************** * Public Function Prototypes |