]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/fdsel.h
   2  * Copyright (c) 2000-2001,2003-2004,2011,2014 Apple Inc. All Rights Reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   6  * This file contains Original Code and/or Modifications of Original Code 
   7  * as defined in and that are subject to the Apple Public Source License 
   8  * Version 2.0 (the 'License'). You may not use this file except in 
   9  * compliance with the License. Please obtain a copy of the License at 
  10  * http://www.opensource.apple.com/apsl/ and read it before using this 
  13  * The Original Code and all software distributed under the License are 
  14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  18  * Please see the License for the specific language governing rights and 
  19  * limitations under the License. 
  21  * @APPLE_LICENSE_HEADER_END@ 
  26 // fdsel - select-style file descriptor set management 
  31 #include <security_utilities/utilities.h> 
  32 #include <sys/types.h> 
  33 #include <security_utilities/debugging.h> 
  37 namespace UnixPlusPlus 
{ 
  41 // An FDSet object maintains a single select(2) compatible bitmap. 
  42 // Size is implicitly kept by the caller (who needs to call grow() as 
  43 // needed, starting at zero). As long as this is done correctly, we are 
  44 // not bound by the FD_SETSIZE limit. 
  45 // An FDSet can self-copy for select(2) use; after that, the [] operator 
  46 // investigates the copy. 
  48 // Why are we using the FD_* macros even though we know these 
  49 // are fd_mask arrays? Some implementations use optimized assembly 
  50 // for these operations, and we want to pick those up. 
  52 // This whole mess is completely UNIX specific. If your system has 
  53 // the poll(2) system call, ditch this and use it. 
  57     FDSet() : mBits(NULL
), mUseBits(NULL
) { } 
  60     void grow(int oldWords
, int newWords
); 
  61     void set(int fd
, bool on
); 
  63     fd_set 
*make(int words
); 
  64     bool operator [] (int fd
) const     { return FD_ISSET(fd
, (fd_set 
*)mUseBits
); } 
  66     inline static int words(int fd
)     { return (fd 
- 1) / NFDBITS 
+ 1; } 
  69     fd_mask 
*mBits
;                                     // base bits 
  70     fd_mask 
*mUseBits
;                          // mutable copy for select(2) 
  72     void grow(fd_mask 
* &bits
, int oldWords
, int newWords
); 
  76 }       // end namespace UnixPlusPlus 
  77 }       // end namespace Security